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:path/path.dart' as p; | 12 import 'package:path/path.dart' as p; |
13 import 'package:stack_trace/stack_trace.dart'; | 13 import 'package:stack_trace/stack_trace.dart'; |
14 | 14 |
15 import '../backend/invoker.dart'; | 15 import '../backend/invoker.dart'; |
16 import '../backend/metadata.dart'; | 16 import '../backend/metadata.dart'; |
17 import '../backend/suite.dart'; | |
kevmoo
2015/07/28 01:48:00
Suite is still referenced by a couple of methods
nweiz
2015/07/28 20:01:21
Done.
| |
18 import '../backend/test_platform.dart'; | 17 import '../backend/test_platform.dart'; |
19 import '../util/async_thunk.dart'; | 18 import '../util/async_thunk.dart'; |
20 import '../util/dart.dart' as dart; | 19 import '../util/dart.dart' as dart; |
21 import '../util/io.dart'; | 20 import '../util/io.dart'; |
22 import '../util/remote_exception.dart'; | 21 import '../util/remote_exception.dart'; |
23 import '../utils.dart'; | 22 import '../utils.dart'; |
24 import 'browser/server.dart'; | 23 import 'browser/server.dart'; |
25 import 'load_exception.dart'; | 24 import 'load_exception.dart'; |
26 import 'load_suite.dart'; | 25 import 'load_suite.dart'; |
27 import 'parse_metadata.dart'; | 26 import 'parse_metadata.dart'; |
27 import 'runner_suite.dart'; | |
28 import 'vm/isolate_test.dart'; | 28 import 'vm/isolate_test.dart'; |
29 | 29 |
30 /// A class for finding test files and loading them into a runnable form. | 30 /// A class for finding test files and loading them into a runnable form. |
31 class Loader { | 31 class Loader { |
32 /// All platforms for which tests should be loaded. | 32 /// All platforms for which tests should be loaded. |
33 final List<TestPlatform> _platforms; | 33 final List<TestPlatform> _platforms; |
34 | 34 |
35 /// Whether to enable colors for Dart compilation. | 35 /// Whether to enable colors for Dart compilation. |
36 final bool _color; | 36 final bool _color; |
37 | 37 |
38 /// Whether raw JavaScript stack traces should be used for tests that are | 38 /// Whether raw JavaScript stack traces should be used for tests that are |
39 /// compiled to JavaScript. | 39 /// compiled to JavaScript. |
40 final bool _jsTrace; | 40 final bool _jsTrace; |
41 | 41 |
42 /// Global metadata that applies to all test suites. | 42 /// Global metadata that applies to all test suites. |
43 final Metadata _metadata; | 43 final Metadata _metadata; |
44 | 44 |
45 /// The root directory that will be served for browser tests. | 45 /// The root directory that will be served for browser tests. |
46 final String _root; | 46 final String _root; |
47 | 47 |
48 /// The package root to use for loading tests. | 48 /// The package root to use for loading tests. |
49 final String _packageRoot; | 49 final String _packageRoot; |
50 | 50 |
51 /// The URL for the `pub serve` instance to use to load tests. | 51 /// The URL for the `pub serve` instance to use to load tests. |
52 /// | 52 /// |
53 /// This is `null` if tests should be loaded from the filesystem. | 53 /// This is `null` if tests should be loaded from the filesystem. |
54 final Uri _pubServeUrl; | 54 final Uri _pubServeUrl; |
55 | 55 |
56 /// All suites that have been created by the loader. | 56 /// All suites that have been created by the loader. |
57 final _suites = new Set<Suite>(); | 57 final _suites = new Set<RunnerSuite>(); |
58 | 58 |
59 /// The server that serves browser test pages. | 59 /// The server that serves browser test pages. |
60 /// | 60 /// |
61 /// This is lazily initialized the first time it's accessed. | 61 /// This is lazily initialized the first time it's accessed. |
62 Future<BrowserServer> get _browserServer { | 62 Future<BrowserServer> get _browserServer { |
63 return _browserServerThunk.run(() { | 63 return _browserServerThunk.run(() { |
64 return BrowserServer.start( | 64 return BrowserServer.start( |
65 root: _root, | 65 root: _root, |
66 packageRoot: _packageRoot, | 66 packageRoot: _packageRoot, |
67 pubServeUrl: _pubServeUrl, | 67 pubServeUrl: _pubServeUrl, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 return; | 152 return; |
153 } | 153 } |
154 | 154 |
155 for (var platform in _platforms) { | 155 for (var platform in _platforms) { |
156 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) continue; | 156 if (!suiteMetadata.testOn.evaluate(platform, os: currentOS)) continue; |
157 | 157 |
158 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); | 158 var metadata = suiteMetadata.forPlatform(platform, os: currentOS); |
159 | 159 |
160 // Don't load a skipped suite. | 160 // Don't load a skipped suite. |
161 if (metadata.skip) { | 161 if (metadata.skip) { |
162 yield new LoadSuite.forSuite(new Suite([ | 162 yield new LoadSuite.forSuite(new RunnerSuite([ |
163 new LocalTest(path, metadata, () {}) | 163 new LocalTest(path, metadata, () {}) |
164 ], path: path, platform: platform, metadata: metadata)); | 164 ], path: path, platform: platform, metadata: metadata)); |
165 continue; | 165 continue; |
166 } | 166 } |
167 | 167 |
168 var name = (platform.isJS ? "compiling " : "loading ") + path; | 168 var name = (platform.isJS ? "compiling " : "loading ") + path; |
169 yield new LoadSuite(name, () { | 169 yield new LoadSuite(name, () { |
170 return platform == TestPlatform.vm | 170 return platform == TestPlatform.vm |
171 ? _loadVmFile(path, metadata) | 171 ? _loadVmFile(path, metadata) |
172 : _loadBrowserFile(path, platform, metadata); | 172 : _loadBrowserFile(path, platform, metadata); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 completer.completeError( | 255 completer.completeError( |
256 new LoadException(path, asyncError.error), | 256 new LoadException(path, asyncError.error), |
257 asyncError.stackTrace); | 257 asyncError.stackTrace); |
258 } else { | 258 } else { |
259 assert(response["type"] == "success"); | 259 assert(response["type"] == "success"); |
260 completer.complete(response["tests"]); | 260 completer.complete(response["tests"]); |
261 } | 261 } |
262 }); | 262 }); |
263 | 263 |
264 try { | 264 try { |
265 var suite = new Suite((await completer.future).map((test) { | 265 var suite = new RunnerSuite((await completer.future).map((test) { |
266 var testMetadata = new Metadata.deserialize(test['metadata']); | 266 var testMetadata = new Metadata.deserialize(test['metadata']); |
267 return new IsolateTest(test['name'], testMetadata, test['sendPort']); | 267 return new IsolateTest(test['name'], testMetadata, test['sendPort']); |
268 }), | 268 }), |
269 metadata: metadata, | 269 metadata: metadata, |
270 path: path, | 270 path: path, |
271 platform: TestPlatform.vm, | 271 platform: TestPlatform.vm, |
272 os: currentOS, | 272 os: currentOS, |
273 onClose: isolate.kill); | 273 onClose: isolate.kill); |
274 _suites.add(suite); | 274 _suites.add(suite); |
275 return suite; | 275 return suite; |
276 } finally { | 276 } finally { |
277 subscription.cancel(); | 277 subscription.cancel(); |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 /// Closes the loader and releases all resources allocated by it. | 281 /// Closes the loader and releases all resources allocated by it. |
282 Future close() { | 282 Future close() { |
283 return _closeThunk.run(() async { | 283 return _closeThunk.run(() async { |
284 await Future.wait(_suites.map((suite) => suite.close())); | 284 await Future.wait(_suites.map((suite) => suite.close())); |
285 _suites.clear(); | 285 _suites.clear(); |
286 | 286 |
287 if (!_browserServerThunk.hasRun) return; | 287 if (!_browserServerThunk.hasRun) return; |
288 await (await _browserServer).close(); | 288 await (await _browserServer).close(); |
289 }); | 289 }); |
290 } | 290 } |
291 } | 291 } |
OLD | NEW |