Add --name and --plain-name to 'flutter test' (#11020)

This adds a way to run only a subset of the tests.
(The new flags do the same thing as 'pub run test'.)
This commit is contained in:
Brian Slesinsky
2017-06-29 17:26:19 -07:00
committed by GitHub
parent 0a915d6faf
commit 6841ab22be
4 changed files with 98 additions and 27 deletions

View File

@@ -22,6 +22,18 @@ import '../test/watcher.dart';
class TestCommand extends FlutterCommand {
TestCommand({ bool verboseHelp: false }) {
usesPubOption();
argParser.addOption('name',
help: 'A regular expression matching substrings of the names of tests to run.',
valueHelp: 'regexp',
allowMultiple: true,
splitCommas: false,
);
argParser.addOption('plain-name',
help: 'A plain-text substring of the names of tests to run.',
valueHelp: 'substring',
allowMultiple: true,
splitCommas: false,
);
argParser.addFlag('start-paused',
defaultsTo: false,
negatable: false,
@@ -141,6 +153,8 @@ class TestCommand extends FlutterCommand {
}
commandValidator();
final List<String> names = argResults['name'];
final List<String> plainNames = argResults['plain-name'];
Iterable<String> files = argResults.rest.map<String>((String testPath) => fs.path.absolute(testPath)).toList();
@@ -189,6 +203,8 @@ class TestCommand extends FlutterCommand {
final int result = await runTests(files,
workDir: workDir,
names: names,
plainNames: plainNames,
watcher: watcher,
enableObservatory: collector != null || startPaused,
startPaused: startPaused,

View File

@@ -21,6 +21,8 @@ import 'watcher.dart';
Future<int> runTests(
List<String> testFiles, {
Directory workDir,
List<String> names: const <String>[],
List<String> plainNames: const <String>[],
bool enableObservatory: false,
bool startPaused: false,
bool ipv6: false,
@@ -41,6 +43,14 @@ Future<int> runTests(
testArgs.addAll(<String>['-r', 'json']);
}
for (String name in names) {
testArgs..add("--name")..add(name);
}
for (String plainName in plainNames) {
testArgs..add("--plain-name")..add(plainName);
}
testArgs.add('--');
testArgs.addAll(testFiles);