Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions test/test_pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,21 +423,13 @@ Map<String, String> getPubTestEnvironment([String tokenEndpoint]) {
return environment;
}

/// The test runner starts all tests from a `data:` URI.
final bool _runningAsTestRunner = Platform.script.scheme == 'data';

/// The path to the root of pub's sources in the pub repo.
final String _pubRoot = (() {
// The test runner always runs from the repo directory.
if (_runningAsTestRunner) return p.current;

// Running from "test/../some_test.dart".
var script = p.fromUri(Platform.script);

var components = p.split(script);
var testIndex = components.indexOf('test');
if (testIndex == -1) throw StateError("Can't find pub's root.");
return p.joinAll(components.take(testIndex));
if (!fileExists(p.join('bin', 'pub.dart'))) {
throw StateError(
"Current working directory (${p.current} is not pub's root. Run tests from pub's root.");
}
return p.current;
})();

/// Starts a Pub process and returns a [PubProcess] that supports interaction
Expand Down
22 changes: 12 additions & 10 deletions tool/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import 'package:pub/src/dart.dart';
import 'package:pub/src/exceptions.dart';

Future<void> main(List<String> args) async {
Process testProcess;
ProcessSignal.sigint.watch().listen((signal) {
testProcess?.kill(signal);
});
final pubSnapshotFilename =
path.absolute(path.join('.dart_tool', '_pub', 'pub.dart.snapshot.dart2'));
final pubSnapshotIncrementalFilename = '$pubSnapshotFilename.incremental';
Expand All @@ -30,17 +34,15 @@ Future<void> main(List<String> args) async {
incrementalDillOutputPath: pubSnapshotIncrementalFilename,
name: 'bin/pub.dart',
packageConfigPath: path.join('.dart_tool', 'package_config.json'));
final extension = Platform.isWindows ? '.bat' : '';
final testProcess = await Process.start(
path.join(path.dirname(Platform.resolvedExecutable), 'pub$extension'),
['run', 'test', ...args],
environment: {'_PUB_TEST_SNAPSHOT': pubSnapshotFilename});
await Future.wait([
testProcess.stdout.pipe(stdout),
testProcess.stderr.pipe(stderr),
]);
testProcess = await Process.start(
Platform.resolvedExecutable,
['run', 'test', '--chain-stack-traces', ...args],
environment: {'_PUB_TEST_SNAPSHOT': pubSnapshotFilename},
mode: ProcessStartMode.inheritStdio,
);
exitCode = await testProcess.exitCode;
} on ApplicationException catch (_) {
} on ApplicationException catch (e) {
print('Failed building snapshot: $e');
exitCode = 1;
} finally {
try {
Expand Down