Chromium Code Reviews| 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'; | 16 import '../backend/invoker.dart'; |
| 17 import '../backend/metadata.dart'; | 17 import '../backend/metadata.dart'; |
| 18 import '../backend/test_platform.dart'; | 18 import '../backend/test_platform.dart'; |
| 19 import '../util/dart.dart' as dart; | 19 import '../util/dart.dart' as dart; |
| 20 import '../util/io.dart'; | 20 import '../util/io.dart'; |
| 21 import '../util/remote_exception.dart'; | 21 import '../util/remote_exception.dart'; |
| 22 import '../utils.dart'; | 22 import '../utils.dart'; |
| 23 import 'browser/server.dart'; | 23 import 'browser/server.dart'; |
| 24 import 'load_exception.dart'; | 24 import 'load_exception.dart'; |
| 25 import 'load_suite.dart'; | 25 import 'load_suite.dart'; |
| 26 import 'parse_metadata.dart'; | 26 import 'parse_metadata.dart'; |
| 27 import 'runner_suite.dart'; | 27 import 'runner_suite.dart'; |
| 28 import 'vm/environment.dart'; | |
| 28 import 'vm/isolate_test.dart'; | 29 import 'vm/isolate_test.dart'; |
| 29 | 30 |
| 30 /// A class for finding test files and loading them into a runnable form. | 31 /// A class for finding test files and loading them into a runnable form. |
| 31 class Loader { | 32 class Loader { |
| 32 /// All platforms for which tests should be loaded. | 33 /// All platforms for which tests should be loaded. |
| 33 final List<TestPlatform> _platforms; | 34 final List<TestPlatform> _platforms; |
| 34 | 35 |
| 35 /// Whether to enable colors for Dart compilation. | 36 /// Whether to enable colors for Dart compilation. |
| 36 final bool _color; | 37 final bool _color; |
| 37 | 38 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 return; | 153 return; |
| 153 } | 154 } |
| 154 | 155 |
| 155 for (var platform in _platforms) { | 156 for (var platform in _platforms) { |
| 156 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) continue; | 157 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) continue; |
| 157 | 158 |
| 158 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); | 159 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); |
| 159 | 160 |
| 160 // Don't load a skipped suite. | 161 // Don't load a skipped suite. |
| 161 if (metadata.skip) { | 162 if (metadata.skip) { |
| 162 yield new LoadSuite.forSuite(new RunnerSuite([ | 163 yield new LoadSuite.forSuite(new RunnerSuite(const VMEnvironment(), [ |
| 163 new LocalTest(path, metadata, () {}) | 164 new LocalTest(path, metadata, () {}) |
| 164 ], path: path, platform: platform, metadata: metadata)); | 165 ], path: path, platform: platform, metadata: metadata)); |
| 165 continue; | 166 continue; |
| 166 } | 167 } |
| 167 | 168 |
| 168 var name = (platform.isJS ? "compiling " : "loading ") + path; | 169 var name = (platform.isJS ? "compiling " : "loading ") + path; |
| 169 yield new LoadSuite(name, () { | 170 yield new LoadSuite(name, () { |
| 170 return platform == TestPlatform.vm | 171 return platform == TestPlatform.vm |
| 171 ? _loadVmFile(path, metadata) | 172 ? _loadVmFile(path, metadata) |
| 172 : _loadBrowserFile(path, platform, metadata); | 173 : _loadBrowserFile(path, platform, metadata); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 completer.completeError( | 256 completer.completeError( |
| 256 new LoadException(path, asyncError.error), | 257 new LoadException(path, asyncError.error), |
| 257 asyncError.stackTrace); | 258 asyncError.stackTrace); |
| 258 } else { | 259 } else { |
| 259 assert(response["type"] == "success"); | 260 assert(response["type"] == "success"); |
| 260 completer.complete(response["tests"]); | 261 completer.complete(response["tests"]); |
| 261 } | 262 } |
| 262 }); | 263 }); |
| 263 | 264 |
| 264 try { | 265 try { |
| 265 var suite = new RunnerSuite((await completer.future).map((test) { | 266 var suite = new RunnerSuite(const VMEnvironment(), |
|
kevmoo
2015/07/30 01:37:24
nested awaits worry me – could make debugging that
nweiz
2015/07/30 19:41:50
Part of the point of await is that it can be used
| |
| 267 (await completer.future).map((test) { | |
| 266 var testMetadata = new Metadata.deserialize(test['metadata']); | 268 var testMetadata = new Metadata.deserialize(test['metadata']); |
| 267 return new IsolateTest(test['name'], testMetadata, test['sendPort']); | 269 return new IsolateTest(test['name'], testMetadata, test['sendPort']); |
| 268 }), | 270 }), |
| 269 metadata: metadata, | 271 metadata: metadata, |
| 270 path: path, | 272 path: path, |
| 271 platform: TestPlatform.vm, | 273 platform: TestPlatform.vm, |
| 272 os: currentOS, | 274 os: currentOS, |
| 273 onClose: isolate.kill); | 275 onClose: isolate.kill); |
| 274 _suites.add(suite); | 276 _suites.add(suite); |
| 275 return suite; | 277 return suite; |
| 276 } finally { | 278 } finally { |
| 277 subscription.cancel(); | 279 subscription.cancel(); |
| 278 } | 280 } |
| 279 } | 281 } |
| 280 | 282 |
| 281 /// Closes the loader and releases all resources allocated by it. | 283 /// Closes the loader and releases all resources allocated by it. |
| 282 Future close() { | 284 Future close() { |
| 283 return _closeMemo.runOnce(() async { | 285 return _closeMemo.runOnce(() async { |
| 284 await Future.wait(_suites.map((suite) => suite.close())); | 286 await Future.wait(_suites.map((suite) => suite.close())); |
| 285 _suites.clear(); | 287 _suites.clear(); |
| 286 | 288 |
| 287 if (!_browserServerMemo.hasRun) return; | 289 if (!_browserServerMemo.hasRun) return; |
| 288 await (await _browserServer).close(); | 290 await (await _browserServer).close(); |
| 289 }); | 291 }); |
| 290 } | 292 } |
| 291 } | 293 } |
| OLD | NEW |