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/invoker.dart'; | 13 import '../backend/invoker.dart'; |
13 import '../backend/metadata.dart'; | 14 import '../backend/metadata.dart'; |
14 import '../backend/test.dart'; | 15 import '../backend/test.dart'; |
15 import '../backend/test_platform.dart'; | 16 import '../backend/test_platform.dart'; |
16 import '../utils.dart'; | 17 import '../utils.dart'; |
17 import 'load_exception.dart'; | 18 import 'load_exception.dart'; |
18 import 'runner_suite.dart'; | 19 import 'runner_suite.dart'; |
19 import 'vm/environment.dart'; | 20 import 'vm/environment.dart'; |
20 | 21 |
21 /// 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 |
(...skipping 15 matching lines...) Expand all Loading... |
37 /// run and completed successfully. | 38 /// run and completed successfully. |
38 /// | 39 /// |
39 /// 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 |
40 /// example if an error occurred while loading it). | 41 /// example if an error occurred while loading it). |
41 final Future<RunnerSuite> suite; | 42 final Future<RunnerSuite> suite; |
42 | 43 |
43 /// Returns the test that loads the suite. | 44 /// Returns the test that loads the suite. |
44 /// | 45 /// |
45 /// 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 |
46 /// method for accessing it directly. | 47 /// method for accessing it directly. |
47 Test get test => entries.single as Test; | 48 Test get test => this.group.entries.single as Test; |
48 | 49 |
49 /// Creates a load suite named [name] on [platform]. | 50 /// Creates a load suite named [name] on [platform]. |
50 /// | 51 /// |
51 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a | 52 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a |
52 /// [RunnerSuite]. Its return value is forwarded through [suite], although if | 53 /// [RunnerSuite]. Its return value is forwarded through [suite], although if |
53 /// it throws an error that will be forwarded through the suite's test. | 54 /// it throws an error that will be forwarded through the suite's test. |
54 /// | 55 /// |
55 /// If the the load test is closed before [body] is complete, it will close | 56 /// If the the load test is closed before [body] is complete, it will close |
56 /// the suite returned by [body] once it completes. | 57 /// the suite returned by [body] once it completes. |
57 factory LoadSuite(String name, body(), {TestPlatform platform}) { | 58 factory LoadSuite(String name, body(), {TestPlatform platform}) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 }, platform: platform); | 101 }, platform: platform); |
101 } | 102 } |
102 | 103 |
103 /// A utility constructor for a load suite that just emits [suite]. | 104 /// A utility constructor for a load suite that just emits [suite]. |
104 factory LoadSuite.forSuite(RunnerSuite suite) { | 105 factory LoadSuite.forSuite(RunnerSuite suite) { |
105 return new LoadSuite("loading ${suite.path}", () => suite, | 106 return new LoadSuite("loading ${suite.path}", () => suite, |
106 platform: suite.platform); | 107 platform: suite.platform); |
107 } | 108 } |
108 | 109 |
109 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform}) | 110 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform}) |
110 : super(const VMEnvironment(), [ | 111 : super(const VMEnvironment(), new Group.root([ |
111 new LocalTest(name, | 112 new LocalTest(name, |
112 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), | 113 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), |
113 body) | 114 body) |
114 ], platform: platform); | 115 ]), platform: platform); |
115 | 116 |
116 /// A constructor used by [changeSuite]. | 117 /// A constructor used by [changeSuite]. |
117 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite) | 118 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite) |
118 : super(const VMEnvironment(), old.entries, platform: old.platform); | 119 : super(const VMEnvironment(), old.group, platform: old.platform); |
119 | 120 |
120 /// 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 |
121 /// transforms [suite] once it's loaded. | 122 /// transforms [suite] once it's loaded. |
122 /// | 123 /// |
123 /// If [suite] completes to `null`, [change] won't be run. | 124 /// If [suite] completes to `null`, [change] won't be run. |
124 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { | 125 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { |
125 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { | 126 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { |
126 if (loadedSuite == null) return null; | 127 if (loadedSuite == null) return null; |
127 return change(loadedSuite); | 128 return change(loadedSuite); |
128 })); | 129 })); |
129 } | 130 } |
130 | 131 |
131 /// Runs the test and returns the suite. | 132 /// Runs the test and returns the suite. |
132 /// | 133 /// |
133 /// Rather than emitting errors through a [LiveTest], this just pipes them | 134 /// Rather than emitting errors through a [LiveTest], this just pipes them |
134 /// through the return value. | 135 /// through the return value. |
135 Future<RunnerSuite> getSuite() async { | 136 Future<RunnerSuite> getSuite() async { |
136 var liveTest = await test.load(this); | 137 var liveTest = await test.load(this); |
137 liveTest.onPrint.listen(print); | 138 liveTest.onPrint.listen(print); |
138 await liveTest.run(); | 139 await liveTest.run(); |
139 | 140 |
140 if (liveTest.errors.isEmpty) return await suite; | 141 if (liveTest.errors.isEmpty) return await suite; |
141 | 142 |
142 var error = liveTest.errors.first; | 143 var error = liveTest.errors.first; |
143 await new Future.error(error.error, error.stackTrace); | 144 await new Future.error(error.error, error.stackTrace); |
144 throw 'unreachable'; | 145 throw 'unreachable'; |
145 } | 146 } |
146 } | 147 } |
OLD | NEW |