Chromium Code Reviews| 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'; |
|
kevmoo
2015/07/22 04:10:12
now unused
nweiz
2015/07/22 18:35:48
Done.
| |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:scheduled_test/descriptor.dart' as d; |
| 10 import 'package:scheduled_test/scheduled_stream.dart'; | |
| 11 import 'package:scheduled_test/scheduled_test.dart'; | |
| 10 import 'package:test/src/util/io.dart'; | 12 import 'package:test/src/util/io.dart'; |
|
kevmoo
2015/07/22 04:10:12
now unused
nweiz
2015/07/22 18:35:48
Done.
| |
| 11 import 'package:test/test.dart'; | |
| 12 | 13 |
| 13 import '../io.dart'; | 14 import '../io.dart'; |
| 14 | 15 |
| 15 void main() { | 16 void main() { |
| 17 useSandbox(); | |
| 18 | |
| 16 test("reports when no tests are run", () { | 19 test("reports when no tests are run", () { |
| 17 return withTempDir((path) { | 20 d.file("test.dart", "void main() {}").create(); |
| 18 new File(p.join(path, "test.dart")).writeAsStringSync("void main() {}"); | 21 |
| 19 var result = runTest(["-r", "expanded", "test.dart"], | 22 var test = runTest(["test.dart"], compact: true); |
| 20 workingDirectory: path); | 23 test.stdout.expect(consumeThrough(contains("No tests ran."))); |
| 21 expect(result.stdout, contains("No tests ran.")); | 24 test.shouldExit(0); |
| 22 }); | |
| 23 }); | 25 }); |
| 24 | 26 |
| 25 test("runs several successful tests and reports when each completes", () { | 27 test("runs several successful tests and reports when each completes", () { |
| 26 _expectReport(""" | 28 _expectReport(""" |
| 27 test('success 1', () {}); | 29 test('success 1', () {}); |
| 28 test('success 2', () {}); | 30 test('success 2', () {}); |
| 29 test('success 3', () {});""", | 31 test('success 3', () {});""", |
| 30 """ | 32 """ |
| 31 +0: success 1 | 33 +0: success 1 |
| 32 +1: success 2 | 34 +1: success 2 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 52 | 54 |
| 53 +0 -2: failure 3 | 55 +0 -2: failure 3 |
| 54 +0 -3: failure 3 | 56 +0 -3: failure 3 |
| 55 oh no | 57 oh no |
| 56 test.dart 8:33 main.<fn> | 58 test.dart 8:33 main.<fn> |
| 57 | 59 |
| 58 +0 -3: Some tests failed."""); | 60 +0 -3: Some tests failed."""); |
| 59 }); | 61 }); |
| 60 | 62 |
| 61 test("includes the full stack trace with --verbose-trace", () { | 63 test("includes the full stack trace with --verbose-trace", () { |
| 62 return withTempDir((path) { | 64 d.file("test.dart", """ |
| 63 new File(p.join(path, "test.dart")).writeAsStringSync(""" | |
| 64 import 'dart:async'; | 65 import 'dart:async'; |
| 65 | 66 |
| 66 import 'package:test/test.dart'; | 67 import 'package:test/test.dart'; |
| 67 | 68 |
| 68 void main() { | 69 void main() { |
| 69 test("failure", () => throw "oh no"); | 70 test("failure", () => throw "oh no"); |
| 70 } | 71 } |
| 71 """); | 72 """).create(); |
| 72 var result = runTest(["-r", "compact", "--verbose-trace", "test.dart"], | 73 |
| 73 workingDirectory: path); | 74 var test = runTest(["--verbose-trace", "test.dart"], compact: true); |
| 74 expect(result.stdout, contains("dart:isolate-patch")); | 75 test.stdout.expect(consumeThrough(contains("dart:isolate-patch"))); |
| 75 }); | 76 test.shouldExit(1); |
| 76 }); | 77 }); |
| 77 | 78 |
| 78 test("runs failing tests along with successful tests", () { | 79 test("runs failing tests along with successful tests", () { |
| 79 _expectReport(""" | 80 _expectReport(""" |
| 80 test('failure 1', () => throw new TestFailure('oh no')); | 81 test('failure 1', () => throw new TestFailure('oh no')); |
| 81 test('success 1', () {}); | 82 test('success 1', () {}); |
| 82 test('failure 2', () => throw new TestFailure('oh no')); | 83 test('failure 2', () => throw new TestFailure('oh no')); |
| 83 test('success 2', () {});""", | 84 test('success 2', () {});""", |
| 84 """ | 85 """ |
| 85 +0: failure 1 | 86 +0: failure 1 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 +0 ~1: skip 1 | 303 +0 ~1: skip 1 |
| 303 Skip: some reason | 304 Skip: some reason |
| 304 +0 ~1: skip 2 | 305 +0 ~1: skip 2 |
| 305 +0 ~2: skip 2 | 306 +0 ~2: skip 2 |
| 306 Skip: or another | 307 Skip: or another |
| 307 +0 ~2: All tests skipped."""); | 308 +0 ~2: All tests skipped."""); |
| 308 }); | 309 }); |
| 309 }); | 310 }); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void _expectReport(String tests, String expected, {List<String> args, | 313 void _expectReport(String tests, String expected) { |
| 313 int concurrency}) { | |
| 314 if (concurrency == null) concurrency = 1; | |
| 315 | |
| 316 var dart = """ | 314 var dart = """ |
| 317 import 'dart:async'; | 315 import 'dart:async'; |
| 318 | 316 |
| 319 import 'package:test/test.dart'; | 317 import 'package:test/test.dart'; |
| 320 | 318 |
| 321 void main() { | 319 void main() { |
| 322 $tests | 320 $tests |
| 323 } | 321 } |
| 324 """; | 322 """; |
| 325 | 323 |
| 326 expect(withTempDir((path) { | 324 d.file("test.dart", dart).create(); |
| 327 new File(p.join(path, "test.dart")).writeAsStringSync(dart); | 325 |
| 328 if (args == null) args = []; | 326 var test = runTest(["test.dart"]); |
| 329 args = args.toList() | 327 test.shouldExit(); |
| 330 ..add("test.dart") | 328 |
| 331 ..add("--concurrency=$concurrency") | 329 schedule(() async { |
| 332 ..add("--reporter=expanded"); | 330 var stdoutLines = await test.stdoutStream().toList(); |
| 333 var result = runTest(args, workingDirectory: path); | |
| 334 | 331 |
| 335 // Remove excess trailing whitespace and trim off timestamps. | 332 // Remove excess trailing whitespace and trim off timestamps. |
| 336 var actual = result.stdout.trim().split("\n").map((line) { | 333 var actual = stdoutLines.map((line) { |
| 337 if (line.startsWith(" ") || line.isEmpty) return line.trimRight(); | 334 if (line.startsWith(" ") || line.isEmpty) return line.trimRight(); |
| 338 return line.trim().replaceFirst(new RegExp("^[0-9]{2}:[0-9]{2} "), ""); | 335 return line.trim().replaceFirst(new RegExp("^[0-9]{2}:[0-9]{2} "), ""); |
| 339 }).join("\n"); | 336 }).join("\n"); |
| 340 | 337 |
| 341 // Un-indent the expected string. | 338 // Un-indent the expected string. |
| 342 var indentation = expected.indexOf(new RegExp("[^ ]")); | 339 var indentation = expected.indexOf(new RegExp("[^ ]")); |
| 343 expected = expected.split("\n").map((line) { | 340 expected = expected.split("\n").map((line) { |
| 344 if (line.isEmpty) return line; | 341 if (line.isEmpty) return line; |
| 345 return line.substring(indentation); | 342 return line.substring(indentation); |
| 346 }).join("\n"); | 343 }).join("\n"); |
| 347 | 344 |
| 348 expect(actual, equals(expected)); | 345 expect(actual, equals(expected)); |
| 349 }), completes); | 346 }); |
| 350 } | 347 } |
| OLD | NEW |