Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: lib/src/runner/loader.dart

Issue 1055083004: Normalize handling of the package root in the runner. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Unused import Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/runner/browser/server.dart ('k') | lib/src/util/io.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 17 matching lines...) Expand all
28 class Loader { 28 class Loader {
29 /// All platforms for which tests should be loaded. 29 /// All platforms for which tests should be loaded.
30 final List<TestPlatform> _platforms; 30 final List<TestPlatform> _platforms;
31 31
32 /// Whether to enable colors for Dart compilation. 32 /// Whether to enable colors for Dart compilation.
33 final bool _color; 33 final bool _color;
34 34
35 /// The root directory that will be served for browser tests. 35 /// The root directory that will be served for browser tests.
36 final String _root; 36 final String _root;
37 37
38 /// The package root to use for loading tests, or `null` to use the automatic 38 /// The package root to use for loading tests.
39 /// root.
40 final String _packageRoot; 39 final String _packageRoot;
41 40
42 /// The URL for the `pub serve` instance to use to load tests. 41 /// The URL for the `pub serve` instance to use to load tests.
43 /// 42 ///
44 /// This is `null` if tests should be loaded from the filesystem. 43 /// This is `null` if tests should be loaded from the filesystem.
45 final Uri _pubServeUrl; 44 final Uri _pubServeUrl;
46 45
47 /// All isolates that have been spun up by the loader. 46 /// All isolates that have been spun up by the loader.
48 final _isolates = new Set<Isolate>(); 47 final _isolates = new Set<Isolate>();
49 48
(...skipping 14 matching lines...) Expand all
64 return _browserServerCompleter.future; 63 return _browserServerCompleter.future;
65 } 64 }
66 Completer<BrowserServer> _browserServerCompleter; 65 Completer<BrowserServer> _browserServerCompleter;
67 66
68 /// Creates a new loader. 67 /// Creates a new loader.
69 /// 68 ///
70 /// [root] is the root directory that will be served for browser tests. It 69 /// [root] is the root directory that will be served for browser tests. It
71 /// defaults to the working directory. 70 /// defaults to the working directory.
72 /// 71 ///
73 /// If [packageRoot] is passed, it's used as the package root for all loaded 72 /// If [packageRoot] is passed, it's used as the package root for all loaded
74 /// tests. Otherwise, the `packages/` directories next to the test entrypoints 73 /// tests. Otherwise, it's inferred from [root].
75 /// will be used.
76 /// 74 ///
77 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve` 75 /// If [pubServeUrl] is passed, tests will be loaded from the `pub serve`
78 /// instance at that URL rather than from the filesystem. 76 /// instance at that URL rather than from the filesystem.
79 /// 77 ///
80 /// If [color] is true, console colors will be used when compiling Dart. 78 /// If [color] is true, console colors will be used when compiling Dart.
79 ///
80 /// If the package root doesn't exist, throws an [ApplicationException].
81 Loader(Iterable<TestPlatform> platforms, {String root, String packageRoot, 81 Loader(Iterable<TestPlatform> platforms, {String root, String packageRoot,
82 Uri pubServeUrl, bool color: false}) 82 Uri pubServeUrl, bool color: false})
83 : _platforms = platforms.toList(), 83 : _platforms = platforms.toList(),
84 _pubServeUrl = pubServeUrl, 84 _pubServeUrl = pubServeUrl,
85 _root = root == null ? p.current : root, 85 _root = root == null ? p.current : root,
86 _packageRoot = packageRoot, 86 _packageRoot = packageRootFor(root, packageRoot),
87 _color = color; 87 _color = color;
88 88
89 /// Loads all test suites in [dir]. 89 /// Loads all test suites in [dir].
90 /// 90 ///
91 /// This will load tests from files that end in "_test.dart". Any tests that 91 /// This will load tests from files that end in "_test.dart". Any tests that
92 /// fail to load will be emitted as [LoadException]s. 92 /// fail to load will be emitted as [LoadException]s.
93 Stream<Suite> loadDir(String dir) { 93 Stream<Suite> loadDir(String dir) {
94 return mergeStreams(new Directory(dir).listSync(recursive: true) 94 return mergeStreams(new Directory(dir).listSync(recursive: true)
95 .map((entry) { 95 .map((entry) {
96 if (entry is! File) return new Stream.fromIterable([]); 96 if (entry is! File) return new Stream.fromIterable([]);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return controller.stream; 149 return controller.stream;
150 } 150 }
151 151
152 /// Load the test suite at [path] in a browser. 152 /// Load the test suite at [path] in a browser.
153 Future<Suite> _loadBrowserFile(String path, TestPlatform platform) => 153 Future<Suite> _loadBrowserFile(String path, TestPlatform platform) =>
154 _browserServer.then((browserServer) => 154 _browserServer.then((browserServer) =>
155 browserServer.loadSuite(path, platform)); 155 browserServer.loadSuite(path, platform));
156 156
157 /// Load the test suite at [path] in VM isolate. 157 /// Load the test suite at [path] in VM isolate.
158 Future<Suite> _loadVmFile(String path) { 158 Future<Suite> _loadVmFile(String path) {
159 var packageRoot = packageRootFor(path, _packageRoot);
160 var receivePort = new ReceivePort(); 159 var receivePort = new ReceivePort();
161 160
162 return new Future.sync(() { 161 return new Future.sync(() {
163 if (_pubServeUrl != null) { 162 if (_pubServeUrl != null) {
164 var url = _pubServeUrl.resolve( 163 var url = _pubServeUrl.resolve(
165 p.relative(path, from: 'test') + '.vm_test.dart'); 164 p.relative(path, from: 'test') + '.vm_test.dart');
166 return Isolate.spawnUri(url, [], {'reply': receivePort.sendPort}) 165 return Isolate.spawnUri(url, [], {'reply': receivePort.sendPort})
167 .then((isolate) => new IsolateWrapper(isolate, () {})) 166 .then((isolate) => new IsolateWrapper(isolate, () {}))
168 .catchError((error, stackTrace) { 167 .catchError((error, stackTrace) {
169 if (error is! IsolateSpawnException) throw error; 168 if (error is! IsolateSpawnException) throw error;
(...skipping 15 matching lines...) Expand all
185 import "package:test/src/runner/vm/isolate_listener.dart"; 184 import "package:test/src/runner/vm/isolate_listener.dart";
186 185
187 import "${p.toUri(p.absolute(path))}" as test; 186 import "${p.toUri(p.absolute(path))}" as test;
188 187
189 void main(_, Map message) { 188 void main(_, Map message) {
190 var sendPort = message['reply']; 189 var sendPort = message['reply'];
191 IsolateListener.start(sendPort, () => test.main); 190 IsolateListener.start(sendPort, () => test.main);
192 } 191 }
193 ''', { 192 ''', {
194 'reply': receivePort.sendPort 193 'reply': receivePort.sendPort
195 }, packageRoot: packageRoot); 194 }, packageRoot: _packageRoot);
196 } 195 }
197 }).catchError((error, stackTrace) { 196 }).catchError((error, stackTrace) {
198 receivePort.close(); 197 receivePort.close();
199 if (error is LoadException) throw error; 198 if (error is LoadException) throw error;
200 return new Future.error(new LoadException(path, error), stackTrace); 199 return new Future.error(new LoadException(path, error), stackTrace);
201 }).then((isolate) { 200 }).then((isolate) {
202 _isolates.add(isolate); 201 _isolates.add(isolate);
203 return receivePort.first; 202 return receivePort.first;
204 }).then((response) { 203 }).then((response) {
205 if (response["type"] == "loadException") { 204 if (response["type"] == "loadException") {
(...skipping 16 matching lines...) Expand all
222 Future close() { 221 Future close() {
223 for (var isolate in _isolates) { 222 for (var isolate in _isolates) {
224 isolate.kill(); 223 isolate.kill();
225 } 224 }
226 _isolates.clear(); 225 _isolates.clear();
227 226
228 if (_browserServerCompleter == null) return new Future.value(); 227 if (_browserServerCompleter == null) return new Future.value();
229 return _browserServer.then((browserServer) => browserServer.close()); 228 return _browserServer.then((browserServer) => browserServer.close());
230 } 229 }
231 } 230 }
OLDNEW
« no previous file with comments | « lib/src/runner/browser/server.dart ('k') | lib/src/util/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698