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 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
10 import 'package:test/src/util/io.dart'; | 10 import 'package:test/src/util/io.dart'; |
11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
12 | 12 |
13 import '../io.dart'; | 13 import '../io.dart'; |
14 | 14 |
15 void main() { | 15 void main() { |
16 test("reports when no tests are run", () { | 16 test("reports when no tests are run", () { |
17 return withTempDir((path) { | 17 return withTempDir((path) { |
18 new File(p.join(path, "test.dart")).writeAsStringSync("void main() {}"); | 18 new File(p.join(path, "test.dart")).writeAsStringSync("void main() {}"); |
19 var result = runTest(["-r", "compact", "test.dart"], | 19 var result = runTest(["-r", "compact", "test.dart"], |
20 workingDirectory: path); | 20 workingDirectory: path); |
21 expect(result.stdout, equals("No tests ran.\n")); | 21 expect(result.stdout, contains("No tests ran.")); |
22 }); | 22 }); |
23 }); | 23 }); |
24 | 24 |
25 test("runs several successful tests and reports when each completes", () { | 25 test("runs several successful tests and reports when each completes", () { |
26 _expectReport(""" | 26 _expectReport(""" |
27 test('success 1', () {}); | 27 test('success 1', () {}); |
28 test('success 2', () {}); | 28 test('success 2', () {}); |
29 test('success 3', () {});""", | 29 test('success 3', () {});""", |
30 """ | 30 """ |
| 31 +0: loading test.dart |
31 +0: success 1 | 32 +0: success 1 |
32 +1: success 1 | 33 +1: success 1 |
33 +1: success 2 | 34 +1: success 2 |
34 +2: success 2 | 35 +2: success 2 |
35 +2: success 3 | 36 +2: success 3 |
36 +3: success 3 | 37 +3: success 3 |
37 +3: All tests passed!"""); | 38 +3: All tests passed!"""); |
38 }); | 39 }); |
39 | 40 |
40 test("runs several failing tests and reports when each fails", () { | 41 test("runs several failing tests and reports when each fails", () { |
41 _expectReport(""" | 42 _expectReport(""" |
42 test('failure 1', () => throw new TestFailure('oh no')); | 43 test('failure 1', () => throw new TestFailure('oh no')); |
43 test('failure 2', () => throw new TestFailure('oh no')); | 44 test('failure 2', () => throw new TestFailure('oh no')); |
44 test('failure 3', () => throw new TestFailure('oh no'));""", | 45 test('failure 3', () => throw new TestFailure('oh no'));""", |
45 """ | 46 """ |
| 47 +0: loading test.dart |
46 +0: failure 1 | 48 +0: failure 1 |
47 +0 -1: failure 1 | 49 +0 -1: failure 1 |
48 oh no | 50 oh no |
49 test.dart 6:33 main.<fn> | 51 test.dart 6:33 main.<fn> |
50 | 52 |
51 | 53 |
52 +0 -1: failure 2 | 54 +0 -1: failure 2 |
53 +0 -2: failure 2 | 55 +0 -2: failure 2 |
54 oh no | 56 oh no |
55 test.dart 7:33 main.<fn> | 57 test.dart 7:33 main.<fn> |
(...skipping 25 matching lines...) Expand all Loading... |
81 }); | 83 }); |
82 }); | 84 }); |
83 | 85 |
84 test("runs failing tests along with successful tests", () { | 86 test("runs failing tests along with successful tests", () { |
85 _expectReport(""" | 87 _expectReport(""" |
86 test('failure 1', () => throw new TestFailure('oh no')); | 88 test('failure 1', () => throw new TestFailure('oh no')); |
87 test('success 1', () {}); | 89 test('success 1', () {}); |
88 test('failure 2', () => throw new TestFailure('oh no')); | 90 test('failure 2', () => throw new TestFailure('oh no')); |
89 test('success 2', () {});""", | 91 test('success 2', () {});""", |
90 """ | 92 """ |
| 93 +0: loading test.dart |
91 +0: failure 1 | 94 +0: failure 1 |
92 +0 -1: failure 1 | 95 +0 -1: failure 1 |
93 oh no | 96 oh no |
94 test.dart 6:33 main.<fn> | 97 test.dart 6:33 main.<fn> |
95 | 98 |
96 | 99 |
97 +0 -1: success 1 | 100 +0 -1: success 1 |
98 +1 -1: success 1 | 101 +1 -1: success 1 |
99 +1 -1: failure 2 | 102 +1 -1: failure 2 |
100 +1 -2: failure 2 | 103 +1 -2: failure 2 |
(...skipping 12 matching lines...) Expand all Loading... |
113 // errors have been thrown. | 116 // errors have been thrown. |
114 var completer = new Completer(); | 117 var completer = new Completer(); |
115 test('failures', () { | 118 test('failures', () { |
116 new Future.microtask(() => throw 'first error'); | 119 new Future.microtask(() => throw 'first error'); |
117 new Future.microtask(() => throw 'second error'); | 120 new Future.microtask(() => throw 'second error'); |
118 new Future.microtask(() => throw 'third error'); | 121 new Future.microtask(() => throw 'third error'); |
119 new Future.microtask(completer.complete); | 122 new Future.microtask(completer.complete); |
120 }); | 123 }); |
121 test('wait', () => completer.future);""", | 124 test('wait', () => completer.future);""", |
122 """ | 125 """ |
| 126 +0: loading test.dart |
123 +0: failures | 127 +0: failures |
124 +0 -1: failures | 128 +0 -1: failures |
125 first error | 129 first error |
126 test.dart 10:38 main.<fn>.<fn> | 130 test.dart 10:38 main.<fn>.<fn> |
127 ===== asynchronous gap =========================== | 131 ===== asynchronous gap =========================== |
128 dart:async Future.Future.microtask | 132 dart:async Future.Future.microtask |
129 test.dart 10:15 main.<fn> | 133 test.dart 10:15 main.<fn> |
130 | 134 |
131 second error | 135 second error |
132 test.dart 11:38 main.<fn>.<fn> | 136 test.dart 11:38 main.<fn>.<fn> |
(...skipping 16 matching lines...) Expand all Loading... |
149 group("print:", () { | 153 group("print:", () { |
150 test("handles multiple prints", () { | 154 test("handles multiple prints", () { |
151 _expectReport(""" | 155 _expectReport(""" |
152 test('test', () { | 156 test('test', () { |
153 print("one"); | 157 print("one"); |
154 print("two"); | 158 print("two"); |
155 print("three"); | 159 print("three"); |
156 print("four"); | 160 print("four"); |
157 });""", | 161 });""", |
158 """ | 162 """ |
| 163 +0: loading test.dart |
159 +0: test | 164 +0: test |
160 one | 165 one |
161 two | 166 two |
162 three | 167 three |
163 four | 168 four |
164 | 169 |
165 +1: test | 170 +1: test |
166 +1: All tests passed!"""); | 171 +1: All tests passed!"""); |
167 }); | 172 }); |
168 | 173 |
(...skipping 10 matching lines...) Expand all Loading... |
179 new Future(() => print("three")); | 184 new Future(() => print("three")); |
180 new Future(() => print("four")); | 185 new Future(() => print("four")); |
181 new Future(testDone.complete); | 186 new Future(testDone.complete); |
182 }); | 187 }); |
183 }); | 188 }); |
184 | 189 |
185 test('wait', () { | 190 test('wait', () { |
186 waitStarted.complete(); | 191 waitStarted.complete(); |
187 return testDone.future; | 192 return testDone.future; |
188 });""", """ | 193 });""", """ |
| 194 +0: loading test.dart |
189 +0: test | 195 +0: test |
190 +1: test | 196 +1: test |
191 +1: wait | 197 +1: wait |
192 +1: test | 198 +1: test |
193 one | 199 one |
194 two | 200 two |
195 three | 201 three |
196 four | 202 four |
197 | 203 |
198 +2: wait | 204 +2: wait |
(...skipping 18 matching lines...) Expand all Loading... |
217 completer.complete(); | 223 completer.complete(); |
218 }); | 224 }); |
219 | 225 |
220 print("one"); | 226 print("one"); |
221 print("two"); | 227 print("two"); |
222 throw "first error"; | 228 throw "first error"; |
223 }); | 229 }); |
224 | 230 |
225 test('wait', () => completer.future);""", | 231 test('wait', () => completer.future);""", |
226 """ | 232 """ |
| 233 +0: loading test.dart |
227 +0: test | 234 +0: test |
228 one | 235 one |
229 two | 236 two |
230 | 237 |
231 +0 -1: test | 238 +0 -1: test |
232 first error | 239 first error |
233 test.dart 24:11 main.<fn> | 240 test.dart 24:11 main.<fn> |
234 | 241 |
235 three | 242 three |
236 four | 243 four |
(...skipping 12 matching lines...) Expand all Loading... |
249 }); | 256 }); |
250 }); | 257 }); |
251 | 258 |
252 group("skip:", () { | 259 group("skip:", () { |
253 test("displays skipped tests separately", () { | 260 test("displays skipped tests separately", () { |
254 _expectReport(""" | 261 _expectReport(""" |
255 test('skip 1', () {}, skip: true); | 262 test('skip 1', () {}, skip: true); |
256 test('skip 2', () {}, skip: true); | 263 test('skip 2', () {}, skip: true); |
257 test('skip 3', () {}, skip: true);""", | 264 test('skip 3', () {}, skip: true);""", |
258 """ | 265 """ |
| 266 +0: loading test.dart |
259 +0: skip 1 | 267 +0: skip 1 |
260 +0 ~1: skip 1 | 268 +0 ~1: skip 1 |
261 +0 ~1: skip 2 | 269 +0 ~1: skip 2 |
262 +0 ~2: skip 2 | 270 +0 ~2: skip 2 |
263 +0 ~2: skip 3 | 271 +0 ~2: skip 3 |
264 +0 ~3: skip 3 | 272 +0 ~3: skip 3 |
265 +0 ~3: All tests skipped."""); | 273 +0 ~3: All tests skipped."""); |
266 }); | 274 }); |
267 | 275 |
268 test("runs skipped tests along with successful tests", () { | 276 test("runs skipped tests along with successful tests", () { |
269 _expectReport(""" | 277 _expectReport(""" |
270 test('skip 1', () {}, skip: true); | 278 test('skip 1', () {}, skip: true); |
271 test('success 1', () {}); | 279 test('success 1', () {}); |
272 test('skip 2', () {}, skip: true); | 280 test('skip 2', () {}, skip: true); |
273 test('success 2', () {});""", | 281 test('success 2', () {});""", |
274 """ | 282 """ |
| 283 +0: loading test.dart |
275 +0: skip 1 | 284 +0: skip 1 |
276 +0 ~1: skip 1 | 285 +0 ~1: skip 1 |
277 +0 ~1: success 1 | 286 +0 ~1: success 1 |
278 +1 ~1: success 1 | 287 +1 ~1: success 1 |
279 +1 ~1: skip 2 | 288 +1 ~1: skip 2 |
280 +1 ~2: skip 2 | 289 +1 ~2: skip 2 |
281 +1 ~2: success 2 | 290 +1 ~2: success 2 |
282 +2 ~2: success 2 | 291 +2 ~2: success 2 |
283 +2 ~2: All tests passed!"""); | 292 +2 ~2: All tests passed!"""); |
284 }); | 293 }); |
285 | 294 |
286 test("runs skipped tests along with successful and failing tests", () { | 295 test("runs skipped tests along with successful and failing tests", () { |
287 _expectReport(""" | 296 _expectReport(""" |
288 test('failure 1', () => throw new TestFailure('oh no')); | 297 test('failure 1', () => throw new TestFailure('oh no')); |
289 test('skip 1', () {}, skip: true); | 298 test('skip 1', () {}, skip: true); |
290 test('success 1', () {}); | 299 test('success 1', () {}); |
291 test('failure 2', () => throw new TestFailure('oh no')); | 300 test('failure 2', () => throw new TestFailure('oh no')); |
292 test('skip 2', () {}, skip: true); | 301 test('skip 2', () {}, skip: true); |
293 test('success 2', () {});""", | 302 test('success 2', () {});""", |
294 """ | 303 """ |
| 304 +0: loading test.dart |
295 +0: failure 1 | 305 +0: failure 1 |
296 +0 -1: failure 1 | 306 +0 -1: failure 1 |
297 oh no | 307 oh no |
298 test.dart 6:35 main.<fn> | 308 test.dart 6:35 main.<fn> |
299 | 309 |
300 | 310 |
301 +0 -1: skip 1 | 311 +0 -1: skip 1 |
302 +0 ~1 -1: skip 1 | 312 +0 ~1 -1: skip 1 |
303 +0 ~1 -1: success 1 | 313 +0 ~1 -1: success 1 |
304 +1 ~1 -1: success 1 | 314 +1 ~1 -1: success 1 |
305 +1 ~1 -1: failure 2 | 315 +1 ~1 -1: failure 2 |
306 +1 ~1 -2: failure 2 | 316 +1 ~1 -2: failure 2 |
307 oh no | 317 oh no |
308 test.dart 9:35 main.<fn> | 318 test.dart 9:35 main.<fn> |
309 | 319 |
310 | 320 |
311 +1 ~1 -2: skip 2 | 321 +1 ~1 -2: skip 2 |
312 +1 ~2 -2: skip 2 | 322 +1 ~2 -2: skip 2 |
313 +1 ~2 -2: success 2 | 323 +1 ~2 -2: success 2 |
314 +2 ~2 -2: success 2 | 324 +2 ~2 -2: success 2 |
315 +2 ~2 -2: Some tests failed."""); | 325 +2 ~2 -2: Some tests failed."""); |
316 }); | 326 }); |
317 | 327 |
318 test("displays the skip reason if available", () { | 328 test("displays the skip reason if available", () { |
319 _expectReport(""" | 329 _expectReport(""" |
320 test('skip 1', () {}, skip: 'some reason'); | 330 test('skip 1', () {}, skip: 'some reason'); |
321 test('skip 2', () {}, skip: 'or another');""", | 331 test('skip 2', () {}, skip: 'or another');""", |
322 """ | 332 """ |
| 333 +0: loading test.dart |
323 +0: skip 1 | 334 +0: skip 1 |
324 +0 ~1: skip 1 | 335 +0 ~1: skip 1 |
325 Skip: some reason | 336 Skip: some reason |
326 | 337 |
327 +0 ~1: skip 2 | 338 +0 ~1: skip 2 |
328 +0 ~2: skip 2 | 339 +0 ~2: skip 2 |
329 Skip: or another | 340 Skip: or another |
330 | 341 |
331 +0 ~2: All tests skipped."""); | 342 +0 ~2: All tests skipped."""); |
332 }); | 343 }); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // Un-indent the expected string. | 377 // Un-indent the expected string. |
367 var indentation = expected.indexOf(new RegExp("[^ ]")); | 378 var indentation = expected.indexOf(new RegExp("[^ ]")); |
368 expected = expected.split("\n").map((line) { | 379 expected = expected.split("\n").map((line) { |
369 if (line.isEmpty) return line; | 380 if (line.isEmpty) return line; |
370 return line.substring(indentation); | 381 return line.substring(indentation); |
371 }).join("\n"); | 382 }).join("\n"); |
372 | 383 |
373 expect(actual, equals(expected)); | 384 expect(actual, equals(expected)); |
374 }), completes); | 385 }), completes); |
375 } | 386 } |
OLD | NEW |