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

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

Issue 1490973003: Clean up the warning for unknown tags. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years 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
« no previous file with comments | « lib/src/runner/load_suite.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'package:scheduled_test/descriptor.dart' as d; 7 import 'package:scheduled_test/descriptor.dart' as d;
8 import 'package:scheduled_test/scheduled_process.dart';
9 import 'package:scheduled_test/scheduled_stream.dart'; 8 import 'package:scheduled_test/scheduled_stream.dart';
10 import 'package:scheduled_test/scheduled_test.dart'; 9 import 'package:scheduled_test/scheduled_test.dart';
11 10
12 import '../io.dart'; 11 import '../io.dart';
13 12
14 void main() { 13 void main() {
15 useSandbox(); 14 useSandbox();
16 15
17 setUp(() { 16 setUp(() {
18 d.file("test.dart", """ 17 d.file("test.dart", """
19 import 'package:test/test.dart'; 18 import 'package:test/test.dart';
20 19
21 void main() { 20 void main() {
22 test("no tags", () {}); 21 test("no tags", () {});
23 test("a", () {}, tags: "a"); 22 test("a", () {}, tags: "a");
24 test("b", () {}, tags: "b"); 23 test("b", () {}, tags: "b");
25 test("bc", () {}, tags: ["b", "c"]); 24 test("bc", () {}, tags: ["b", "c"]);
26 } 25 }
27 """).create(); 26 """).create();
28 }); 27 });
29 28
30 group("--tags", () { 29 group("--tags", () {
31 test("runs all tests when no tags are specified", () { 30 test("runs all tests when no tags are specified", () {
32 var test = runTest(["test.dart"]); 31 var test = runTest(["test.dart"]);
32 test.stdout.expect(tagWarnings(['a', 'b', 'c']));
33 test.stdout.expect(consumeThrough(contains(": no tags"))); 33 test.stdout.expect(consumeThrough(contains(": no tags")));
34 test.stdout.expect(consumeThrough(contains(": a"))); 34 test.stdout.expect(consumeThrough(contains(": a")));
35 test.stdout.expect(consumeThrough(contains(": b"))); 35 test.stdout.expect(consumeThrough(contains(": b")));
36 test.stdout.expect(consumeThrough(contains(": bc"))); 36 test.stdout.expect(consumeThrough(contains(": bc")));
37 test.stdout.expect(consumeThrough(contains("+4: All tests passed!"))); 37 test.stdout.expect(consumeThrough(contains("+4: All tests passed!")));
38 expectTagWarnings(test, [
39 ['a', 'a'],
40 ['b', 'b'],
41 ['b and c', 'bc']
42 ]);
43 test.shouldExit(0); 38 test.shouldExit(0);
44 }); 39 });
45 40
46 test("runs a test with only a specified tag", () { 41 test("runs a test with only a specified tag", () {
47 var test = runTest(["--tags=a", "test.dart"]); 42 var test = runTest(["--tags=a", "test.dart"]);
43 test.stdout.expect(tagWarnings(['b', 'c']));
48 test.stdout.expect(consumeThrough(contains(": a"))); 44 test.stdout.expect(consumeThrough(contains(": a")));
49 test.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); 45 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
50 expectTagWarnings(test, [
51 ['b', 'b'],
52 ['b and c', 'bc']
53 ]);
54 test.shouldExit(0); 46 test.shouldExit(0);
55 }); 47 });
56 48
57 test("runs a test with a specified tag among others", () { 49 test("runs a test with a specified tag among others", () {
58 var test = runTest(["--tags=c", "test.dart"]); 50 var test = runTest(["--tags=c", "test.dart"]);
51 test.stdout.expect(tagWarnings(['a', 'b']));
59 test.stdout.expect(consumeThrough(contains(": bc"))); 52 test.stdout.expect(consumeThrough(contains(": bc")));
60 test.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); 53 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
61 expectTagWarnings(test, [
62 ['a', 'a'],
63 ['b', 'b'],
64 ['b', 'bc']
65 ]);
66 test.shouldExit(0); 54 test.shouldExit(0);
67 }); 55 });
68 56
69 test("with multiple tags, runs only tests matching all of them", () { 57 test("with multiple tags, runs only tests matching all of them", () {
70 var test = runTest(["--tags=b,c", "test.dart"]); 58 var test = runTest(["--tags=b,c", "test.dart"]);
59 test.stdout.expect(tagWarnings(['a']));
71 test.stdout.expect(consumeThrough(contains(": bc"))); 60 test.stdout.expect(consumeThrough(contains(": bc")));
72 test.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); 61 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
73 expectTagWarnings(test, [
74 ['a', 'a']
75 ]);
76 test.shouldExit(0); 62 test.shouldExit(0);
77 }); 63 });
78 64
79 test("prints no warnings when all tags are specified", () { 65 test("prints no warnings when all tags are specified", () {
80 var test = runTest(["--tags=a,b,c", "test.dart"]); 66 var test = runTest(["--tags=a,b,c", "test.dart"]);
81 test.stdout.expect(consumeThrough(contains("No tests ran."))); 67 test.stdout.expect(consumeThrough(contains("No tests ran.")));
82 expectTagWarnings(test, []);
83 test.shouldExit(0); 68 test.shouldExit(0);
84 }); 69 });
85 }); 70 });
86 71
87 group("--exclude-tags", () { 72 group("--exclude-tags", () {
88 test("dosn't run a test with only an excluded tag", () { 73 test("dosn't run a test with only an excluded tag", () {
89 var test = runTest(["--exclude-tags=a", "test.dart"]); 74 var test = runTest(["--exclude-tags=a", "test.dart"]);
75 test.stdout.expect(tagWarnings(['b', 'c']));
90 test.stdout.expect(consumeThrough(contains(": no tags"))); 76 test.stdout.expect(consumeThrough(contains(": no tags")));
91 test.stdout.expect(consumeThrough(contains(": b"))); 77 test.stdout.expect(consumeThrough(contains(": b")));
92 test.stdout.expect(consumeThrough(contains(": bc"))); 78 test.stdout.expect(consumeThrough(contains(": bc")));
93 test.stdout.expect(consumeThrough(contains("+3: All tests passed!"))); 79 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
94 expectTagWarnings(test, [
95 ['b', 'b'],
96 ['b and c', 'bc'],
97 ]);
98 test.shouldExit(0); 80 test.shouldExit(0);
99 }); 81 });
100 82
101 test("doesn't run a test with an exluded tag among others", () { 83 test("doesn't run a test with an exluded tag among others", () {
102 var test = runTest(["--exclude-tags=c", "test.dart"]); 84 var test = runTest(["--exclude-tags=c", "test.dart"]);
85 test.stdout.expect(tagWarnings(['a', 'b']));
103 test.stdout.expect(consumeThrough(contains(": no tags"))); 86 test.stdout.expect(consumeThrough(contains(": no tags")));
104 test.stdout.expect(consumeThrough(contains(": a"))); 87 test.stdout.expect(consumeThrough(contains(": a")));
105 test.stdout.expect(consumeThrough(contains(": b"))); 88 test.stdout.expect(consumeThrough(contains(": b")));
106 test.stdout.expect(consumeThrough(contains("+3: All tests passed!"))); 89 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
107 expectTagWarnings(test, [
108 ['a', 'a'],
109 ['b', 'b'],
110 ['b', 'bc'],
111 ]);
112 test.shouldExit(0); 90 test.shouldExit(0);
113 }); 91 });
114 92
115 test("allows unused tags", () { 93 test("allows unused tags", () {
116 var test = runTest(["--exclude-tags=b,z", "test.dart"]); 94 var test = runTest(["--exclude-tags=b,z", "test.dart"]);
95 test.stdout.expect(tagWarnings(['a', 'c']));
117 test.stdout.expect(consumeThrough(contains(": no tags"))); 96 test.stdout.expect(consumeThrough(contains(": no tags")));
118 test.stdout.expect(consumeThrough(contains(": a"))); 97 test.stdout.expect(consumeThrough(contains(": a")));
119 test.stdout.expect(consumeThrough(contains("+2: All tests passed!"))); 98 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
120 expectTagWarnings(test, [
121 ['a', 'a'],
122 ['c', 'bc'],
123 ]);
124 test.shouldExit(0); 99 test.shouldExit(0);
125 }); 100 });
126 101
127 test("prints no warnings when all tags are specified", () { 102 test("prints no warnings when all tags are specified", () {
128 var test = runTest(["--exclude-tags=a,b,c", "test.dart"]); 103 var test = runTest(["--exclude-tags=a,b,c", "test.dart"]);
129 test.stdout.expect(consumeThrough(contains(": no tags"))); 104 test.stdout.expect(consumeThrough(contains(": no tags")));
130 test.stdout.expect(consumeThrough(contains("+1: All tests passed!"))); 105 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
131 expectTagWarnings(test, []);
132 test.shouldExit(0); 106 test.shouldExit(0);
133 }); 107 });
134 }); 108 });
135 109
136 group("with a tagged group", () { 110 group("with a tagged group", () {
137 setUp(() { 111 setUp(() {
138 d.file("test.dart", """ 112 d.file("test.dart", """
139 import 'package:test/test.dart'; 113 import 'package:test/test.dart';
140 114
141 void main() { 115 void main() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 160
187 void main() { 161 void main() {
188 test("foo", () {}); 162 test("foo", () {});
189 } 163 }
190 """).create(); 164 """).create();
191 165
192 var test = runTest(["-x", "a", "test.dart"]); 166 var test = runTest(["-x", "a", "test.dart"]);
193 test.stdout.expect(consumeThrough(contains("No tests ran"))); 167 test.stdout.expect(consumeThrough(contains("No tests ran")));
194 test.shouldExit(0); 168 test.shouldExit(0);
195 }); 169 });
170
171 group("warning formatting", () {
172 test("for multiple tags", () {
173 d.file("test.dart", """
174 import 'package:test/test.dart';
175
176 void main() {
177 test("foo", () {}, tags: ["a", "b"]);
178 }
179 """).create();
180
181 var test = runTest(["test.dart"]);
182 test.stdout.expect(consumeThrough(lines(
183 'Warning: Tags were used that weren\'t specified on the command '
184 'line.\n'
185 ' a was used in the test "foo"\n'
186 ' b was used in the test "foo"')));
187 test.shouldExit(0);
188 });
189
190 test("for multiple tests", () {
191 d.file("test.dart", """
192 import 'package:test/test.dart';
193
194 void main() {
195 test("foo", () {}, tags: "a");
196 test("bar", () {}, tags: "a");
197 }
198 """).create();
199
200 var test = runTest(["test.dart"]);
201 test.stdout.expect(consumeThrough(lines(
202 'Warning: A tag was used that wasn\'t specified on the command '
203 'line.\n'
204 ' a was used in:\n'
205 ' the test "foo"\n'
206 ' the test "bar"')));
207 test.shouldExit(0);
208 });
209
210 test("for groups", () {
211 d.file("test.dart", """
212 import 'package:test/test.dart';
213
214 void main() {
215 group("group", () {
216 test("foo", () {});
217 test("bar", () {});
218 }, tags: "a");
219 }
220 """).create();
221
222 var test = runTest(["test.dart"]);
223 test.stdout.expect(consumeThrough(lines(
224 'Warning: A tag was used that wasn\'t specified on the command '
225 'line.\n'
226 ' a was used in the group "group"')));
227 test.shouldExit(0);
228 });
229
230 test("for suites", () {
231 d.file("test.dart", """
232 @Tags(const ["a"])
233 import 'package:test/test.dart';
234
235 void main() {
236 test("foo", () {});
237 test("bar", () {});
238 }
239 """).create();
240
241 var test = runTest(["test.dart"]);
242 test.stdout.expect(consumeThrough(lines(
243 'Warning: A tag was used that wasn\'t specified on the command '
244 'line.\n'
245 ' a was used in the suite itself')));
246 test.shouldExit(0);
247 });
248
249 test("doesn't double-print a tag warning", () {
250 d.file("test.dart", """
251 import 'package:test/test.dart';
252
253 void main() {
254 test("foo", () {}, tags: "a");
255 }
256 """).create();
257
258 var test = runTest(["-p", "vm,content-shell", "test.dart"]);
259 test.stdout.expect(consumeThrough(lines(
260 'Warning: A tag was used that wasn\'t specified on the command '
261 'line.\n'
262 ' a was used in the test "foo"')));
263 test.stdout.expect(never(startsWith("Warning:")));
264 test.shouldExit(0);
265 });
266 });
196 } 267 }
197 268
198 /// Asserts that [test] emits [warnings] in order. 269 /// Returns a [StreamMatcher] that asserts that a test emits warnings for [tags]
199 /// 270 /// in order.
200 /// Each element of [warnings] should be a pair whose first element is the 271 StreamMatcher tagWarnings(List<String> tags) => inOrder(() sync* {
201 /// unrecognized tags and whose second is the name of the test in which they 272 yield consumeThrough(
202 /// were detected. 273 "Warning: ${tags.length == 1 ? 'A tag was' : 'Tags were'} used that "
203 expectTagWarnings(ScheduledProcess test, List<List<String>> warnings) { 274 "${tags.length == 1 ? "wasn't" : "weren't"} specified on the command "
204 for (var warning in warnings) { 275 "line.");
205 test.stderr.expect(consumeThrough(allOf([ 276
206 startsWith("Warning: Unknown tag"), 277 for (var tag in tags) {
207 endsWith('${warning.first} in test "${warning.last}".') 278 yield consumeWhile(isNot(contains(" was used in")));
208 ]))); 279 yield consumeThrough(startsWith(" $tag was used in"));
209 } 280 }
210 test.stderr.expect(never(startsWith("Warning:"))); 281
211 } 282 // Consume until the end of the warning block, and assert that it has no
283 // further tags than the ones we specified.
284 yield consumeWhile(isNot(anyOf([contains(" was used in"), isEmpty])));
285 yield isEmpty;
286 }());
287
288 /// Returns a [StreamMatcher] that matches the lines of [string] in order.
289 StreamMatcher lines(String string) => inOrder(string.split("\n"));
OLDNEW
« no previous file with comments | « lib/src/runner/load_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698