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:unittest/src/util/exit_codes.dart' as exit_codes; | 10 import 'package:test/src/util/exit_codes.dart' as exit_codes; |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:test/test.dart'; |
12 | 12 |
13 import '../io.dart'; | 13 import '../io.dart'; |
14 | 14 |
15 String _sandbox; | 15 String _sandbox; |
16 | 16 |
17 final _success = """ | 17 final _success = """ |
18 import 'dart:async'; | 18 import 'dart:async'; |
19 | 19 |
20 import 'package:unittest/unittest.dart'; | 20 import 'package:test/test.dart'; |
21 | 21 |
22 void main() { | 22 void main() { |
23 test("success", () {}); | 23 test("success", () {}); |
24 } | 24 } |
25 """; | 25 """; |
26 | 26 |
27 final _failure = """ | 27 final _failure = """ |
28 import 'dart:async'; | 28 import 'dart:async'; |
29 | 29 |
30 import 'package:unittest/unittest.dart'; | 30 import 'package:test/test.dart'; |
31 | 31 |
32 void main() { | 32 void main() { |
33 test("failure", () => throw new TestFailure("oh no")); | 33 test("failure", () => throw new TestFailure("oh no")); |
34 } | 34 } |
35 """; | 35 """; |
36 | 36 |
37 final _usage = """ | 37 final _usage = """ |
38 Usage: pub run unittest:unittest [files or directories...] | 38 Usage: pub run test:test [files or directories...] |
39 | 39 |
40 -h, --help Shows this usage information. | 40 -h, --help Shows this usage information. |
41 -n, --name A substring of the name of the test to run. | 41 -n, --name A substring of the name of the test to run. |
42 Regular expression syntax is supported. | 42 Regular expression syntax is supported. |
43 | 43 |
44 -N, --plain-name A plain-text substring of the name of the test to run. | 44 -N, --plain-name A plain-text substring of the name of the test to run. |
45 -p, --platform The platform(s) on which to run the tests. | 45 -p, --platform The platform(s) on which to run the tests. |
46 [vm (default), chrome] | 46 [vm (default), chrome] |
47 | 47 |
48 --[no-]color Whether to use terminal colors. | 48 --[no-]color Whether to use terminal colors. |
49 (auto-detected by default) | 49 (auto-detected by default) |
50 """; | 50 """; |
51 | 51 |
52 void main() { | 52 void main() { |
53 setUp(() { | 53 setUp(() { |
54 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; | 54 _sandbox = Directory.systemTemp.createTempSync('test_').path; |
55 }); | 55 }); |
56 | 56 |
57 tearDown(() { | 57 tearDown(() { |
58 new Directory(_sandbox).deleteSync(recursive: true); | 58 new Directory(_sandbox).deleteSync(recursive: true); |
59 }); | 59 }); |
60 | 60 |
61 test("prints help information", () { | 61 test("prints help information", () { |
62 var result = _runUnittest(["--help"]); | 62 var result = _runUnittest(["--help"]); |
63 expect(result.stdout, equals(""" | 63 expect(result.stdout, equals(""" |
64 Runs tests in this package. | 64 Runs tests in this package. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 var result = _runUnittest(["--color", "test.dart"]); | 274 var result = _runUnittest(["--color", "test.dart"]); |
275 // This is the color code for red. | 275 // This is the color code for red. |
276 expect(result.stdout, contains("\u001b[31m")); | 276 expect(result.stdout, contains("\u001b[31m")); |
277 }); | 277 }); |
278 | 278 |
279 group("with the --name flag,", () { | 279 group("with the --name flag,", () { |
280 test("selects tests with matching names", () { | 280 test("selects tests with matching names", () { |
281 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 281 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
282 import 'dart:async'; | 282 import 'dart:async'; |
283 | 283 |
284 import 'package:unittest/unittest.dart'; | 284 import 'package:test/test.dart'; |
285 | 285 |
286 void main() { | 286 void main() { |
287 test("selected 1", () {}); | 287 test("selected 1", () {}); |
288 test("nope", () => throw new TestFailure("oh no")); | 288 test("nope", () => throw new TestFailure("oh no")); |
289 test("selected 2", () {}); | 289 test("selected 2", () {}); |
290 } | 290 } |
291 """); | 291 """); |
292 | 292 |
293 var result = _runUnittest(["--name", "selected", "test.dart"]); | 293 var result = _runUnittest(["--name", "selected", "test.dart"]); |
294 expect(result.stdout, contains("+2: All tests passed!")); | 294 expect(result.stdout, contains("+2: All tests passed!")); |
295 expect(result.exitCode, equals(0)); | 295 expect(result.exitCode, equals(0)); |
296 }); | 296 }); |
297 | 297 |
298 test("supports RegExp syntax", () { | 298 test("supports RegExp syntax", () { |
299 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 299 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
300 import 'dart:async'; | 300 import 'dart:async'; |
301 | 301 |
302 import 'package:unittest/unittest.dart'; | 302 import 'package:test/test.dart'; |
303 | 303 |
304 void main() { | 304 void main() { |
305 test("test 1", () {}); | 305 test("test 1", () {}); |
306 test("test 2", () => throw new TestFailure("oh no")); | 306 test("test 2", () => throw new TestFailure("oh no")); |
307 test("test 3", () {}); | 307 test("test 3", () {}); |
308 } | 308 } |
309 """); | 309 """); |
310 | 310 |
311 var result = _runUnittest(["--name", "test [13]", "test.dart"]); | 311 var result = _runUnittest(["--name", "test [13]", "test.dart"]); |
312 expect(result.stdout, contains("+2: All tests passed!")); | 312 expect(result.stdout, contains("+2: All tests passed!")); |
313 expect(result.exitCode, equals(0)); | 313 expect(result.exitCode, equals(0)); |
314 }); | 314 }); |
315 | 315 |
316 test("produces an error when no tests match", () { | 316 test("produces an error when no tests match", () { |
317 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 317 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
318 | 318 |
319 var result = _runUnittest(["--name", "no match", "test.dart"]); | 319 var result = _runUnittest(["--name", "no match", "test.dart"]); |
320 expect(result.stderr, | 320 expect(result.stderr, |
321 contains('No tests match regular expression "no match".')); | 321 contains('No tests match regular expression "no match".')); |
322 expect(result.exitCode, equals(exit_codes.data)); | 322 expect(result.exitCode, equals(exit_codes.data)); |
323 }); | 323 }); |
324 }); | 324 }); |
325 | 325 |
326 group("with the --plain-name flag,", () { | 326 group("with the --plain-name flag,", () { |
327 test("selects tests with matching names", () { | 327 test("selects tests with matching names", () { |
328 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 328 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
329 import 'dart:async'; | 329 import 'dart:async'; |
330 | 330 |
331 import 'package:unittest/unittest.dart'; | 331 import 'package:test/test.dart'; |
332 | 332 |
333 void main() { | 333 void main() { |
334 test("selected 1", () {}); | 334 test("selected 1", () {}); |
335 test("nope", () => throw new TestFailure("oh no")); | 335 test("nope", () => throw new TestFailure("oh no")); |
336 test("selected 2", () {}); | 336 test("selected 2", () {}); |
337 } | 337 } |
338 """); | 338 """); |
339 | 339 |
340 var result = _runUnittest(["--plain-name", "selected", "test.dart"]); | 340 var result = _runUnittest(["--plain-name", "selected", "test.dart"]); |
341 expect(result.stdout, contains("+2: All tests passed!")); | 341 expect(result.stdout, contains("+2: All tests passed!")); |
342 expect(result.exitCode, equals(0)); | 342 expect(result.exitCode, equals(0)); |
343 }); | 343 }); |
344 | 344 |
345 test("doesn't support RegExp syntax", () { | 345 test("doesn't support RegExp syntax", () { |
346 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 346 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
347 import 'dart:async'; | 347 import 'dart:async'; |
348 | 348 |
349 import 'package:unittest/unittest.dart'; | 349 import 'package:test/test.dart'; |
350 | 350 |
351 void main() { | 351 void main() { |
352 test("test 1", () => throw new TestFailure("oh no")); | 352 test("test 1", () => throw new TestFailure("oh no")); |
353 test("test 2", () => throw new TestFailure("oh no")); | 353 test("test 2", () => throw new TestFailure("oh no")); |
354 test("test [12]", () {}); | 354 test("test [12]", () {}); |
355 } | 355 } |
356 """); | 356 """); |
357 | 357 |
358 var result = _runUnittest(["--plain-name", "test [12]", "test.dart"]); | 358 var result = _runUnittest(["--plain-name", "test [12]", "test.dart"]); |
359 expect(result.stdout, contains("+1: All tests passed!")); | 359 expect(result.stdout, contains("+1: All tests passed!")); |
(...skipping 10 matching lines...) Expand all Loading... |
370 }); | 370 }); |
371 }); | 371 }); |
372 }); | 372 }); |
373 } | 373 } |
374 | 374 |
375 ProcessResult _runUnittest(List<String> args) => | 375 ProcessResult _runUnittest(List<String> args) => |
376 runUnittest(args, workingDirectory: _sandbox); | 376 runUnittest(args, workingDirectory: _sandbox); |
377 | 377 |
378 ProcessResult _runDart(List<String> args) => | 378 ProcessResult _runDart(List<String> args) => |
379 runDart(args, workingDirectory: _sandbox); | 379 runDart(args, workingDirectory: _sandbox); |
OLD | NEW |