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

Unified Diff: test/runner/runner_test.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 | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/runner/runner_test.dart
diff --git a/test/runner/runner_test.dart b/test/runner/runner_test.dart
index 692b1faa157c08c6e5bdd102d2c25267c8504f2d..eb31b313cc604dcda5adde0ed3e48ee3587c7e3e 100644
--- a/test/runner/runner_test.dart
+++ b/test/runner/runner_test.dart
@@ -38,6 +38,10 @@ final _usage = """
Usage: pub run unittest:unittest [files or directories...]
-h, --help Shows this usage information.
+-n, --name A substring of the name of the test to run.
+ Regular expression syntax is supported.
+
+-N, --plain-name A plain-text substring of the name of the test to run.
-p, --platform The platform(s) on which to run the tests.
[vm (default), chrome]
@@ -264,13 +268,107 @@ $_usage"""));
});
});
- group("flags", () {
+ group("flags:", () {
test("with the --color flag, uses colors", () {
new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
var result = _runUnittest(["--color", "test.dart"]);
// This is the color code for red.
expect(result.stdout, contains("\u001b[31m"));
});
+
+ group("with the --name flag,", () {
+ test("selects tests with matching names", () {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+import 'dart:async';
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+ test("selected 1", () {});
+ test("nope", () => throw new TestFailure("oh no"));
+ test("selected 2", () {});
+}
+""");
+
+ var result = _runUnittest(["--name", "selected", "test.dart"]);
+ expect(result.stdout, contains("+2: All tests passed!"));
+ expect(result.exitCode, equals(0));
+ });
+
+ test("supports RegExp syntax", () {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+import 'dart:async';
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+ test("test 1", () {});
+ test("test 2", () => throw new TestFailure("oh no"));
+ test("test 3", () {});
+}
+""");
+
+ var result = _runUnittest(["--name", "test [13]", "test.dart"]);
+ expect(result.stdout, contains("+2: All tests passed!"));
+ expect(result.exitCode, equals(0));
+ });
+
+ test("produces an error when no tests match", () {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
+
+ var result = _runUnittest(["--name", "no match", "test.dart"]);
+ expect(result.stderr,
+ contains('No tests match regular expression "no match".'));
+ expect(result.exitCode, equals(exit_codes.data));
+ });
+ });
+
+ group("with the --plain-name flag,", () {
+ test("selects tests with matching names", () {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+import 'dart:async';
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+ test("selected 1", () {});
+ test("nope", () => throw new TestFailure("oh no"));
+ test("selected 2", () {});
+}
+""");
+
+ var result = _runUnittest(["--plain-name", "selected", "test.dart"]);
+ expect(result.stdout, contains("+2: All tests passed!"));
+ expect(result.exitCode, equals(0));
+ });
+
+ test("doesn't support RegExp syntax", () {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
+import 'dart:async';
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+ test("test 1", () => throw new TestFailure("oh no"));
+ test("test 2", () => throw new TestFailure("oh no"));
+ test("test [12]", () {});
+}
+""");
+
+ var result = _runUnittest(["--plain-name", "test [12]", "test.dart"]);
+ expect(result.stdout, contains("+1: All tests passed!"));
+ expect(result.exitCode, equals(0));
+ });
+
+ test("produces an error when no tests match", () {
+ new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
+
+ var result = _runUnittest(["--plain-name", "no match", "test.dart"]);
+ expect(result.stderr,
+ contains('No tests match "no match".'));
+ expect(result.exitCode, equals(exit_codes.data));
+ });
+ });
});
}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698