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.test.io; | 5 library test.test.io; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
11 import 'package:test/src/util/io.dart'; | 11 import 'package:test/src/util/io.dart'; |
12 | 12 |
13 /// The path to the root directory of the `test` package. | 13 /// The path to the root directory of the `test` package. |
14 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); | 14 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); |
15 | 15 |
16 /// The path to the `pub` executable in the current Dart SDK. | 16 /// The path to the `pub` executable in the current Dart SDK. |
17 final _pubPath = p.join( | 17 final _pubPath = p.absolute(p.join( |
18 p.dirname(Platform.executable), | 18 p.dirname(Platform.executable), |
19 Platform.isWindows ? 'pub.bat' : 'pub'); | 19 Platform.isWindows ? 'pub.bat' : 'pub')); |
20 | 20 |
21 /// Runs the test executable with the package root set properly. | 21 /// Runs the test executable with the package root set properly. |
22 ProcessResult runUnittest(List<String> args, {String workingDirectory, | 22 ProcessResult runUnittest(List<String> args, {String workingDirectory, |
23 Map<String, String> environment}) { | 23 Map<String, String> environment}) { |
24 var allArgs = [ | 24 var allArgs = [ |
25 p.absolute(p.join(packageDir, 'bin/test.dart')), | 25 p.absolute(p.join(packageDir, 'bin/test.dart')), |
26 "--package-root=${p.join(packageDir, 'packages')}" | 26 "--package-root=${p.join(packageDir, 'packages')}" |
27 ]..addAll(args); | 27 ]..addAll(args); |
28 | 28 |
29 if (environment == null) environment = {}; | 29 if (environment == null) environment = {}; |
30 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); | 30 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); |
31 | 31 |
32 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 32 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
33 return runDart(allArgs, workingDirectory: workingDirectory, | 33 return runDart(allArgs, workingDirectory: workingDirectory, |
34 environment: environment); | 34 environment: environment); |
35 } | 35 } |
36 | 36 |
37 /// Runs Dart. | 37 /// Runs Dart. |
38 ProcessResult runDart(List<String> args, {String workingDirectory, | 38 ProcessResult runDart(List<String> args, {String workingDirectory, |
39 Map<String, String> environment}) { | 39 Map<String, String> environment}) { |
40 var allArgs = Platform.executableArguments.toList()..addAll(args); | 40 var allArgs = Platform.executableArguments.map((arg) { |
41 // The bots use a relative package root, which we need to make absolute if | |
kevmoo
2015/04/21 22:53:10
want to make this comment more general than just f
nweiz
2015/04/21 22:57:33
Done.
| |
42 // we're going to run in a different working directory. | |
43 if (!arg.startsWith("--package-root=")) return arg; | |
44 return "--package-root=" + | |
45 p.absolute(arg.substring("--package-root=".length)); | |
46 }).toList()..addAll(args); | |
41 | 47 |
42 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 48 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
43 return Process.runSync(Platform.executable, allArgs, | 49 return Process.runSync(p.absolute(Platform.executable), allArgs, |
44 workingDirectory: workingDirectory, environment: environment); | 50 workingDirectory: workingDirectory, environment: environment); |
45 } | 51 } |
46 | 52 |
47 /// Runs Pub. | 53 /// Runs Pub. |
48 ProcessResult runPub(List<String> args, {String workingDirectory, | 54 ProcessResult runPub(List<String> args, {String workingDirectory, |
49 Map<String, String> environment}) { | 55 Map<String, String> environment}) { |
50 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 56 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
51 return Process.runSync(_pubPath, args, | 57 return Process.runSync(_pubPath, args, |
52 workingDirectory: workingDirectory, environment: environment); | 58 workingDirectory: workingDirectory, environment: environment); |
53 } | 59 } |
(...skipping 23 matching lines...) Expand all Loading... | |
77 workingDirectory: workingDirectory, environment: environment); | 83 workingDirectory: workingDirectory, environment: environment); |
78 } | 84 } |
79 | 85 |
80 /// Starts Pub. | 86 /// Starts Pub. |
81 Future<Process> startPub(List<String> args, {String workingDirectory, | 87 Future<Process> startPub(List<String> args, {String workingDirectory, |
82 Map<String, String> environment}) { | 88 Map<String, String> environment}) { |
83 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 89 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
84 return Process.start(_pubPath, args, | 90 return Process.start(_pubPath, args, |
85 workingDirectory: workingDirectory, environment: environment); | 91 workingDirectory: workingDirectory, environment: environment); |
86 } | 92 } |
OLD | NEW |