| 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 | 8 |
| 9 import 'package:test/src/backend/state.dart'; | 9 import 'package:test/src/backend/state.dart'; |
| 10 import 'package:test/src/backend/test_platform.dart'; | 10 import 'package:test/src/backend/test_platform.dart'; |
| 11 import 'package:test/src/runner/load_exception.dart'; | 11 import 'package:test/src/runner/load_exception.dart'; |
| 12 import 'package:test/src/runner/load_suite.dart'; | 12 import 'package:test/src/runner/load_suite.dart'; |
| 13 import 'package:test/src/runner/runner_suite.dart'; | 13 import 'package:test/src/runner/runner_suite.dart'; |
| 14 import 'package:test/src/runner/vm/environment.dart'; | 14 import 'package:test/src/runner/vm/environment.dart'; |
| 15 import 'package:test/test.dart'; | 15 import 'package:test/test.dart'; |
| 16 | 16 |
| 17 import '../utils.dart'; | 17 import '../utils.dart'; |
| 18 | 18 |
| 19 void main() { | 19 void main() { |
| 20 var innerSuite; | 20 var innerSuite; |
| 21 setUp(() => innerSuite = new RunnerSuite(const VMEnvironment(), [])); | 21 setUp(() => innerSuite = new RunnerSuite(const VMEnvironment(), [])); |
| 22 | 22 |
| 23 test("running a load test causes LoadSuite.suite to emit a suite", () async { | 23 test("running a load test causes LoadSuite.suite to emit a suite", () async { |
| 24 var suite = new LoadSuite("name", () => new Future.value(innerSuite)); | 24 var suite = new LoadSuite("name", () => new Future.value(innerSuite)); |
| 25 expect(suite.tests, hasLength(1)); | 25 expect(suite.entries, hasLength(1)); |
| 26 | 26 |
| 27 expect(suite.suite, completion(equals(innerSuite))); | 27 expect(suite.suite, completion(equals(innerSuite))); |
| 28 var liveTest = await suite.tests.single.load(suite); | 28 var liveTest = await suite.entries.single.load(suite); |
| 29 await liveTest.run(); | 29 await liveTest.run(); |
| 30 expectTestPassed(liveTest); | 30 expectTestPassed(liveTest); |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 test("running a load suite's body may be synchronous", () async { | 33 test("running a load suite's body may be synchronous", () async { |
| 34 var suite = new LoadSuite("name", () => innerSuite); | 34 var suite = new LoadSuite("name", () => innerSuite); |
| 35 expect(suite.tests, hasLength(1)); | 35 expect(suite.entries, hasLength(1)); |
| 36 | 36 |
| 37 expect(suite.suite, completion(equals(innerSuite))); | 37 expect(suite.suite, completion(equals(innerSuite))); |
| 38 var liveTest = await suite.tests.single.load(suite); | 38 var liveTest = await suite.entries.single.load(suite); |
| 39 await liveTest.run(); | 39 await liveTest.run(); |
| 40 expectTestPassed(liveTest); | 40 expectTestPassed(liveTest); |
| 41 }); | 41 }); |
| 42 | 42 |
| 43 test("a load test doesn't complete until the body returns", () async { | 43 test("a load test doesn't complete until the body returns", () async { |
| 44 var completer = new Completer(); | 44 var completer = new Completer(); |
| 45 var suite = new LoadSuite("name", () => completer.future); | 45 var suite = new LoadSuite("name", () => completer.future); |
| 46 expect(suite.tests, hasLength(1)); | 46 expect(suite.entries, hasLength(1)); |
| 47 | 47 |
| 48 var liveTest = await suite.tests.single.load(suite); | 48 var liveTest = await suite.entries.single.load(suite); |
| 49 expect(liveTest.run(), completes); | 49 expect(liveTest.run(), completes); |
| 50 await new Future.delayed(Duration.ZERO); | 50 await new Future.delayed(Duration.ZERO); |
| 51 expect(liveTest.state.status, equals(Status.running)); | 51 expect(liveTest.state.status, equals(Status.running)); |
| 52 | 52 |
| 53 completer.complete(innerSuite); | 53 completer.complete(innerSuite); |
| 54 await new Future.delayed(Duration.ZERO); | 54 await new Future.delayed(Duration.ZERO); |
| 55 expectTestPassed(liveTest); | 55 expectTestPassed(liveTest); |
| 56 }); | 56 }); |
| 57 | 57 |
| 58 test("a load test forwards errors and completes LoadSuite.suite to null", | 58 test("a load test forwards errors and completes LoadSuite.suite to null", |
| 59 () async { | 59 () async { |
| 60 var suite = new LoadSuite("name", () => fail("error")); | 60 var suite = new LoadSuite("name", () => fail("error")); |
| 61 expect(suite.tests, hasLength(1)); | 61 expect(suite.entries, hasLength(1)); |
| 62 | 62 |
| 63 expect(suite.suite, completion(isNull)); | 63 expect(suite.suite, completion(isNull)); |
| 64 | 64 |
| 65 var liveTest = await suite.tests.single.load(suite); | 65 var liveTest = await suite.entries.single.load(suite); |
| 66 await liveTest.run(); | 66 await liveTest.run(); |
| 67 expectTestFailed(liveTest, "error"); | 67 expectTestFailed(liveTest, "error"); |
| 68 }); | 68 }); |
| 69 | 69 |
| 70 test("a load test completes early if it's closed", () async { | 70 test("a load test completes early if it's closed", () async { |
| 71 var suite = new LoadSuite("name", () => new Completer().future); | 71 var suite = new LoadSuite("name", () => new Completer().future); |
| 72 expect(suite.tests, hasLength(1)); | 72 expect(suite.entries, hasLength(1)); |
| 73 | 73 |
| 74 var liveTest = await suite.tests.single.load(suite); | 74 var liveTest = await suite.entries.single.load(suite); |
| 75 expect(liveTest.run(), completes); | 75 expect(liveTest.run(), completes); |
| 76 await new Future.delayed(Duration.ZERO); | 76 await new Future.delayed(Duration.ZERO); |
| 77 expect(liveTest.state.status, equals(Status.running)); | 77 expect(liveTest.state.status, equals(Status.running)); |
| 78 | 78 |
| 79 expect(liveTest.close(), completes); | 79 expect(liveTest.close(), completes); |
| 80 }); | 80 }); |
| 81 | 81 |
| 82 test("forLoadException() creates a suite that completes to a LoadException", | 82 test("forLoadException() creates a suite that completes to a LoadException", |
| 83 () async { | 83 () async { |
| 84 var exception = new LoadException("path", "error"); | 84 var exception = new LoadException("path", "error"); |
| 85 var suite = new LoadSuite.forLoadException(exception); | 85 var suite = new LoadSuite.forLoadException(exception); |
| 86 expect(suite.tests, hasLength(1)); | 86 expect(suite.entries, hasLength(1)); |
| 87 | 87 |
| 88 expect(suite.suite, completion(isNull)); | 88 expect(suite.suite, completion(isNull)); |
| 89 | 89 |
| 90 var liveTest = await suite.tests.single.load(suite); | 90 var liveTest = await suite.entries.single.load(suite); |
| 91 await liveTest.run(); | 91 await liveTest.run(); |
| 92 expect(liveTest.state.status, equals(Status.complete)); | 92 expect(liveTest.state.status, equals(Status.complete)); |
| 93 expect(liveTest.state.result, equals(Result.error)); | 93 expect(liveTest.state.result, equals(Result.error)); |
| 94 expect(liveTest.errors, hasLength(1)); | 94 expect(liveTest.errors, hasLength(1)); |
| 95 expect(liveTest.errors.first.error, equals(exception)); | 95 expect(liveTest.errors.first.error, equals(exception)); |
| 96 }); | 96 }); |
| 97 | 97 |
| 98 test("forSuite() creates a load suite that completes to a test suite", | 98 test("forSuite() creates a load suite that completes to a test suite", |
| 99 () async { | 99 () async { |
| 100 var suite = new LoadSuite.forSuite(innerSuite); | 100 var suite = new LoadSuite.forSuite(innerSuite); |
| 101 expect(suite.tests, hasLength(1)); | 101 expect(suite.entries, hasLength(1)); |
| 102 | 102 |
| 103 expect(suite.suite, completion(equals(innerSuite))); | 103 expect(suite.suite, completion(equals(innerSuite))); |
| 104 var liveTest = await suite.tests.single.load(suite); | 104 var liveTest = await suite.entries.single.load(suite); |
| 105 await liveTest.run(); | 105 await liveTest.run(); |
| 106 expectTestPassed(liveTest); | 106 expectTestPassed(liveTest); |
| 107 }); | 107 }); |
| 108 | 108 |
| 109 group("changeSuite()", () { | 109 group("changeSuite()", () { |
| 110 test("returns a new load suite with the same properties", () { | 110 test("returns a new load suite with the same properties", () { |
| 111 var suite = new LoadSuite("name", () => innerSuite, | 111 var suite = new LoadSuite("name", () => innerSuite, |
| 112 platform: TestPlatform.vm); | 112 platform: TestPlatform.vm); |
| 113 expect(suite.tests, hasLength(1)); | 113 expect(suite.entries, hasLength(1)); |
| 114 | 114 |
| 115 var newSuite = suite.changeSuite((suite) => suite); | 115 var newSuite = suite.changeSuite((suite) => suite); |
| 116 expect(newSuite.platform, equals(TestPlatform.vm)); | 116 expect(newSuite.platform, equals(TestPlatform.vm)); |
| 117 expect(newSuite.tests, equals(suite.tests)); | 117 expect(newSuite.entries.single.name, equals(suite.entries.single.name)); |
| 118 }); | 118 }); |
| 119 | 119 |
| 120 test("changes the inner suite", () async { | 120 test("changes the inner suite", () async { |
| 121 var suite = new LoadSuite("name", () => innerSuite); | 121 var suite = new LoadSuite("name", () => innerSuite); |
| 122 expect(suite.tests, hasLength(1)); | 122 expect(suite.entries, hasLength(1)); |
| 123 | 123 |
| 124 var newInnerSuite = new RunnerSuite(const VMEnvironment(), []); | 124 var newInnerSuite = new RunnerSuite(const VMEnvironment(), []); |
| 125 var newSuite = suite.changeSuite((suite) => newInnerSuite); | 125 var newSuite = suite.changeSuite((suite) => newInnerSuite); |
| 126 expect(newSuite.suite, completion(equals(newInnerSuite))); | 126 expect(newSuite.suite, completion(equals(newInnerSuite))); |
| 127 | 127 |
| 128 var liveTest = await suite.tests.single.load(suite); | 128 var liveTest = await suite.entries.single.load(suite); |
| 129 await liveTest.run(); | 129 await liveTest.run(); |
| 130 expectTestPassed(liveTest); | 130 expectTestPassed(liveTest); |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 test("doesn't run change() if the suite is null", () async { | 133 test("doesn't run change() if the suite is null", () async { |
| 134 var suite = new LoadSuite("name", () => null); | 134 var suite = new LoadSuite("name", () => null); |
| 135 expect(suite.tests, hasLength(1)); | 135 expect(suite.entries, hasLength(1)); |
| 136 | 136 |
| 137 var newSuite = suite.changeSuite(expectAsync((_) {}, count: 0)); | 137 var newSuite = suite.changeSuite(expectAsync((_) {}, count: 0)); |
| 138 expect(newSuite.suite, completion(isNull)); | 138 expect(newSuite.suite, completion(isNull)); |
| 139 | 139 |
| 140 var liveTest = await suite.tests.single.load(suite); | 140 var liveTest = await suite.entries.single.load(suite); |
| 141 await liveTest.run(); | 141 await liveTest.run(); |
| 142 expectTestPassed(liveTest); | 142 expectTestPassed(liveTest); |
| 143 }); | 143 }); |
| 144 }); | 144 }); |
| 145 | 145 |
| 146 group("getSuite()", () { | 146 group("getSuite()", () { |
| 147 test("runs the test and returns the suite", () { | 147 test("runs the test and returns the suite", () { |
| 148 var suite = new LoadSuite.forSuite(innerSuite); | 148 var suite = new LoadSuite.forSuite(innerSuite); |
| 149 expect(suite.tests, hasLength(1)); | 149 expect(suite.entries, hasLength(1)); |
| 150 | 150 |
| 151 expect(suite.getSuite(), completion(equals(innerSuite))); | 151 expect(suite.getSuite(), completion(equals(innerSuite))); |
| 152 }); | 152 }); |
| 153 | 153 |
| 154 test("forwards errors to the future", () { | 154 test("forwards errors to the future", () { |
| 155 var suite = new LoadSuite("name", () => throw "error"); | 155 var suite = new LoadSuite("name", () => throw "error"); |
| 156 expect(suite.tests, hasLength(1)); | 156 expect(suite.entries, hasLength(1)); |
| 157 | 157 |
| 158 expect(suite.getSuite(), throwsA("error")); | 158 expect(suite.getSuite(), throwsA("error")); |
| 159 }); | 159 }); |
| 160 }); | 160 }); |
| 161 } | 161 } |
| OLD | NEW |