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.loader; | 5 library test.runner.loader; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 | 10 |
11 import 'package:analyzer/analyzer.dart'; | 11 import 'package:analyzer/analyzer.dart'; |
12 import 'package:async/async.dart'; | 12 import 'package:async/async.dart'; |
13 import 'package:path/path.dart' as p; | 13 import 'package:path/path.dart' as p; |
14 import 'package:stack_trace/stack_trace.dart'; | 14 import 'package:stack_trace/stack_trace.dart'; |
15 | 15 |
16 import '../backend/invoker.dart'; | |
17 import '../backend/group.dart'; | 16 import '../backend/group.dart'; |
18 import '../backend/metadata.dart'; | 17 import '../backend/metadata.dart'; |
19 import '../backend/suite_entry.dart'; | |
20 import '../backend/test_platform.dart'; | 18 import '../backend/test_platform.dart'; |
21 import '../util/dart.dart' as dart; | 19 import '../util/dart.dart' as dart; |
22 import '../util/io.dart'; | 20 import '../util/io.dart'; |
23 import '../util/remote_exception.dart'; | 21 import '../util/remote_exception.dart'; |
24 import '../utils.dart'; | 22 import '../utils.dart'; |
25 import 'browser/server.dart'; | 23 import 'browser/server.dart'; |
26 import 'configuration.dart'; | 24 import 'configuration.dart'; |
27 import 'hack_load_vm_file_hook.dart'; | 25 import 'hack_load_vm_file_hook.dart'; |
28 import 'load_exception.dart'; | 26 import 'load_exception.dart'; |
29 import 'load_suite.dart'; | 27 import 'load_suite.dart'; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return; | 112 return; |
115 } | 113 } |
116 | 114 |
117 for (var platform in _config.platforms) { | 115 for (var platform in _config.platforms) { |
118 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) continue; | 116 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) continue; |
119 | 117 |
120 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); | 118 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); |
121 | 119 |
122 // Don't load a skipped suite. | 120 // Don't load a skipped suite. |
123 if (metadata.skip) { | 121 if (metadata.skip) { |
124 yield new LoadSuite.forSuite(new RunnerSuite(const VMEnvironment(), [ | 122 yield new LoadSuite.forSuite(new RunnerSuite( |
125 new LocalTest(path, metadata, () {}) | 123 const VMEnvironment(), |
126 ], path: path, platform: platform, metadata: metadata)); | 124 new Group.root([], metadata: metadata), |
| 125 path: path, platform: platform)); |
127 continue; | 126 continue; |
128 } | 127 } |
129 | 128 |
130 var name = (platform.isJS ? "compiling " : "loading ") + path; | 129 var name = (platform.isJS ? "compiling " : "loading ") + path; |
131 yield new LoadSuite(name, () { | 130 yield new LoadSuite(name, () { |
132 return platform == TestPlatform.vm | 131 return platform == TestPlatform.vm |
133 ? _loadVmFile(path, metadata) | 132 ? _loadVmFile(path, metadata) |
134 : _loadBrowserFile(path, platform, metadata); | 133 : _loadBrowserFile(path, platform, metadata); |
135 }, platform: platform); | 134 }, platform: platform); |
136 } | 135 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 new LoadException(path, response["message"]), | 213 new LoadException(path, response["message"]), |
215 new Trace.current()); | 214 new Trace.current()); |
216 } else if (response["type"] == "error") { | 215 } else if (response["type"] == "error") { |
217 isolate.kill(); | 216 isolate.kill(); |
218 var asyncError = RemoteException.deserialize(response["error"]); | 217 var asyncError = RemoteException.deserialize(response["error"]); |
219 completer.completeError( | 218 completer.completeError( |
220 new LoadException(path, asyncError.error), | 219 new LoadException(path, asyncError.error), |
221 asyncError.stackTrace); | 220 asyncError.stackTrace); |
222 } else { | 221 } else { |
223 assert(response["type"] == "success"); | 222 assert(response["type"] == "success"); |
224 completer.complete(response["entries"]); | 223 completer.complete(response["root"]); |
225 } | 224 } |
226 }); | 225 }); |
227 | 226 |
228 try { | 227 try { |
229 var suite = new RunnerSuite( | 228 var suite = new RunnerSuite( |
230 const VMEnvironment(), | 229 const VMEnvironment(), |
231 _deserializeEntries(await completer.future), | 230 _deserializeGroup(await completer.future), |
232 metadata: metadata, | |
233 path: path, | 231 path: path, |
234 platform: TestPlatform.vm, | 232 platform: TestPlatform.vm, |
235 os: currentOS, | 233 os: currentOS, |
236 onClose: isolate.kill); | 234 onClose: isolate.kill); |
237 _suites.add(suite); | 235 _suites.add(suite); |
238 return suite; | 236 return suite; |
239 } finally { | 237 } finally { |
240 subscription.cancel(); | 238 subscription.cancel(); |
241 } | 239 } |
242 } | 240 } |
243 | 241 |
244 /// Deserializes [entries] into concrete [SuiteEntry] subclasses. | 242 /// Deserializes [group] into a concrete [Group] class. |
245 Iterable<SuiteEntry> _deserializeEntries(List<Map> entries) { | 243 Group _deserializeGroup(Map group) { |
246 return entries.map((entry) { | 244 var metadata = new Metadata.deserialize(group['metadata']); |
247 var metadata = new Metadata.deserialize(entry['metadata']); | 245 return new Group(group['name'], group['entries'].map((entry) { |
248 if (entry['type'] == 'group') { | 246 if (entry['type'] == 'group') return _deserializeGroup(entry); |
249 return new Group( | 247 var testMetadata = new Metadata.deserialize(entry['metadata']); |
250 entry['name'], metadata, _deserializeEntries(entry['entries'])); | 248 return new IsolateTest(entry['name'], testMetadata, entry['sendPort']); |
251 } else { | 249 }), metadata: metadata); |
252 return new IsolateTest(entry['name'], metadata, entry['sendPort']); | |
253 } | |
254 }); | |
255 } | 250 } |
256 | 251 |
257 /// Closes the loader and releases all resources allocated by it. | 252 /// Closes the loader and releases all resources allocated by it. |
258 Future close() { | 253 Future close() { |
259 return _closeMemo.runOnce(() async { | 254 return _closeMemo.runOnce(() async { |
260 await Future.wait(_suites.map((suite) => suite.close())); | 255 await Future.wait(_suites.map((suite) => suite.close())); |
261 _suites.clear(); | 256 _suites.clear(); |
262 | 257 |
263 if (!_browserServerMemo.hasRun) return; | 258 if (!_browserServerMemo.hasRun) return; |
264 await (await _browserServer).close(); | 259 await (await _browserServer).close(); |
265 }); | 260 }); |
266 } | 261 } |
267 } | 262 } |
OLD | NEW |