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