Skip to content

Commit bdae5ed

Browse files
committed
Improve test script
1 parent 9941c1f commit bdae5ed

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

test/test_pub.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,11 @@ final bool _runningAsTestRunner = Platform.script.scheme == 'data';
428428

429429
/// The path to the root of pub's sources in the pub repo.
430430
final String _pubRoot = (() {
431-
// The test runner always runs from the repo directory.
432-
if (_runningAsTestRunner) return p.current;
433-
434-
// Running from "test/../some_test.dart".
435-
var script = p.fromUri(Platform.script);
436-
437-
var components = p.split(script);
438-
var testIndex = components.indexOf('test');
439-
if (testIndex == -1) throw StateError("Can't find pub's root.");
440-
return p.joinAll(components.take(testIndex));
431+
if (!fileExists(p.join('bin', 'pub.dart'))) {
432+
throw StateError(
433+
"Current working directory (${p.current} is not pub's root. Run tests from pub's root.");
434+
}
435+
return p.current;
441436
})();
442437

443438
/// Starts a Pub process and returns a [PubProcess] that supports interaction

tool/test.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import 'package:pub/src/dart.dart';
1919
import 'package:pub/src/exceptions.dart';
2020

2121
Future<void> main(List<String> args) async {
22+
Process testProcess;
23+
ProcessSignal.sigint.watch().listen((signal) {
24+
testProcess?.kill(signal);
25+
});
2226
final pubSnapshotFilename =
2327
path.absolute(path.join('.dart_tool', '_pub', 'pub.dart.snapshot.dart2'));
2428
final pubSnapshotIncrementalFilename = '$pubSnapshotFilename.incremental';
@@ -30,17 +34,15 @@ Future<void> main(List<String> args) async {
3034
incrementalDillOutputPath: pubSnapshotIncrementalFilename,
3135
name: 'bin/pub.dart',
3236
packageConfigPath: path.join('.dart_tool', 'package_config.json'));
33-
final extension = Platform.isWindows ? '.bat' : '';
34-
final testProcess = await Process.start(
35-
path.join(path.dirname(Platform.resolvedExecutable), 'pub$extension'),
36-
['run', 'test', ...args],
37-
environment: {'_PUB_TEST_SNAPSHOT': pubSnapshotFilename});
38-
await Future.wait([
39-
testProcess.stdout.pipe(stdout),
40-
testProcess.stderr.pipe(stderr),
41-
]);
37+
testProcess = await Process.start(
38+
Platform.resolvedExecutable,
39+
['run', 'test', '--chain-stack-traces', ...args],
40+
environment: {'_PUB_TEST_SNAPSHOT': pubSnapshotFilename},
41+
mode: ProcessStartMode.inheritStdio,
42+
);
4243
exitCode = await testProcess.exitCode;
43-
} on ApplicationException catch (_) {
44+
} on ApplicationException catch (e) {
45+
print('Failed building snapshot: $e');
4446
exitCode = 1;
4547
} finally {
4648
try {

0 commit comments

Comments
 (0)