Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Unified Diff: bin/unittest.dart

Issue 1041503002: Allow tests to be selected by name. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: cr Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/unittest.dart
diff --git a/bin/unittest.dart b/bin/unittest.dart
index 0189c8f1c4b9233f6d8c0ed6ee92c86d4f20c4f2..63cfe326387ee17a5087b0af6e6c0f4f71a3f7d9 100644
--- a/bin/unittest.dart
+++ b/bin/unittest.dart
@@ -26,6 +26,13 @@ void main(List<String> args) {
_parser.addFlag("help", abbr: "h", negatable: false,
help: "Shows this usage information.");
_parser.addOption("package-root", hide: true);
+ _parser.addOption("name",
+ abbr: 'n',
+ help: 'A substring of the name of the test to run.\n'
+ 'Regular expression syntax is supported.');
+ _parser.addOption("plain-name",
+ abbr: 'N',
+ help: 'A plain-text substring of the name of the test to run.');
_parser.addOption("platform",
abbr: 'p',
help: 'The platform(s) on which to run the tests.',
@@ -72,6 +79,39 @@ void main(List<String> args) {
throw new LoadException(path, 'Does not exist.');
}));
}).then((suites) {
+ suites = flatten(suites);
+
+ var pattern;
+ if (options["name"] != null) {
+ if (options["plain-name"] != null) {
+ _printUsage("--name and --plain-name may not both be passed.");
+ exitCode = exit_codes.data;
+ return null;
+ }
+ pattern = new RegExp(options["name"]);
+ } else if (options["plain-name"] != null) {
+ pattern = options["plain-name"];
+ }
+
+ if (pattern != null) {
+ suites = suites.map((suite) {
+ return suite.change(
+ tests: suite.tests.where((test) => test.name.contains(pattern)));
+ }).toList();
+
+ if (suites.every((suite) => suite.tests.isEmpty)) {
+ stderr.write('No tests match ');
+
+ if (pattern is RegExp) {
+ stderr.write('regular expression "${pattern.pattern}".');
+ } else {
+ stderr.writeln('"$pattern".');
+ }
+ exitCode = exit_codes.data;
+ return null;
+ }
+ }
+
var reporter = new CompactReporter(flatten(suites), color: color);
return reporter.run().then((success) {
exitCode = success ? 0 : 1;
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698