blob: 6648afadc315da10f64629786c5b93466a97c573 [file] [log] [blame]
#!/usr/bin/env dart
/// Test wrapper script.
/// Many of the integration tests runs the `pub` command, this is slow if every
/// invocation requires the dart compiler to load all the sources. This script
/// will create a `pub.XXX.dart.snapshot.dart2` which the tests can utilize.
/// After creating the snapshot this script will forward arguments to
/// `pub run test`, and ensure that the snapshot is deleted after tests have been
/// run.
import 'dart:io';
import 'package:path/path.dart' as path;
Future<void> main(List<String> args) async {
final pubSnapshotFilename = path.join(
(await Directory.systemTemp.createTemp()).path,
try {
print('Building snapshot');
final stopwatch = Stopwatch()..start();
final root = path.dirname(path.dirname(Platform.script.path));
final compilationResult = await, [
path.join(root, 'bin', 'pub.dart')
if (compilationResult.exitCode != 0) {
'Failed building snapshot: ${compilationResult.stdout} ${compilationResult.stderr}');
exitCode = compilationResult.exitCode;
print('Took ${stopwatch.elapsedMilliseconds} milliseconds');
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([
exitCode = await testProcess.exitCode;
} finally {
try {
await File(pubSnapshotFilename).delete();
} on Exception {
// snapshot didn't exist.