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

Side by Side Diff: test/runner/tag_test.dart

Issue 1405633004: feature: tag tests; choose tags on command line Base URL: git@github.com:yjbanov/test.git@tags
Patch Set: address review comments; --exclude-tags Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 @TestOn("vm")
6
7 import 'package:scheduled_test/descriptor.dart' as d;
8 import 'package:scheduled_test/scheduled_stream.dart';
9 import 'package:scheduled_test/scheduled_test.dart';
10
11 import '../io.dart';
12
13 void main() {
14 useSandbox();
15
16 group("--tags", () {
17 test("runs only tests containing specified tags", () {
18 d.file("test.dart", """
19 import 'package:test/test.dart';
20
21 void main() {
22 test("no tags", () {});
23 test("a", () {}, tags: "a");
24 test("b", () {}, tags: "b");
25 test("bc", () {}, tags: "b,c");
26 }
27 """).create();
28
29 var test;
30
31 /// [warnings] contains pairs, each containing a comma-separated list of
32 /// tags the warning is about and the test name.
33 expectTagWarnings(List<List<String>> warnings) {
34 for (var warning in warnings) {
35 test.stderr.expect(consumeThrough(contains(
36 "WARNING: unrecognized tags {${warning[0]}}"
37 " in test '${warning[1]}'")));
38 }
39 test.stderr.expect(isDone);
40 }
41
42 test = runTest(["test.dart"]);
nweiz 2015/11/16 21:59:44 Each of these invocations of the test runner shoul
yjbanov 2015/11/26 06:30:27 Done.
43 test.stdout.expect(consumeThrough(contains("+4: All tests passed!")));
44 expectTagWarnings([
45 ['a', 'a'],
46 ['b', 'b'],
47 ['b, c', 'bc'],
48 ]);
49 test.shouldExit(0);
50
51 test = runTest(["--tags=a", "test.dart"]);
52 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
53 expectTagWarnings([
54 ['b', 'b'],
55 ['b, c', 'bc'],
56 ]);
57 test.shouldExit(0);
58
59 test = runTest(["--tags=b", "test.dart"]);
60 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
61 expectTagWarnings([
62 ['a', 'a'],
63 ['c', 'bc'],
64 ]);
65 test.shouldExit(0);
66
67 test = runTest(["--tags=c", "test.dart"]);
68 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
69 expectTagWarnings([
70 ['a', 'a'],
71 ['b', 'b'],
72 ['b', 'bc'],
73 ]);
74 test.shouldExit(0);
75
76 test = runTest(["--tags=a,b,c", "test.dart"]);
77 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
78 expectTagWarnings([]);
79 test.shouldExit(0);
80 });
81
82 test("takes -t abbreviation and --tag typo", () {
83 d.file("test.dart", """
84 import 'package:test/test.dart';
85
86 void main() {
87 test("no tags", () {});
88 test("a", () {}, tags: "a");
89 }
90 """).create();
91
92 var test = runTest(["test.dart"]);
nweiz 2015/11/16 21:59:44 You don't need to test what happens if no flags ar
yjbanov 2015/11/26 06:30:27 I was sanity checking the test itself, but done.
93 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
94 test.shouldExit(0);
95
96 test = runTest(["-t", "a", "test.dart"]);
97 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
98 test.shouldExit(0);
99
100 test = runTest(["--tag=a", "test.dart"]);
101 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
102 test.shouldExit(0);
103 });
104 });
105
106 group("--exclude-tags", () {
107 test("runs only tests containing specified tags", () {
108 d.file("test.dart", """
109 import 'package:test/test.dart';
110
111 void main() {
112 test("no tags", () {});
113 test("a", () {}, tags: "a");
114 test("b", () {}, tags: "b");
115 test("bc", () {}, tags: "b,c");
116 }
117 """).create();
118
119 var test;
120
121 /// [warnings] contains pairs, each containing a comma-separated list of
122 /// tags the warning is about and the test name.
123 expectTagWarnings(List<List<String>> warnings) {
124 for (var warning in warnings) {
125 test.stderr.expect(consumeThrough(contains(
126 "WARNING: unrecognized tags {${warning[0]}}"
127 " in test '${warning[1]}'")));
128 }
129 test.stderr.expect(isDone);
130 }
131
132 test = runTest(["--exclude-tags=a", "test.dart"]);
133 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
134 expectTagWarnings([
135 ['b', 'b'],
136 ['b, c', 'bc'],
137 ]);
138 test.shouldExit(0);
139
140 test = runTest(["--exclude-tags=b", "test.dart"]);
141 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
142 expectTagWarnings([
143 ['a', 'a'],
144 ['c', 'bc'],
145 ]);
146 test.shouldExit(0);
147
148 test = runTest(["--exclude-tags=c", "test.dart"]);
149 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
150 expectTagWarnings([
151 ['a', 'a'],
152 ['b', 'b'],
153 ['b', 'bc'],
154 ]);
155 test.shouldExit(0);
156
157 test = runTest(["--exclude-tags=a,b,c", "test.dart"]);
158 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
159 expectTagWarnings([]);
160 test.shouldExit(0);
161 });
162
163 test("takes -e abbreviation and --exclude-tag typo", () {
164 d.file("test.dart", """
165 import 'package:test/test.dart';
166
167 void main() {
168 test("no tags", () {});
169 test("a", () {}, tags: "a");
170 }
171 """).create();
172
173 var test = runTest(["-e", "a", "test.dart"]);
174 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
175 test.shouldExit(0);
176
177 test = runTest(["--exclude-tag=a", "test.dart"]);
178 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
179 test.shouldExit(0);
180 });
181 });
182
183 group('interaction between --tags and --exclude-tags', () {
184 test('refuses include and exclude the same tag simultaneously', () {
185 d.file("test.dart", """
186 import 'package:test/test.dart';
187
188 void main() {
189 test("foo", () {});
190 }
191 """).create();
192
193 var test = runTest(["-t", "a,b", "-e", "a,b,c", "test.dart"]);
194 test.stderr.expect(consumeThrough(contains("Included and excluded tag sets may not intersect. Found intersection: a, b")));
nweiz 2015/11/16 21:59:44 Long line.
yjbanov 2015/11/26 06:30:27 Done.
195 test.stderr.expect(consumeThrough(contains("Usage:")));
196 test.shouldExit(64);
197 });
198
199 test("--exclude-tags takes precedence over --tags", () {
200 d.file("test.dart", """
201 import 'package:test/test.dart';
202
203 void main() {
204 test("ab", () {}, tags: "ab");
205 }
206 """).create();
207
208 var test = runTest(["-t", "a", "-e", "b", "test.dart"]);
209 test.stdout.expect(consumeThrough(contains("No tests ran")));
210 test.shouldExit(0);
211 });
212 });
213 }
nweiz 2015/11/16 21:59:44 Also test that you exclude tags specified on the g
yjbanov 2015/11/26 06:30:27 Done.
OLDNEW
« test/backend/metadata_test.dart ('K') | « test/backend/metadata_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698