| 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:io'; | 13 import 'dart:io'; |
| 14 import 'dart:isolate'; | 14 import 'dart:isolate'; |
| 15 import 'dart:platform' as platform; | |
| 16 | 15 |
| 17 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
| 18 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 19 import 'package:scheduled_test/scheduled_test.dart' as scheduled_test; | 18 import 'package:scheduled_test/scheduled_test.dart' as scheduled_test; |
| 20 | 19 |
| 21 import 'utils.dart'; | 20 import 'utils.dart'; |
| 22 | 21 |
| 23 /// Declares a test with the given [description] and [body]. [body] corresponds | 22 /// Declares a test with the given [description] and [body]. [body] corresponds |
| 24 /// to the `main` method of a test file, and will be run in an isolate. By | 23 /// to the `main` method of a test file, and will be run in an isolate. By |
| 25 /// default, this expects that all tests defined in [body] pass, but if | 24 /// default, this expects that all tests defined in [body] pass, but if |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 _testToRun = message['testToRun']; | 112 _testToRun = message['testToRun']; |
| 114 _replyTo = message['replyTo']; | 113 _replyTo = message['replyTo']; |
| 115 _inChildIsolate = true; | 114 _inChildIsolate = true; |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 | 117 |
| 119 /// Runs the test described by [description] in its own isolate. Returns a map | 118 /// Runs the test described by [description] in its own isolate. Returns a map |
| 120 /// describing the results of that test run. | 119 /// describing the results of that test run. |
| 121 Future<Map> _runInIsolate(String description) { | 120 Future<Map> _runInIsolate(String description) { |
| 122 var replyPort = new ReceivePort(); | 121 var replyPort = new ReceivePort(); |
| 123 return Isolate.spawnUri(platform.script, [], { | 122 return Isolate.spawnUri(Uri.parse(Platform.script), [], { |
| 124 'testToRun': description, | 123 'testToRun': description, |
| 125 'replyTo': replyPort.sendPort | 124 'replyTo': replyPort.sendPort |
| 126 }).then((_) { | 125 }).then((_) { |
| 127 // TODO(nweiz): Remove this timeout once issue 8417 is fixed and we can | 126 // TODO(nweiz): Remove this timeout once issue 8417 is fixed and we can |
| 128 // capture top-level exceptions. | 127 // capture top-level exceptions. |
| 129 return timeout(replyPort.first, 30 * 1000, () { | 128 return timeout(replyPort.first, 30 * 1000, () { |
| 130 throw 'Timed out waiting for test to complete.'; | 129 throw 'Timed out waiting for test to complete.'; |
| 131 }); | 130 }); |
| 132 }); | 131 }); |
| 133 } | 132 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 "uncaughtError": uncaughtError, | 200 "uncaughtError": uncaughtError, |
| 202 "results": results.map((testCase) => { | 201 "results": results.map((testCase) => { |
| 203 "description": testCase.description, | 202 "description": testCase.description, |
| 204 "message": testCase.message, | 203 "message": testCase.message, |
| 205 "result": testCase.result, | 204 "result": testCase.result, |
| 206 "stackTrace": testCase.stackTrace | 205 "stackTrace": testCase.stackTrace |
| 207 }).toList() | 206 }).toList() |
| 208 }); | 207 }); |
| 209 } | 208 } |
| 210 } | 209 } |
| OLD | NEW |