OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// A test library for testing test libraries? We must go deeper. | 5 /// A test library for testing test libraries? We must go deeper. |
6 /// | 6 /// |
7 /// Since unit testing code tends to use a lot of global state, it can be tough | 7 /// Since unit testing code tends to use a lot of global state, it can be tough |
8 /// to test. This library manages it by running each test case in a child | 8 /// to test. This library manages it by running each test case in a child |
9 /// isolate, then reporting the results back to the parent isolate. | 9 /// isolate, then reporting the results back to the parent isolate. |
10 library metatest; | 10 library metatest; |
11 | 11 |
12 import 'dart:async'; | 12 import 'dart:async'; |
13 | 13 |
14 // TODO(nweiz): Stop importing from src when dart-lang/test#48 is fixed. | 14 // TODO(nweiz): Stop importing from src when dart-lang/test#48 is fixed. |
15 import 'package:test/src/backend/declarer.dart'; | 15 import 'package:test/src/backend/declarer.dart'; |
16 import 'package:test/src/backend/live_test.dart'; | 16 import 'package:test/src/backend/live_test.dart'; |
17 import 'package:test/src/backend/state.dart'; | 17 import 'package:test/src/backend/state.dart'; |
18 import 'package:test/src/backend/suite.dart'; | 18 import 'package:test/src/backend/suite.dart'; |
kevmoo
2015/08/26 21:25:39
now usused
nweiz
2015/08/26 21:28:00
Done.
| |
19 import 'package:test/src/runner/engine.dart'; | 19 import 'package:test/src/runner/engine.dart'; |
20 import 'package:test/src/runner/runner_suite.dart'; | |
21 import 'package:test/src/runner/vm/environment.dart'; | |
20 import 'package:test/test.dart'; | 22 import 'package:test/test.dart'; |
21 | 23 |
22 /// Declares a test with the given [description] and [body]. | 24 /// Declares a test with the given [description] and [body]. |
23 /// | 25 /// |
24 /// [body] corresponds to the `main` method of a test file. By default, this | 26 /// [body] corresponds to the `main` method of a test file. By default, this |
25 /// expects that all tests defined in [body] pass, but if [passing] is passed, | 27 /// expects that all tests defined in [body] pass, but if [passing] is passed, |
26 /// only tests listed there are expected to pass. | 28 /// only tests listed there are expected to pass. |
27 void expectTestsPass(String description, void body(), {List<String> passing, | 29 void expectTestsPass(String description, void body(), {List<String> passing, |
28 String testOn, Timeout timeout, skip, Map<String, dynamic> onPlatform}) { | 30 String testOn, Timeout timeout, skip, Map<String, dynamic> onPlatform}) { |
29 _setUpTest(description, body, (liveTests) { | 31 _setUpTest(description, body, (liveTests) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 | 65 |
64 /// Sets up a test with the given [description] and [body]. After the test runs, | 66 /// Sets up a test with the given [description] and [body]. After the test runs, |
65 /// calls [validate] with the result map. | 67 /// calls [validate] with the result map. |
66 void _setUpTest(String description, void body(), | 68 void _setUpTest(String description, void body(), |
67 void validate(List<LiveTest> liveTests), {String testOn, Timeout timeout, | 69 void validate(List<LiveTest> liveTests), {String testOn, Timeout timeout, |
68 skip, Map<String, dynamic> onPlatform}) { | 70 skip, Map<String, dynamic> onPlatform}) { |
69 test(description, () async { | 71 test(description, () async { |
70 var declarer = new Declarer(); | 72 var declarer = new Declarer(); |
71 runZoned(body, zoneValues: {#test.declarer: declarer}); | 73 runZoned(body, zoneValues: {#test.declarer: declarer}); |
72 | 74 |
73 var engine = new Engine.withSuites([new Suite(declarer.tests)]); | 75 var engine = new Engine.withSuites([ |
76 new RunnerSuite(new VMEnvironment(), declarer.tests) | |
77 ]); | |
74 for (var test in engine.liveTests) { | 78 for (var test in engine.liveTests) { |
75 test.onPrint.listen(print); | 79 test.onPrint.listen(print); |
76 } | 80 } |
77 await engine.run(); | 81 await engine.run(); |
78 | 82 |
79 validate(engine.liveTests); | 83 validate(engine.liveTests); |
80 }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); | 84 }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); |
81 } | 85 } |
82 | 86 |
83 /// Returns a string description of the test run descibed by [liveTests]. | 87 /// Returns a string description of the test run descibed by [liveTests]. |
84 String _summarizeTests(List<LiveTest> liveTests) { | 88 String _summarizeTests(List<LiveTest> liveTests) { |
85 var buffer = new StringBuffer(); | 89 var buffer = new StringBuffer(); |
86 for (var liveTest in liveTests) { | 90 for (var liveTest in liveTests) { |
87 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}"); | 91 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}"); |
88 for (var error in liveTest.errors) { | 92 for (var error in liveTest.errors) { |
89 buffer.writeln(error.error); | 93 buffer.writeln(error.error); |
90 if (error.stackTrace != null) buffer.writeln(error.stackTrace); | 94 if (error.stackTrace != null) buffer.writeln(error.stackTrace); |
91 } | 95 } |
92 } | 96 } |
93 return buffer.toString(); | 97 return buffer.toString(); |
94 } | 98 } |
OLD | NEW |