| 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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 | 9 |
| 10 import 'package:test/src/backend/invoker.dart'; | 10 import 'package:test/src/backend/invoker.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 void main() { | 32 void main() { |
| 33 tearDown(() { | 33 tearDown(() { |
| 34 if (_isolate != null) _isolate.kill(); | 34 if (_isolate != null) _isolate.kill(); |
| 35 _isolate = null; | 35 _isolate = null; |
| 36 | 36 |
| 37 if (_liveTest != null) _liveTest.close(); | 37 if (_liveTest != null) _liveTest.close(); |
| 38 _liveTest = null; | 38 _liveTest = null; |
| 39 }); | 39 }); |
| 40 | 40 |
| 41 test("sends a list of available tests on startup", () async { | 41 test("sends a list of available tests and groups on startup", () async { |
| 42 var response = await (await _spawnIsolate(_successfulTests)).first; | 42 var response = await (await _spawnIsolate(_successfulTests)).first; |
| 43 expect(response, containsPair("type", "success")); | 43 expect(response, containsPair("type", "success")); |
| 44 expect(response, contains("tests")); | 44 expect(response, contains("entries")); |
| 45 | 45 |
| 46 var tests = response["tests"]; | 46 var tests = response["entries"]; |
| 47 expect(tests, hasLength(3)); | 47 expect(tests, hasLength(3)); |
| 48 expect(tests[0], containsPair("name", "successful 1")); | 48 expect(tests[0], containsPair("name", "successful 1")); |
| 49 expect(tests[1], containsPair("name", "successful 2")); | 49 expect(tests[1], containsPair("name", "successful 2")); |
| 50 expect(tests[2], containsPair("name", "successful 3")); | 50 expect(tests[2], containsPair("type", "group")); |
| 51 expect(tests[2], containsPair("name", "successful")); |
| 52 expect(tests[2], contains("entries")); |
| 53 expect(tests[2]["entries"][0], containsPair("name", "successful 3")); |
| 51 }); | 54 }); |
| 52 | 55 |
| 53 test("waits for a returned future sending a response", () async { | 56 test("waits for a returned future sending a response", () async { |
| 54 var response = await (await _spawnIsolate(_asyncTests)).first; | 57 var response = await (await _spawnIsolate(_asyncTests)).first; |
| 55 expect(response, containsPair("type", "success")); | 58 expect(response, containsPair("type", "success")); |
| 56 expect(response, contains("tests")); | 59 expect(response, contains("entries")); |
| 57 | 60 |
| 58 var tests = response["tests"]; | 61 var tests = response["entries"]; |
| 59 expect(tests, hasLength(3)); | 62 expect(tests, hasLength(3)); |
| 60 expect(tests[0], containsPair("name", "successful 1")); | 63 expect(tests[0], containsPair("name", "successful 1")); |
| 61 expect(tests[1], containsPair("name", "successful 2")); | 64 expect(tests[1], containsPair("name", "successful 2")); |
| 62 expect(tests[2], containsPair("name", "successful 3")); | 65 expect(tests[2], containsPair("name", "successful 3")); |
| 63 }); | 66 }); |
| 64 | 67 |
| 65 test("sends an error response if loading fails", () async { | 68 test("sends an error response if loading fails", () async { |
| 66 var response = await (await _spawnIsolate(_loadError)).first; | 69 var response = await (await _spawnIsolate(_loadError)).first; |
| 67 expect(response, containsPair("type", "error")); | 70 expect(response, containsPair("type", "error")); |
| 68 expect(response, contains("error")); | 71 expect(response, contains("error")); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 }); | 259 }); |
| 257 } | 260 } |
| 258 | 261 |
| 259 /// Loads the first test defined in [entryPoint] in another isolate. | 262 /// Loads the first test defined in [entryPoint] in another isolate. |
| 260 /// | 263 /// |
| 261 /// This test will be automatically closed when the test is finished. | 264 /// This test will be automatically closed when the test is finished. |
| 262 Future<LiveTest> _isolateTest(void entryPoint(SendPort sendPort)) async { | 265 Future<LiveTest> _isolateTest(void entryPoint(SendPort sendPort)) async { |
| 263 var response = await (await _spawnIsolate(entryPoint)).first; | 266 var response = await (await _spawnIsolate(entryPoint)).first; |
| 264 expect(response, containsPair("type", "success")); | 267 expect(response, containsPair("type", "success")); |
| 265 | 268 |
| 266 var testMap = response["tests"].first; | 269 var testMap = response["entries"].first; |
| 270 expect(testMap, containsPair("type", "test")); |
| 267 var metadata = new Metadata.deserialize(testMap["metadata"]); | 271 var metadata = new Metadata.deserialize(testMap["metadata"]); |
| 268 var test = new IsolateTest(testMap["name"], metadata, testMap["sendPort"]); | 272 var test = new IsolateTest(testMap["name"], metadata, testMap["sendPort"]); |
| 269 var suite = new Suite([test]); | 273 var suite = new Suite([test]); |
| 270 _liveTest = test.load(suite); | 274 _liveTest = test.load(suite); |
| 271 return _liveTest; | 275 return _liveTest; |
| 272 } | 276 } |
| 273 | 277 |
| 274 /// Spawns an isolate from [entryPoint], sends it a new [SendPort], and returns | 278 /// Spawns an isolate from [entryPoint], sends it a new [SendPort], and returns |
| 275 /// the corresponding [ReceivePort]. | 279 /// the corresponding [ReceivePort]. |
| 276 /// | 280 /// |
| (...skipping 24 matching lines...) Expand all Loading... |
| 301 /// An isolate entrypoint that returns a function with the wrong arity. | 305 /// An isolate entrypoint that returns a function with the wrong arity. |
| 302 void _wrongArity(SendPort sendPort) { | 306 void _wrongArity(SendPort sendPort) { |
| 303 IsolateListener.start(sendPort, new Metadata(), () => (_) {}); | 307 IsolateListener.start(sendPort, new Metadata(), () => (_) {}); |
| 304 } | 308 } |
| 305 | 309 |
| 306 /// An isolate entrypoint that defines three tests that succeed. | 310 /// An isolate entrypoint that defines three tests that succeed. |
| 307 void _successfulTests(SendPort sendPort) { | 311 void _successfulTests(SendPort sendPort) { |
| 308 IsolateListener.start(sendPort, new Metadata(), () => () { | 312 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 309 test("successful 1", () {}); | 313 test("successful 1", () {}); |
| 310 test("successful 2", () {}); | 314 test("successful 2", () {}); |
| 311 test("successful 3", () {}); | 315 group("successful", () => test("3", () {})); |
| 312 }); | 316 }); |
| 313 } | 317 } |
| 314 | 318 |
| 315 /// An isolate entrypoint that defines three tests asynchronously. | 319 /// An isolate entrypoint that defines three tests asynchronously. |
| 316 void _asyncTests(SendPort sendPort) { | 320 void _asyncTests(SendPort sendPort) { |
| 317 IsolateListener.start(sendPort, new Metadata(), () => () { | 321 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 318 return new Future(() { | 322 return new Future(() { |
| 319 test("successful 1", () {}); | 323 test("successful 1", () {}); |
| 320 | 324 |
| 321 return new Future(() { | 325 return new Future(() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 /// An isolate entrypoint that defines a test that prints twice. | 398 /// An isolate entrypoint that defines a test that prints twice. |
| 395 void _printTest(SendPort sendPort) { | 399 void _printTest(SendPort sendPort) { |
| 396 IsolateListener.start(sendPort, new Metadata(), () => () { | 400 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 397 test("prints", () { | 401 test("prints", () { |
| 398 print("Hello,"); | 402 print("Hello,"); |
| 399 return new Future(() => print("world!")); | 403 return new Future(() => print("world!")); |
| 400 }); | 404 }); |
| 401 }); | 405 }); |
| 402 } | 406 } |
| 403 | 407 |
| OLD | NEW |