| Index: test/vm_listener_test.dart
|
| diff --git a/test/vm_listener_test.dart b/test/vm_listener_test.dart
|
| index b626ad151a72a86cf4cb05c007053674145c1d22..f401a0c7f1338a882cbbb97910c8390563629e3f 100644
|
| --- a/test/vm_listener_test.dart
|
| +++ b/test/vm_listener_test.dart
|
| @@ -5,10 +5,10 @@
|
| import 'dart:async';
|
| import 'dart:isolate';
|
|
|
| -import 'package:unittest/src/declarer.dart';
|
| import 'package:unittest/src/invoker.dart';
|
| import 'package:unittest/src/isolate_test.dart';
|
| import 'package:unittest/src/live_test.dart';
|
| +import 'package:unittest/src/remote_exception.dart';
|
| import 'package:unittest/src/state.dart';
|
| import 'package:unittest/src/suite.dart';
|
| import 'package:unittest/src/vm_listener.dart';
|
| @@ -16,9 +16,6 @@ import 'package:unittest/unittest.dart';
|
|
|
| import 'utils.dart';
|
|
|
| -/// The current declarer.
|
| -Declarer get _declarer => Zone.current[#unittest.declarer];
|
| -
|
| /// An isolate that's been spun up for the current test.
|
| ///
|
| /// This is tracked so that it can be killed once the test is done.
|
| @@ -41,7 +38,11 @@ void main() {
|
| test("sends a list of available tests on startup", () {
|
| return _spawnIsolate(_successfulTests).then((receivePort) {
|
| return receivePort.first;
|
| - }).then((tests) {
|
| + }).then((response) {
|
| + expect(response, containsPair("type", "success"));
|
| + expect(response, contains("tests"));
|
| +
|
| + var tests = response["tests"];
|
| expect(tests, hasLength(3));
|
| expect(tests[0], containsPair("name", "successful 1"));
|
| expect(tests[1], containsPair("name", "successful 2"));
|
| @@ -49,6 +50,52 @@ void main() {
|
| });
|
| });
|
|
|
| + test("sends an error response if loading fails", () {
|
| + return _spawnIsolate(_loadError).then((receivePort) {
|
| + return receivePort.first;
|
| + }).then((response) {
|
| + expect(response, containsPair("type", "error"));
|
| + expect(response, contains("error"));
|
| +
|
| + var error = RemoteException.deserialize(response["error"]).error;
|
| + expect(error.message, equals("oh no"));
|
| + expect(error.type, equals("String"));
|
| + });
|
| + });
|
| +
|
| + test("sends an error response on a NoSuchMethodError", () {
|
| + return _spawnIsolate(_noSuchMethodError).then((receivePort) {
|
| + return receivePort.first;
|
| + }).then((response) {
|
| + expect(response, containsPair("type", "loadException"));
|
| + expect(response,
|
| + containsPair("message", "No top-level main() function defined."));
|
| + });
|
| + });
|
| +
|
| + test("sends an error response on non-function main", () {
|
| + return _spawnIsolate(_nonFunction).then((receivePort) {
|
| + return receivePort.first;
|
| + }).then((response) {
|
| + expect(response, containsPair("type", "loadException"));
|
| + expect(response,
|
| + containsPair("message", "Top-level main getter is not a function."));
|
| + });
|
| + });
|
| +
|
| + test("sends an error response on wrong-arity main", () {
|
| + return _spawnIsolate(_wrongArity).then((receivePort) {
|
| + return receivePort.first;
|
| + }).then((response) {
|
| + expect(response, containsPair("type", "loadException"));
|
| + expect(
|
| + response,
|
| + containsPair(
|
| + "message",
|
| + "Top-level main() function takes arguments."));
|
| + });
|
| + });
|
| +
|
| group("in a successful test", () {
|
| test("the state changes from pending to running to complete", () {
|
| return _isolateTest(_successfulTests).then((liveTest) {
|
| @@ -218,7 +265,9 @@ Future<LiveTest> _isolateTest(void entryPoint(SendPort sendPort)) {
|
| return _spawnIsolate(entryPoint).then((receivePort) {
|
| return receivePort.first;
|
| }).then((response) {
|
| - var testMap = response.first;
|
| + expect(response, containsPair("type", "success"));
|
| +
|
| + var testMap = response["tests"].first;
|
| var test = new IsolateTest(testMap["name"], testMap["sendPort"]);
|
| var suite = new Suite("suite", [test]);
|
| _liveTest = test.load(suite);
|
| @@ -238,26 +287,44 @@ Future<ReceivePort> _spawnIsolate(void entryPoint(SendPort sendPort)) {
|
| });
|
| }
|
|
|
| +/// An isolate entrypoint that throws immediately.
|
| +void _loadError(SendPort sendPort) =>
|
| + VmListener.start(sendPort, () => () => throw 'oh no');
|
| +
|
| +/// An isolate entrypoint that throws a NoSuchMethodError.
|
| +void _noSuchMethodError(SendPort sendPort) {
|
| + return VmListener.start(sendPort, () =>
|
| + throw new NoSuchMethodError(null, #main, [], {}));
|
| +}
|
| +
|
| +/// An isolate entrypoint that returns a non-function.
|
| +void _nonFunction(SendPort sendPort) =>
|
| + VmListener.start(sendPort, () => null);
|
| +
|
| +/// An isolate entrypoint that returns a function with the wrong arity.
|
| +void _wrongArity(SendPort sendPort) =>
|
| + VmListener.start(sendPort, () => (_) {});
|
| +
|
| /// An isolate entrypoint that defines three tests that succeed.
|
| void _successfulTests(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("successful 1", () {});
|
| - _declarer.test("successful 2", () {});
|
| - _declarer.test("successful 3", () {});
|
| + VmListener.start(sendPort, () => () {
|
| + test("successful 1", () {});
|
| + test("successful 2", () {});
|
| + test("successful 3", () {});
|
| });
|
| }
|
|
|
| /// An isolate entrypoint that defines a test that fails.
|
| void _failingTest(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("failure", () => throw new TestFailure('oh no'));
|
| + VmListener.start(sendPort, () => () {
|
| + test("failure", () => throw new TestFailure('oh no'));
|
| });
|
| }
|
|
|
| /// An isolate entrypoint that defines a test that fails after succeeding.
|
| void _failAfterSucceedTest(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("fail after succeed", () {
|
| + VmListener.start(sendPort, () => () {
|
| + test("fail after succeed", () {
|
| pumpEventQueue().then((_) {
|
| throw new TestFailure('oh no');
|
| });
|
| @@ -267,8 +334,8 @@ void _failAfterSucceedTest(SendPort sendPort) {
|
|
|
| /// An isolate entrypoint that defines a test that fails multiple times.
|
| void _multiFailTest(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("multiple failures", () {
|
| + VmListener.start(sendPort, () => () {
|
| + test("multiple failures", () {
|
| Invoker.current.addOutstandingCallback();
|
| new Future(() => throw new TestFailure("one"));
|
| new Future(() => throw new TestFailure("two"));
|
| @@ -280,15 +347,15 @@ void _multiFailTest(SendPort sendPort) {
|
|
|
| /// An isolate entrypoint that defines a test that errors.
|
| void _errorTest(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("error", () => throw 'oh no');
|
| + VmListener.start(sendPort, () => () {
|
| + test("error", () => throw 'oh no');
|
| });
|
| }
|
|
|
| /// An isolate entrypoint that defines a test that errors after succeeding.
|
| void _errorAfterSucceedTest(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("error after succeed", () {
|
| + VmListener.start(sendPort, () => () {
|
| + test("error after succeed", () {
|
| pumpEventQueue().then((_) => throw 'oh no');
|
| });
|
| });
|
| @@ -296,8 +363,8 @@ void _errorAfterSucceedTest(SendPort sendPort) {
|
|
|
| /// An isolate entrypoint that defines a test that errors multiple times.
|
| void _multiErrorTest(SendPort sendPort) {
|
| - VmListener.start(sendPort, () {
|
| - _declarer.test("multiple errors", () {
|
| + VmListener.start(sendPort, () => () {
|
| + test("multiple errors", () {
|
| Invoker.current.addOutstandingCallback();
|
| new Future(() => throw "one");
|
| new Future(() => throw "two");
|
|
|