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