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

Side by Side Diff: test/io.dart

Issue 2184543002: Use the package_resolver package. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 4 years, 5 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 | « pubspec.yaml ('k') | test/runner/browser/loader_test.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 // TODO(nweiz): Remove this tag when we can get [packageDir] working without it 5 // TODO(nweiz): Remove this tag when we can get [packageDir] working without it
6 // (dart-lang/sdk#24022). 6 // (dart-lang/sdk#24022).
7 library test.test.io; 7 library test.test.io;
8 8
9 import 'dart:async'; 9 import 'dart:async';
10 import 'dart:io'; 10 import 'dart:io';
11 import 'dart:isolate';
11 12
13 import 'package:package_resolver/package_resolver.dart';
12 import 'package:path/path.dart' as p; 14 import 'package:path/path.dart' as p;
13 import 'package:scheduled_test/descriptor.dart' as d; 15 import 'package:scheduled_test/descriptor.dart' as d;
14 import 'package:scheduled_test/scheduled_process.dart'; 16 import 'package:scheduled_test/scheduled_process.dart';
15 import 'package:scheduled_test/scheduled_stream.dart'; 17 import 'package:scheduled_test/scheduled_stream.dart';
16 import 'package:scheduled_test/scheduled_test.dart'; 18 import 'package:scheduled_test/scheduled_test.dart';
17 import 'package:test/src/util/io.dart'; 19 import 'package:test/src/util/io.dart';
18 20
19 /// The path to the root directory of the `test` package. 21 /// The path to the root directory of the `test` package.
20 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); 22 final Future<String> packageDir = PackageResolver.current.packagePath('test');
21 23
22 /// The path to the `pub` executable in the current Dart SDK. 24 /// The path to the `pub` executable in the current Dart SDK.
23 final _pubPath = p.absolute(p.join( 25 final _pubPath = p.absolute(p.join(
24 p.dirname(Platform.resolvedExecutable), 26 p.dirname(Platform.resolvedExecutable),
25 Platform.isWindows ? 'pub.bat' : 'pub')); 27 Platform.isWindows ? 'pub.bat' : 'pub'));
26 28
27 /// The platform-specific message emitted when a nonexistent file is loaded. 29 /// The platform-specific message emitted when a nonexistent file is loaded.
28 final String noSuchFileMessage = Platform.isWindows 30 final String noSuchFileMessage = Platform.isWindows
29 ? "The system cannot find the file specified." 31 ? "The system cannot find the file specified."
30 : "No such file or directory"; 32 : "No such file or directory";
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 /// Runs the test executable with the package root set properly. 103 /// Runs the test executable with the package root set properly.
102 /// 104 ///
103 /// If [forwardStdio] is true, the standard output and error from the process 105 /// If [forwardStdio] is true, the standard output and error from the process
104 /// will be printed as part of the parent test. This is used for debugging. 106 /// will be printed as part of the parent test. This is used for debugging.
105 ScheduledProcess runTest(List<String> args, {String reporter, 107 ScheduledProcess runTest(List<String> args, {String reporter,
106 int concurrency, Map<String, String> environment, 108 int concurrency, Map<String, String> environment,
107 bool forwardStdio: false}) { 109 bool forwardStdio: false}) {
108 concurrency ??= 1; 110 concurrency ??= 1;
109 111
110 var allArgs = [ 112 var allArgs = [
111 p.absolute(p.join(packageDir, 'bin/test.dart')), 113 packageDir.then((dir) => p.absolute(p.join(dir, 'bin/test.dart'))),
112 "--package-root=${p.join(packageDir, 'packages')}",
113 "--concurrency=$concurrency" 114 "--concurrency=$concurrency"
114 ]; 115 ];
115 if (reporter != null) allArgs.add("--reporter=$reporter"); 116 if (reporter != null) allArgs.add("--reporter=$reporter");
116 allArgs.addAll(args); 117 allArgs.addAll(args);
117 118
118 if (environment == null) environment = {}; 119 if (environment == null) environment = {};
119 environment.putIfAbsent("_DART_TEST_TESTING", () => "true"); 120 environment.putIfAbsent("_DART_TEST_TESTING", () => "true");
120 121
121 var process = runDart(allArgs, 122 var process = runDart(allArgs,
122 environment: environment, 123 environment: environment,
123 description: "dart bin/test.dart"); 124 description: "dart bin/test.dart");
124 125
125 if (forwardStdio) { 126 if (forwardStdio) {
126 process.stdoutStream().listen(print); 127 process.stdoutStream().listen(print);
127 process.stderrStream().listen(print); 128 process.stderrStream().listen(print);
128 } 129 }
129 130
130 return process; 131 return process;
131 } 132 }
132 133
133 /// Runs Dart. 134 /// Runs Dart.
134 ScheduledProcess runDart(List<String> args, {Map<String, String> environment, 135 ScheduledProcess runDart(List<String> args, {Map<String, String> environment,
135 String description}) { 136 String description}) {
136 var allArgs = Platform.executableArguments.map((arg) { 137 var allArgs = Platform.executableArguments
137 // The package root might be relative, so we need to make it absolute if 138 .where((arg) =>
138 // we're going to run in a different working directory. 139 !arg.startsWith("--package-root=") && !arg.startsWith("--packages="))
139 if (!arg.startsWith("--package-root=")) return arg; 140 .toList()
140 return "--package-root=" + 141 ..add(PackageResolver.current.processArgument)
141 p.absolute(p.fromUri(arg.substring("--package-root=".length))); 142 ..addAll(args);
142 }).toList()..addAll(args);
143 143
144 return new ScheduledProcess.start( 144 return new ScheduledProcess.start(
145 p.absolute(Platform.resolvedExecutable), allArgs, 145 p.absolute(Platform.resolvedExecutable), allArgs,
146 workingDirectory: _sandbox, 146 workingDirectory: _sandbox,
147 environment: environment, 147 environment: environment,
148 description: description); 148 description: description);
149 } 149 }
150 150
151 /// Runs Pub. 151 /// Runs Pub.
152 ScheduledProcess runPub(List args, {Map<String, String> environment}) { 152 ScheduledProcess runPub(List args, {Map<String, String> environment}) {
(...skipping 22 matching lines...) Expand all
175 var match; 175 var match;
176 while (match == null) { 176 while (match == null) {
177 var line = await pub.stdout.next(); 177 var line = await pub.stdout.next();
178 match = _servingRegExp.firstMatch(line); 178 match = _servingRegExp.firstMatch(line);
179 } 179 }
180 _pubServePortCompleter.complete(int.parse(match[1])); 180 _pubServePortCompleter.complete(int.parse(match[1]));
181 }, "waiting for pub serve to emit its port number"); 181 }, "waiting for pub serve to emit its port number");
182 182
183 return pub; 183 return pub;
184 } 184 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | test/runner/browser/loader_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698