| Index: test/runner/tag_test.dart
|
| diff --git a/test/runner/tag_test.dart b/test/runner/tag_test.dart
|
| index be227a9ef21827c9d2f397c5afba46d1899b2403..6a2c297d8e30b8a95f498e860ada6d4a8d320f02 100644
|
| --- a/test/runner/tag_test.dart
|
| +++ b/test/runner/tag_test.dart
|
| @@ -5,7 +5,6 @@
|
| @TestOn("vm")
|
|
|
| import 'package:scheduled_test/descriptor.dart' as d;
|
| -import 'package:scheduled_test/scheduled_process.dart';
|
| import 'package:scheduled_test/scheduled_stream.dart';
|
| import 'package:scheduled_test/scheduled_test.dart';
|
|
|
| @@ -30,56 +29,42 @@ void main() {
|
| group("--tags", () {
|
| test("runs all tests when no tags are specified", () {
|
| var test = runTest(["test.dart"]);
|
| + test.stdout.expect(tagWarnings(['a', 'b', 'c']));
|
| test.stdout.expect(consumeThrough(contains(": no tags")));
|
| test.stdout.expect(consumeThrough(contains(": a")));
|
| test.stdout.expect(consumeThrough(contains(": b")));
|
| test.stdout.expect(consumeThrough(contains(": bc")));
|
| test.stdout.expect(consumeThrough(contains("+4: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['a', 'a'],
|
| - ['b', 'b'],
|
| - ['b and c', 'bc']
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| test("runs a test with only a specified tag", () {
|
| var test = runTest(["--tags=a", "test.dart"]);
|
| + test.stdout.expect(tagWarnings(['b', 'c']));
|
| test.stdout.expect(consumeThrough(contains(": a")));
|
| test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['b', 'b'],
|
| - ['b and c', 'bc']
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| test("runs a test with a specified tag among others", () {
|
| var test = runTest(["--tags=c", "test.dart"]);
|
| + test.stdout.expect(tagWarnings(['a', 'b']));
|
| test.stdout.expect(consumeThrough(contains(": bc")));
|
| test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['a', 'a'],
|
| - ['b', 'b'],
|
| - ['b', 'bc']
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| test("with multiple tags, runs only tests matching all of them", () {
|
| var test = runTest(["--tags=b,c", "test.dart"]);
|
| + test.stdout.expect(tagWarnings(['a']));
|
| test.stdout.expect(consumeThrough(contains(": bc")));
|
| test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['a', 'a']
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| test("prints no warnings when all tags are specified", () {
|
| var test = runTest(["--tags=a,b,c", "test.dart"]);
|
| test.stdout.expect(consumeThrough(contains("No tests ran.")));
|
| - expectTagWarnings(test, []);
|
| test.shouldExit(0);
|
| });
|
| });
|
| @@ -87,40 +72,30 @@ void main() {
|
| group("--exclude-tags", () {
|
| test("dosn't run a test with only an excluded tag", () {
|
| var test = runTest(["--exclude-tags=a", "test.dart"]);
|
| + test.stdout.expect(tagWarnings(['b', 'c']));
|
| test.stdout.expect(consumeThrough(contains(": no tags")));
|
| test.stdout.expect(consumeThrough(contains(": b")));
|
| test.stdout.expect(consumeThrough(contains(": bc")));
|
| test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['b', 'b'],
|
| - ['b and c', 'bc'],
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| test("doesn't run a test with an exluded tag among others", () {
|
| var test = runTest(["--exclude-tags=c", "test.dart"]);
|
| + test.stdout.expect(tagWarnings(['a', 'b']));
|
| test.stdout.expect(consumeThrough(contains(": no tags")));
|
| test.stdout.expect(consumeThrough(contains(": a")));
|
| test.stdout.expect(consumeThrough(contains(": b")));
|
| test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['a', 'a'],
|
| - ['b', 'b'],
|
| - ['b', 'bc'],
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| test("allows unused tags", () {
|
| var test = runTest(["--exclude-tags=b,z", "test.dart"]);
|
| + test.stdout.expect(tagWarnings(['a', 'c']));
|
| test.stdout.expect(consumeThrough(contains(": no tags")));
|
| test.stdout.expect(consumeThrough(contains(": a")));
|
| test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
|
| - expectTagWarnings(test, [
|
| - ['a', 'a'],
|
| - ['c', 'bc'],
|
| - ]);
|
| test.shouldExit(0);
|
| });
|
|
|
| @@ -128,7 +103,6 @@ void main() {
|
| var test = runTest(["--exclude-tags=a,b,c", "test.dart"]);
|
| test.stdout.expect(consumeThrough(contains(": no tags")));
|
| test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
|
| - expectTagWarnings(test, []);
|
| test.shouldExit(0);
|
| });
|
| });
|
| @@ -193,19 +167,123 @@ void main() {
|
| test.stdout.expect(consumeThrough(contains("No tests ran")));
|
| test.shouldExit(0);
|
| });
|
| +
|
| + group("warning formatting", () {
|
| + test("for multiple tags", () {
|
| + d.file("test.dart", """
|
| + import 'package:test/test.dart';
|
| +
|
| + void main() {
|
| + test("foo", () {}, tags: ["a", "b"]);
|
| + }
|
| + """).create();
|
| +
|
| + var test = runTest(["test.dart"]);
|
| + test.stdout.expect(consumeThrough(lines(
|
| + 'Warning: Tags were used that weren\'t specified on the command '
|
| + 'line.\n'
|
| + ' a was used in the test "foo"\n'
|
| + ' b was used in the test "foo"')));
|
| + test.shouldExit(0);
|
| + });
|
| +
|
| + test("for multiple tests", () {
|
| + d.file("test.dart", """
|
| + import 'package:test/test.dart';
|
| +
|
| + void main() {
|
| + test("foo", () {}, tags: "a");
|
| + test("bar", () {}, tags: "a");
|
| + }
|
| + """).create();
|
| +
|
| + var test = runTest(["test.dart"]);
|
| + test.stdout.expect(consumeThrough(lines(
|
| + 'Warning: A tag was used that wasn\'t specified on the command '
|
| + 'line.\n'
|
| + ' a was used in:\n'
|
| + ' the test "foo"\n'
|
| + ' the test "bar"')));
|
| + test.shouldExit(0);
|
| + });
|
| +
|
| + test("for groups", () {
|
| + d.file("test.dart", """
|
| + import 'package:test/test.dart';
|
| +
|
| + void main() {
|
| + group("group", () {
|
| + test("foo", () {});
|
| + test("bar", () {});
|
| + }, tags: "a");
|
| + }
|
| + """).create();
|
| +
|
| + var test = runTest(["test.dart"]);
|
| + test.stdout.expect(consumeThrough(lines(
|
| + 'Warning: A tag was used that wasn\'t specified on the command '
|
| + 'line.\n'
|
| + ' a was used in the group "group"')));
|
| + test.shouldExit(0);
|
| + });
|
| +
|
| + test("for suites", () {
|
| + d.file("test.dart", """
|
| + @Tags(const ["a"])
|
| + import 'package:test/test.dart';
|
| +
|
| + void main() {
|
| + test("foo", () {});
|
| + test("bar", () {});
|
| + }
|
| + """).create();
|
| +
|
| + var test = runTest(["test.dart"]);
|
| + test.stdout.expect(consumeThrough(lines(
|
| + 'Warning: A tag was used that wasn\'t specified on the command '
|
| + 'line.\n'
|
| + ' a was used in the suite itself')));
|
| + test.shouldExit(0);
|
| + });
|
| +
|
| + test("doesn't double-print a tag warning", () {
|
| + d.file("test.dart", """
|
| + import 'package:test/test.dart';
|
| +
|
| + void main() {
|
| + test("foo", () {}, tags: "a");
|
| + }
|
| + """).create();
|
| +
|
| + var test = runTest(["-p", "vm,content-shell", "test.dart"]);
|
| + test.stdout.expect(consumeThrough(lines(
|
| + 'Warning: A tag was used that wasn\'t specified on the command '
|
| + 'line.\n'
|
| + ' a was used in the test "foo"')));
|
| + test.stdout.expect(never(startsWith("Warning:")));
|
| + test.shouldExit(0);
|
| + });
|
| + });
|
| }
|
|
|
| -/// Asserts that [test] emits [warnings] in order.
|
| -///
|
| -/// Each element of [warnings] should be a pair whose first element is the
|
| -/// unrecognized tags and whose second is the name of the test in which they
|
| -/// were detected.
|
| -expectTagWarnings(ScheduledProcess test, List<List<String>> warnings) {
|
| - for (var warning in warnings) {
|
| - test.stderr.expect(consumeThrough(allOf([
|
| - startsWith("Warning: Unknown tag"),
|
| - endsWith('${warning.first} in test "${warning.last}".')
|
| - ])));
|
| +/// Returns a [StreamMatcher] that asserts that a test emits warnings for [tags]
|
| +/// in order.
|
| +StreamMatcher tagWarnings(List<String> tags) => inOrder(() sync* {
|
| + yield consumeThrough(
|
| + "Warning: ${tags.length == 1 ? 'A tag was' : 'Tags were'} used that "
|
| + "${tags.length == 1 ? "wasn't" : "weren't"} specified on the command "
|
| + "line.");
|
| +
|
| + for (var tag in tags) {
|
| + yield consumeWhile(isNot(contains(" was used in")));
|
| + yield consumeThrough(startsWith(" $tag was used in"));
|
| }
|
| - test.stderr.expect(never(startsWith("Warning:")));
|
| -}
|
| +
|
| + // Consume until the end of the warning block, and assert that it has no
|
| + // further tags than the ones we specified.
|
| + yield consumeWhile(isNot(anyOf([contains(" was used in"), isEmpty])));
|
| + yield isEmpty;
|
| +}());
|
| +
|
| +/// Returns a [StreamMatcher] that matches the lines of [string] in order.
|
| +StreamMatcher lines(String string) => inOrder(string.split("\n"));
|
|
|