| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'dart:isolate'; | 13 import 'dart:isolate'; |
| 14 | 14 |
| 15 import '../../../pkg/path/lib/path.dart' as path; | 15 import '../../../pkg/path/lib/path.dart' as path; |
| 16 import 'package:scheduled_test/src/utils.dart'; | 16 import 'package:scheduled_test/src/utils.dart'; |
| 17 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 18 | 18 |
| 19 import 'utils.dart'; |
| 20 |
| 19 /// Declares a test with the given [description] and [body]. [body] corresponds | 21 /// Declares a test with the given [description] and [body]. [body] corresponds |
| 20 /// to the `main` method of a test file, and will be run in an isolate. By | 22 /// to the `main` method of a test file, and will be run in an isolate. By |
| 21 /// default, this expects that all tests defined in [body] pass, but if | 23 /// default, this expects that all tests defined in [body] pass, but if |
| 22 /// [passing] is passed, only tests listed there are expected to pass. | 24 /// [passing] is passed, only tests listed there are expected to pass. |
| 23 void expectTestsPass(String description, void body(), {List<String> passing}) { | 25 void expectTestsPass(String description, void body(), {List<String> passing}) { |
| 24 _setUpTest(description, body, (results) { | 26 _setUpTest(description, body, (results) { |
| 25 if (_hasError(results)) { | 27 if (_hasError(results)) { |
| 26 throw 'Expected all tests to pass, but got error(s):\n' | 28 throw 'Expected all tests to pass, but got error(s):\n' |
| 27 '${_summarizeTests(results)}'; | 29 '${_summarizeTests(results)}'; |
| 28 } else if (passing == null) { | 30 } else if (passing == null) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 "message": testCase.message, | 198 "message": testCase.message, |
| 197 "result": testCase.result, | 199 "result": testCase.result, |
| 198 "stackTrace": testCase.stackTrace | 200 "stackTrace": testCase.stackTrace |
| 199 }).toList() | 201 }).toList() |
| 200 }); | 202 }); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void onInit() {} | 205 void onInit() {} |
| 204 void onDone(bool success) {} | 206 void onDone(bool success) {} |
| 205 } | 207 } |
| OLD | NEW |