| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:fake_async/fake_async.dart'; | 7 import 'package:fake_async/fake_async.dart'; |
| 8 import 'package:test/src/backend/invoker.dart'; | 8 import 'package:test/src/backend/invoker.dart'; |
| 9 import 'package:test/src/backend/metadata.dart'; | 9 import 'package:test/src/backend/metadata.dart'; |
| 10 import 'package:test/src/backend/state.dart'; | 10 import 'package:test/src/backend/state.dart'; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 var liveTest = _localTest(() { | 162 var liveTest = _localTest(() { |
| 163 throw new TestFailure('oh no'); | 163 throw new TestFailure('oh no'); |
| 164 }).load(suite); | 164 }).load(suite); |
| 165 | 165 |
| 166 expectSingleFailure(liveTest); | 166 expectSingleFailure(liveTest); |
| 167 return liveTest.run(); | 167 return liveTest.run(); |
| 168 }); | 168 }); |
| 169 | 169 |
| 170 test("a synchronous reported failure causes the test to fail", () { | 170 test("a synchronous reported failure causes the test to fail", () { |
| 171 var liveTest = _localTest(() { | 171 var liveTest = _localTest(() { |
| 172 Invoker.current.handleError(new TestFailure("oh no")); | 172 registerException(new TestFailure("oh no")); |
| 173 }).load(suite); | 173 }).load(suite); |
| 174 | 174 |
| 175 expectSingleFailure(liveTest); | 175 expectSingleFailure(liveTest); |
| 176 return liveTest.run(); | 176 return liveTest.run(); |
| 177 }); | 177 }); |
| 178 | 178 |
| 179 test("a failure reported asynchronously during the test causes it to fail", | 179 test("a failure reported asynchronously during the test causes it to fail", |
| 180 () { | 180 () { |
| 181 var liveTest = _localTest(() { | 181 var liveTest = _localTest(() { |
| 182 Invoker.current.addOutstandingCallback(); | 182 Invoker.current.addOutstandingCallback(); |
| 183 new Future(() => Invoker.current.handleError(new TestFailure("oh no"))); | 183 new Future(() => registerException(new TestFailure("oh no"))); |
| 184 }).load(suite); | 184 }).load(suite); |
| 185 | 185 |
| 186 expectSingleFailure(liveTest); | 186 expectSingleFailure(liveTest); |
| 187 return liveTest.run(); | 187 return liveTest.run(); |
| 188 }); | 188 }); |
| 189 | 189 |
| 190 test("a failure thrown asynchronously during the test causes it to fail", | 190 test("a failure thrown asynchronously during the test causes it to fail", |
| 191 () { | 191 () { |
| 192 var liveTest = _localTest(() { | 192 var liveTest = _localTest(() { |
| 193 Invoker.current.addOutstandingCallback(); | 193 Invoker.current.addOutstandingCallback(); |
| 194 new Future(() => throw new TestFailure("oh no")); | 194 new Future(() => throw new TestFailure("oh no")); |
| 195 }).load(suite); | 195 }).load(suite); |
| 196 | 196 |
| 197 expectSingleFailure(liveTest); | 197 expectSingleFailure(liveTest); |
| 198 return liveTest.run(); | 198 return liveTest.run(); |
| 199 }); | 199 }); |
| 200 | 200 |
| 201 test("a failure reported asynchronously after the test causes it to error", | 201 test("a failure reported asynchronously after the test causes it to error", |
| 202 () { | 202 () { |
| 203 var liveTest = _localTest(() { | 203 var liveTest = _localTest(() { |
| 204 new Future(() => Invoker.current.handleError(new TestFailure("oh no"))); | 204 new Future(() => registerException(new TestFailure("oh no"))); |
| 205 }).load(suite); | 205 }).load(suite); |
| 206 | 206 |
| 207 expectStates(liveTest, [ | 207 expectStates(liveTest, [ |
| 208 const State(Status.running, Result.success), | 208 const State(Status.running, Result.success), |
| 209 const State(Status.complete, Result.success), | 209 const State(Status.complete, Result.success), |
| 210 const State(Status.complete, Result.failure), | 210 const State(Status.complete, Result.failure), |
| 211 const State(Status.complete, Result.error) | 211 const State(Status.complete, Result.error) |
| 212 ]); | 212 ]); |
| 213 | 213 |
| 214 expectErrors(liveTest, [(error) { | 214 expectErrors(liveTest, [(error) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 var liveTest = _localTest(() { | 296 var liveTest = _localTest(() { |
| 297 throw 'oh no'; | 297 throw 'oh no'; |
| 298 }).load(suite); | 298 }).load(suite); |
| 299 | 299 |
| 300 expectSingleError(liveTest); | 300 expectSingleError(liveTest); |
| 301 return liveTest.run(); | 301 return liveTest.run(); |
| 302 }); | 302 }); |
| 303 | 303 |
| 304 test("a synchronous reported error causes the test to error", () { | 304 test("a synchronous reported error causes the test to error", () { |
| 305 var liveTest = _localTest(() { | 305 var liveTest = _localTest(() { |
| 306 Invoker.current.handleError("oh no"); | 306 registerException("oh no"); |
| 307 }).load(suite); | 307 }).load(suite); |
| 308 | 308 |
| 309 expectSingleError(liveTest); | 309 expectSingleError(liveTest); |
| 310 return liveTest.run(); | 310 return liveTest.run(); |
| 311 }); | 311 }); |
| 312 | 312 |
| 313 test("an error reported asynchronously during the test causes it to error", | 313 test("an error reported asynchronously during the test causes it to error", |
| 314 () { | 314 () { |
| 315 var liveTest = _localTest(() { | 315 var liveTest = _localTest(() { |
| 316 Invoker.current.addOutstandingCallback(); | 316 Invoker.current.addOutstandingCallback(); |
| 317 new Future(() => Invoker.current.handleError("oh no")); | 317 new Future(() => registerException("oh no")); |
| 318 }).load(suite); | 318 }).load(suite); |
| 319 | 319 |
| 320 expectSingleError(liveTest); | 320 expectSingleError(liveTest); |
| 321 return liveTest.run(); | 321 return liveTest.run(); |
| 322 }); | 322 }); |
| 323 | 323 |
| 324 test("an error thrown asynchronously during the test causes it to error", | 324 test("an error thrown asynchronously during the test causes it to error", |
| 325 () { | 325 () { |
| 326 var liveTest = _localTest(() { | 326 var liveTest = _localTest(() { |
| 327 Invoker.current.addOutstandingCallback(); | 327 Invoker.current.addOutstandingCallback(); |
| 328 new Future(() => throw "oh no"); | 328 new Future(() => throw "oh no"); |
| 329 }).load(suite); | 329 }).load(suite); |
| 330 | 330 |
| 331 expectSingleError(liveTest); | 331 expectSingleError(liveTest); |
| 332 return liveTest.run(); | 332 return liveTest.run(); |
| 333 }); | 333 }); |
| 334 | 334 |
| 335 test("an error reported asynchronously after the test causes it to error", | 335 test("an error reported asynchronously after the test causes it to error", |
| 336 () { | 336 () { |
| 337 var liveTest = _localTest(() { | 337 var liveTest = _localTest(() { |
| 338 new Future(() => Invoker.current.handleError("oh no")); | 338 new Future(() => registerException("oh no")); |
| 339 }).load(suite); | 339 }).load(suite); |
| 340 | 340 |
| 341 expectStates(liveTest, [ | 341 expectStates(liveTest, [ |
| 342 const State(Status.running, Result.success), | 342 const State(Status.running, Result.success), |
| 343 const State(Status.complete, Result.success), | 343 const State(Status.complete, Result.success), |
| 344 const State(Status.complete, Result.error) | 344 const State(Status.complete, Result.error) |
| 345 ]); | 345 ]); |
| 346 | 346 |
| 347 expectErrors(liveTest, [(error) { | 347 expectErrors(liveTest, [(error) { |
| 348 expect(lastState, equals(const State(Status.complete, Result.error))); | 348 expect(lastState, equals(const State(Status.complete, Result.error))); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 677 |
| 678 expect(innerFunctionCompleted, isFalse); | 678 expect(innerFunctionCompleted, isFalse); |
| 679 }); | 679 }); |
| 680 }); | 680 }); |
| 681 } | 681 } |
| 682 | 682 |
| 683 LocalTest _localTest(body(), {tearDown(), Metadata metadata}) { | 683 LocalTest _localTest(body(), {tearDown(), Metadata metadata}) { |
| 684 if (metadata == null) metadata = new Metadata(); | 684 if (metadata == null) metadata = new Metadata(); |
| 685 return new LocalTest("test", metadata, body, tearDown: tearDown); | 685 return new LocalTest("test", metadata, body, tearDown: tearDown); |
| 686 } | 686 } |
| OLD | NEW |