| 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 library test.runner.load_suite; | 5 library test.runner.load_suite; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| 11 import '../../test.dart'; | 11 import '../../test.dart'; |
| 12 import '../backend/invoker.dart'; | 12 import '../backend/invoker.dart'; |
| 13 import '../backend/metadata.dart'; | 13 import '../backend/metadata.dart'; |
| 14 import '../backend/test.dart'; |
| 14 import '../backend/test_platform.dart'; | 15 import '../backend/test_platform.dart'; |
| 15 import '../utils.dart'; | 16 import '../utils.dart'; |
| 16 import 'load_exception.dart'; | 17 import 'load_exception.dart'; |
| 17 import 'runner_suite.dart'; | 18 import 'runner_suite.dart'; |
| 18 import 'vm/environment.dart'; | 19 import 'vm/environment.dart'; |
| 19 | 20 |
| 20 /// A [Suite] emitted by a [Loader] that provides a test-like interface for | 21 /// A [Suite] emitted by a [Loader] that provides a test-like interface for |
| 21 /// loading a test file. | 22 /// loading a test file. |
| 22 /// | 23 /// |
| 23 /// This is used to expose the current status of test loading to the user. It's | 24 /// This is used to expose the current status of test loading to the user. It's |
| 24 /// important to provide users visibility into what's taking a long time and | 25 /// important to provide users visibility into what's taking a long time and |
| 25 /// where failures occur. And since some tests may be loaded at the same time as | 26 /// where failures occur. And since some tests may be loaded at the same time as |
| 26 /// others are run, it's useful to provide that visibility in the form of a test | 27 /// others are run, it's useful to provide that visibility in the form of a test |
| 27 /// suite so that it can integrate well into the existing reporting interface | 28 /// suite so that it can integrate well into the existing reporting interface |
| 28 /// without too much extra logic. | 29 /// without too much extra logic. |
| 29 /// | 30 /// |
| 30 /// A suite is constructed with logic necessary to produce a test suite. As with | 31 /// A suite is constructed with logic necessary to produce a test suite. As with |
| 31 /// a normal test body, this logic isn't run until [LiveTest.run] is called. The | 32 /// a normal test body, this logic isn't run until [LiveTest.run] is called. The |
| 32 /// suite itself is returned by [suite] once it's avaialble, but any errors or | 33 /// suite itself is returned by [suite] once it's avaialble, but any errors or |
| 33 /// prints will be emitted through the running [LiveTest]. | 34 /// prints will be emitted through the running [LiveTest]. |
| 34 class LoadSuite extends RunnerSuite { | 35 class LoadSuite extends RunnerSuite { |
| 35 /// A future that completes to the loaded suite once the suite's test has been | 36 /// A future that completes to the loaded suite once the suite's test has been |
| 36 /// run and completed successfully. | 37 /// run and completed successfully. |
| 37 /// | 38 /// |
| 38 /// This will return `null` if the suite is unavailable for some reason (for | 39 /// This will return `null` if the suite is unavailable for some reason (for |
| 39 /// example if an error occurred while loading it). | 40 /// example if an error occurred while loading it). |
| 40 final Future<RunnerSuite> suite; | 41 final Future<RunnerSuite> suite; |
| 41 | 42 |
| 43 /// Returns the test that loads the suite. |
| 44 /// |
| 45 /// Load suites are guaranteed to only contain one test. This is a utility |
| 46 /// method for accessing it directly. |
| 47 Test get test => entries.single as Test; |
| 48 |
| 42 /// Creates a load suite named [name] on [platform]. | 49 /// Creates a load suite named [name] on [platform]. |
| 43 /// | 50 /// |
| 44 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a | 51 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a |
| 45 /// [RunnerSuite]. Its return value is forwarded through [suite], although if | 52 /// [RunnerSuite]. Its return value is forwarded through [suite], although if |
| 46 /// it throws an error that will be forwarded through the suite's test. | 53 /// it throws an error that will be forwarded through the suite's test. |
| 47 /// | 54 /// |
| 48 /// If the the load test is closed before [body] is complete, it will close | 55 /// If the the load test is closed before [body] is complete, it will close |
| 49 /// the suite returned by [body] once it completes. | 56 /// the suite returned by [body] once it completes. |
| 50 factory LoadSuite(String name, body(), {TestPlatform platform}) { | 57 factory LoadSuite(String name, body(), {TestPlatform platform}) { |
| 51 var completer = new Completer.sync(); | 58 var completer = new Completer.sync(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 108 |
| 102 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform}) | 109 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform}) |
| 103 : super(const VMEnvironment(), [ | 110 : super(const VMEnvironment(), [ |
| 104 new LocalTest(name, | 111 new LocalTest(name, |
| 105 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), | 112 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), |
| 106 body) | 113 body) |
| 107 ], platform: platform); | 114 ], platform: platform); |
| 108 | 115 |
| 109 /// A constructor used by [changeSuite]. | 116 /// A constructor used by [changeSuite]. |
| 110 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite) | 117 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite) |
| 111 : super(const VMEnvironment(), old.tests, platform: old.platform); | 118 : super(const VMEnvironment(), old.entries, platform: old.platform); |
| 112 | 119 |
| 113 /// Creates a new [LoadSuite] that's identical to this one, but that | 120 /// Creates a new [LoadSuite] that's identical to this one, but that |
| 114 /// transforms [suite] once it's loaded. | 121 /// transforms [suite] once it's loaded. |
| 115 /// | 122 /// |
| 116 /// If [suite] completes to `null`, [change] won't be run. | 123 /// If [suite] completes to `null`, [change] won't be run. |
| 117 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { | 124 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { |
| 118 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { | 125 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { |
| 119 if (loadedSuite == null) return null; | 126 if (loadedSuite == null) return null; |
| 120 return change(loadedSuite); | 127 return change(loadedSuite); |
| 121 })); | 128 })); |
| 122 } | 129 } |
| 123 | 130 |
| 124 /// Runs the test and returns the suite. | 131 /// Runs the test and returns the suite. |
| 125 /// | 132 /// |
| 126 /// Rather than emitting errors through a [LiveTest], this just pipes them | 133 /// Rather than emitting errors through a [LiveTest], this just pipes them |
| 127 /// through the return value. | 134 /// through the return value. |
| 128 Future<RunnerSuite> getSuite() async { | 135 Future<RunnerSuite> getSuite() async { |
| 129 var liveTest = await tests.single.load(this); | 136 var liveTest = await test.load(this); |
| 130 liveTest.onPrint.listen(print); | 137 liveTest.onPrint.listen(print); |
| 131 await liveTest.run(); | 138 await liveTest.run(); |
| 132 | 139 |
| 133 if (liveTest.errors.isEmpty) return await suite; | 140 if (liveTest.errors.isEmpty) return await suite; |
| 134 | 141 |
| 135 var error = liveTest.errors.first; | 142 var error = liveTest.errors.first; |
| 136 await new Future.error(error.error, error.stackTrace); | 143 await new Future.error(error.error, error.stackTrace); |
| 137 throw 'unreachable'; | 144 throw 'unreachable'; |
| 138 } | 145 } |
| 139 } | 146 } |
| OLD | NEW |