mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:10:22 +00:00
Add a little script to run migrated (and unmigrated) tests.
Change-Id: I1c64b96e79084d2b45d97ae7fcb6c0f0eddb6f3d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142561 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
8690bb5653
commit
2471ee5133
2 changed files with 100 additions and 0 deletions
86
tools/migration/bin/test.dart
Normal file
86
tools/migration/bin/test.dart
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
/// A little utility script to make it easier to run NNBD and legacy tests.
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
|
||||
import 'package:migration/src/io.dart';
|
||||
import 'package:migration/src/test_directories.dart';
|
||||
|
||||
/// Maps "normal" names for Dart implementations to their test runner compiler
|
||||
/// names.
|
||||
const compilerNames = {
|
||||
"analyzer": "dart2analyzer",
|
||||
"cfe": "fasta",
|
||||
"dart2js": "dart2js",
|
||||
"ddc": "dartdevk",
|
||||
"vm": "dartk",
|
||||
};
|
||||
|
||||
void main(List<String> arguments) async {
|
||||
var testDir = "";
|
||||
var isLegacy = false;
|
||||
var compilers = <String>[];
|
||||
|
||||
var argParser = ArgParser();
|
||||
argParser.addFlag("legacy",
|
||||
help: "Run the legacy tests.",
|
||||
negatable: false,
|
||||
callback: (flag) => isLegacy = false);
|
||||
|
||||
argParser.addMultiOption("compiler",
|
||||
abbr: "c",
|
||||
help: "Which Dart implementations to run the tests on.",
|
||||
allowed: ["analyzer", "cfe", "dart2js", "ddc", "vm"],
|
||||
callback: (implementations) {
|
||||
compilers.addAll(implementations.map((name) => compilerNames[name]));
|
||||
});
|
||||
|
||||
if (arguments.contains("--help")) {
|
||||
showUsage(argParser);
|
||||
}
|
||||
|
||||
try {
|
||||
var argResults = argParser.parse(arguments);
|
||||
|
||||
if (argResults.rest.length != 1) {
|
||||
showUsage(argParser, "Missing test directory.");
|
||||
}
|
||||
|
||||
testDir = argResults.rest[0];
|
||||
|
||||
// If the test directory is just a single identifier, assume it's a language
|
||||
// test subdirectory.
|
||||
if (!testDir.contains("/")) testDir = "language_2/$testDir";
|
||||
} on FormatException catch (exception) {
|
||||
showUsage(argParser, exception.message);
|
||||
}
|
||||
|
||||
if (!isLegacy) testDir = toNnbdPath(testDir);
|
||||
|
||||
var testArgs = [
|
||||
"--mode=release",
|
||||
if (!isLegacy) ...[
|
||||
"--enable-experiment=non-nullable",
|
||||
"--nnbd=strong",
|
||||
],
|
||||
"--compiler=${compilers.join(',')}",
|
||||
testDir,
|
||||
];
|
||||
|
||||
print("Running tools/test.py ${testArgs.join(' ')}");
|
||||
await runProcessAsync("tools/test.py", testArgs);
|
||||
}
|
||||
|
||||
void showUsage(ArgParser argParser, [String error]) {
|
||||
if (error != null) {
|
||||
print(error);
|
||||
print("");
|
||||
}
|
||||
print("Usage: dart test.dart <source dir>");
|
||||
print(argParser.usage);
|
||||
exit(error == null ? 0 : 1);
|
||||
}
|
|
@ -131,6 +131,20 @@ bool runProcess(String executable, List<String> arguments,
|
|||
return result.exitCode == 0;
|
||||
}
|
||||
|
||||
Future<bool> runProcessAsync(String executable, List<String> arguments,
|
||||
{String workingDirectory}) async {
|
||||
if (dryRun) {
|
||||
print("Dry run: run $executable ${arguments.join(' ')}");
|
||||
return true;
|
||||
}
|
||||
|
||||
var process = await Process.start(executable, arguments);
|
||||
process.stdout.listen(stdout.add);
|
||||
process.stderr.listen(stderr.add);
|
||||
|
||||
return (await process.exitCode) == 0;
|
||||
}
|
||||
|
||||
/// Returns a list of the paths to all files within [dir], which is
|
||||
/// assumed to be relative to the SDK's "tests" directory and having file with
|
||||
/// an extension in [extensions].
|
||||
|
|
Loading…
Reference in a new issue