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; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 /// Sets up a test with the given [description] and [body]. After the test runs, | 65 /// Sets up a test with the given [description] and [body]. After the test runs, |
66 /// calls [validate] with the result map. | 66 /// calls [validate] with the result map. |
67 void _setUpTest(String description, void body(), | 67 void _setUpTest(String description, void body(), |
68 void validate(List<LiveTest> liveTests), {String testOn, Timeout timeout, | 68 void validate(List<LiveTest> liveTests), {String testOn, Timeout timeout, |
69 skip, Map<String, dynamic> onPlatform}) { | 69 skip, Map<String, dynamic> onPlatform}) { |
70 test(description, () async { | 70 test(description, () async { |
71 var declarer = new Declarer(); | 71 var declarer = new Declarer(); |
72 runZoned(body, zoneValues: {#test.declarer: declarer}); | 72 runZoned(body, zoneValues: {#test.declarer: declarer}); |
73 | 73 |
74 var engine = new Engine.withSuites([ | 74 var engine = new Engine.withSuites([ |
75 new RunnerSuite(new VMEnvironment(), declarer.tests) | 75 new RunnerSuite(new VMEnvironment(), declarer.build()) |
76 ]); | 76 ]); |
77 for (var test in engine.liveTests) { | 77 for (var test in engine.liveTests) { |
78 test.onPrint.listen(print); | 78 test.onPrint.listen(print); |
79 } | 79 } |
80 await engine.run(); | 80 await engine.run(); |
81 | 81 |
82 validate(engine.liveTests); | 82 validate(engine.liveTests); |
83 }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); | 83 }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); |
84 } | 84 } |
85 | 85 |
86 /// Returns a string description of the test run descibed by [liveTests]. | 86 /// Returns a string description of the test run descibed by [liveTests]. |
87 String _summarizeTests(List<LiveTest> liveTests) { | 87 String _summarizeTests(List<LiveTest> liveTests) { |
88 var buffer = new StringBuffer(); | 88 var buffer = new StringBuffer(); |
89 for (var liveTest in liveTests) { | 89 for (var liveTest in liveTests) { |
90 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}"); | 90 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}"); |
91 for (var error in liveTest.errors) { | 91 for (var error in liveTest.errors) { |
92 buffer.writeln(error.error); | 92 buffer.writeln(error.error); |
93 if (error.stackTrace != null) buffer.writeln(error.stackTrace); | 93 if (error.stackTrace != null) buffer.writeln(error.stackTrace); |
94 } | 94 } |
95 } | 95 } |
96 return buffer.toString(); | 96 return buffer.toString(); |
97 } | 97 } |
OLD | NEW |