| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 expect(response, contains("tests")); | 49 expect(response, contains("tests")); |
| 50 | 50 |
| 51 var tests = response["tests"]; | 51 var tests = response["tests"]; |
| 52 expect(tests, hasLength(3)); | 52 expect(tests, hasLength(3)); |
| 53 expect(tests[0], containsPair("name", "successful 1")); | 53 expect(tests[0], containsPair("name", "successful 1")); |
| 54 expect(tests[1], containsPair("name", "successful 2")); | 54 expect(tests[1], containsPair("name", "successful 2")); |
| 55 expect(tests[2], containsPair("name", "successful 3")); | 55 expect(tests[2], containsPair("name", "successful 3")); |
| 56 }); | 56 }); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 test("waits for a returned future sending a response", () { |
| 60 return _spawnIsolate(_asyncTests).then((receivePort) { |
| 61 return receivePort.first; |
| 62 }).then((response) { |
| 63 expect(response, containsPair("type", "success")); |
| 64 expect(response, contains("tests")); |
| 65 |
| 66 var tests = response["tests"]; |
| 67 expect(tests, hasLength(3)); |
| 68 expect(tests[0], containsPair("name", "successful 1")); |
| 69 expect(tests[1], containsPair("name", "successful 2")); |
| 70 expect(tests[2], containsPair("name", "successful 3")); |
| 71 }); |
| 72 }); |
| 73 |
| 59 test("sends an error response if loading fails", () { | 74 test("sends an error response if loading fails", () { |
| 60 return _spawnIsolate(_loadError).then((receivePort) { | 75 return _spawnIsolate(_loadError).then((receivePort) { |
| 61 return receivePort.first; | 76 return receivePort.first; |
| 62 }).then((response) { | 77 }).then((response) { |
| 63 expect(response, containsPair("type", "error")); | 78 expect(response, containsPair("type", "error")); |
| 64 expect(response, contains("error")); | 79 expect(response, contains("error")); |
| 65 | 80 |
| 66 var error = RemoteException.deserialize(response["error"]).error; | 81 var error = RemoteException.deserialize(response["error"]).error; |
| 67 expect(error.message, equals("oh no")); | 82 expect(error.message, equals("oh no")); |
| 68 expect(error.type, equals("String")); | 83 expect(error.type, equals("String")); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 338 |
| 324 /// An isolate entrypoint that defines three tests that succeed. | 339 /// An isolate entrypoint that defines three tests that succeed. |
| 325 void _successfulTests(SendPort sendPort) { | 340 void _successfulTests(SendPort sendPort) { |
| 326 IsolateListener.start(sendPort, new Metadata(), () => () { | 341 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 327 test("successful 1", () {}); | 342 test("successful 1", () {}); |
| 328 test("successful 2", () {}); | 343 test("successful 2", () {}); |
| 329 test("successful 3", () {}); | 344 test("successful 3", () {}); |
| 330 }); | 345 }); |
| 331 } | 346 } |
| 332 | 347 |
| 348 /// An isolate entrypoint that defines three tests asynchronously. |
| 349 void _asyncTests(SendPort sendPort) { |
| 350 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 351 return new Future(() { |
| 352 test("successful 1", () {}); |
| 353 |
| 354 return new Future(() { |
| 355 test("successful 2", () {}); |
| 356 |
| 357 return new Future(() { |
| 358 test("successful 3", () {}); |
| 359 }); |
| 360 }); |
| 361 }); |
| 362 }); |
| 363 } |
| 364 |
| 333 /// An isolate entrypoint that defines a test that fails. | 365 /// An isolate entrypoint that defines a test that fails. |
| 334 void _failingTest(SendPort sendPort) { | 366 void _failingTest(SendPort sendPort) { |
| 335 IsolateListener.start(sendPort, new Metadata(), () => () { | 367 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 336 test("failure", () => throw new TestFailure('oh no')); | 368 test("failure", () => throw new TestFailure('oh no')); |
| 337 }); | 369 }); |
| 338 } | 370 } |
| 339 | 371 |
| 340 /// An isolate entrypoint that defines a test that fails after succeeding. | 372 /// An isolate entrypoint that defines a test that fails after succeeding. |
| 341 void _failAfterSucceedTest(SendPort sendPort) { | 373 void _failAfterSucceedTest(SendPort sendPort) { |
| 342 IsolateListener.start(sendPort, new Metadata(), () => () { | 374 IsolateListener.start(sendPort, new Metadata(), () => () { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 /// An isolate entrypoint that defines a test that prints twice. | 425 /// An isolate entrypoint that defines a test that prints twice. |
| 394 void _printTest(SendPort sendPort) { | 426 void _printTest(SendPort sendPort) { |
| 395 IsolateListener.start(sendPort, new Metadata(), () => () { | 427 IsolateListener.start(sendPort, new Metadata(), () => () { |
| 396 test("prints", () { | 428 test("prints", () { |
| 397 print("Hello,"); | 429 print("Hello,"); |
| 398 return new Future(() => print("world!")); | 430 return new Future(() => print("world!")); |
| 399 }); | 431 }); |
| 400 }); | 432 }); |
| 401 } | 433 } |
| 402 | 434 |
| OLD | NEW |