OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 @TestOn("vm") |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:test/src/backend/state.dart'; |
| 10 import 'package:test/src/backend/suite.dart'; |
| 11 import 'package:test/src/runner/load_exception.dart'; |
| 12 import 'package:test/src/runner/load_suite.dart'; |
| 13 import 'package:test/test.dart'; |
| 14 |
| 15 import '../utils.dart'; |
| 16 |
| 17 void main() { |
| 18 test("running a load test causes LoadSuite.suite to emit a suite", () async { |
| 19 var innerSuite = new Suite([]); |
| 20 var suite = new LoadSuite("name", () => new Future.value(innerSuite)); |
| 21 expect(suite.tests, hasLength(1)); |
| 22 |
| 23 expect(suite.suite, completion(equals(innerSuite))); |
| 24 var liveTest = await suite.tests.single.load(suite); |
| 25 await liveTest.run(); |
| 26 expectTestPassed(liveTest); |
| 27 }); |
| 28 |
| 29 test("running a load suite's body may be synchronous", () async { |
| 30 var innerSuite = new Suite([]); |
| 31 var suite = new LoadSuite("name", () => innerSuite); |
| 32 expect(suite.tests, hasLength(1)); |
| 33 |
| 34 expect(suite.suite, completion(equals(innerSuite))); |
| 35 var liveTest = await suite.tests.single.load(suite); |
| 36 await liveTest.run(); |
| 37 expectTestPassed(liveTest); |
| 38 }); |
| 39 |
| 40 test("a load test doesn't complete until the body returns", () async { |
| 41 var completer = new Completer(); |
| 42 var suite = new LoadSuite("name", () => completer.future); |
| 43 expect(suite.tests, hasLength(1)); |
| 44 |
| 45 var liveTest = await suite.tests.single.load(suite); |
| 46 expect(liveTest.run(), completes); |
| 47 await new Future.delayed(Duration.ZERO); |
| 48 expect(liveTest.state.status, equals(Status.running)); |
| 49 |
| 50 completer.complete(new Suite([])); |
| 51 await new Future.delayed(Duration.ZERO); |
| 52 expectTestPassed(liveTest); |
| 53 }); |
| 54 |
| 55 test("a load test forwards errors and completes LoadSuite.suite to null", |
| 56 () async { |
| 57 var suite = new LoadSuite("name", () => fail("error")); |
| 58 expect(suite.tests, hasLength(1)); |
| 59 |
| 60 expect(suite.suite, completion(isNull)); |
| 61 |
| 62 var liveTest = await suite.tests.single.load(suite); |
| 63 await liveTest.run(); |
| 64 expectTestFailed(liveTest, "error"); |
| 65 }); |
| 66 |
| 67 test("a load test completes early if it's closed", () async { |
| 68 var suite = new LoadSuite("name", () => new Completer().future); |
| 69 expect(suite.tests, hasLength(1)); |
| 70 |
| 71 var liveTest = await suite.tests.single.load(suite); |
| 72 expect(liveTest.run(), completes); |
| 73 await new Future.delayed(Duration.ZERO); |
| 74 expect(liveTest.state.status, equals(Status.running)); |
| 75 |
| 76 expect(liveTest.close(), completes); |
| 77 }); |
| 78 |
| 79 test("forLoadException() creates a suite that completes to a LoadException", |
| 80 () async { |
| 81 var exception = new LoadException("path", "error"); |
| 82 var suite = new LoadSuite.forLoadException(exception); |
| 83 expect(suite.tests, hasLength(1)); |
| 84 |
| 85 expect(suite.suite, completion(isNull)); |
| 86 |
| 87 var liveTest = await suite.tests.single.load(suite); |
| 88 await liveTest.run(); |
| 89 expect(liveTest.state.status, equals(Status.complete)); |
| 90 expect(liveTest.state.result, equals(Result.error)); |
| 91 expect(liveTest.errors, hasLength(1)); |
| 92 expect(liveTest.errors.first.error, equals(exception)); |
| 93 }); |
| 94 |
| 95 test("forSuite() creates a load suite that completes to a test suite", |
| 96 () async { |
| 97 var innerSuite = new Suite([]); |
| 98 var suite = new LoadSuite.forSuite(innerSuite); |
| 99 expect(suite.tests, hasLength(1)); |
| 100 |
| 101 expect(suite.suite, completion(equals(innerSuite))); |
| 102 var liveTest = await suite.tests.single.load(suite); |
| 103 await liveTest.run(); |
| 104 expectTestPassed(liveTest); |
| 105 }); |
| 106 |
| 107 group("getSuite()", () { |
| 108 test("runs the test and returns the suite", () { |
| 109 var innerSuite = new Suite([]); |
| 110 var suite = new LoadSuite.forSuite(innerSuite); |
| 111 expect(suite.tests, hasLength(1)); |
| 112 |
| 113 expect(suite.getSuite(), completion(equals(innerSuite))); |
| 114 }); |
| 115 |
| 116 test("forwards errors to the future", () { |
| 117 var suite = new LoadSuite("name", () => throw "error"); |
| 118 expect(suite.tests, hasLength(1)); |
| 119 |
| 120 expect(suite.getSuite(), throwsA("error")); |
| 121 }); |
| 122 }); |
| 123 } |
OLD | NEW |