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:io'; | 8 import 'dart:io'; |
8 | 9 |
9 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
10 import 'package:test/src/util/io.dart'; | 11 import 'package:test/src/util/io.dart'; |
11 | 12 |
12 /// The path to the root directory of the `test` package. | 13 /// The path to the root directory of the `test` package. |
13 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); | 14 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); |
14 | 15 |
| 16 /// The path to the `pub` executable in the current Dart SDK. |
| 17 final _pubPath = p.join( |
| 18 p.dirname(Platform.executable), |
| 19 Platform.isWindows ? 'pub.bat' : 'pub'); |
| 20 |
15 /// Runs the test executable with the package root set properly. | 21 /// Runs the test executable with the package root set properly. |
16 ProcessResult runUnittest(List<String> args, {String workingDirectory, | 22 ProcessResult runUnittest(List<String> args, {String workingDirectory, |
17 Map<String, String> environment}) { | 23 Map<String, String> environment}) { |
18 var allArgs = [ | 24 var allArgs = [ |
19 p.absolute(p.join(packageDir, 'bin/test.dart')), | 25 p.absolute(p.join(packageDir, 'bin/test.dart')), |
20 "--package-root=${p.join(packageDir, 'packages')}" | 26 "--package-root=${p.join(packageDir, 'packages')}" |
21 ]..addAll(args); | 27 ]..addAll(args); |
22 | 28 |
23 if (environment == null) environment = {}; | 29 if (environment == null) environment = {}; |
24 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); | 30 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); |
25 | 31 |
26 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 32 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
27 return runDart(allArgs, workingDirectory: workingDirectory, | 33 return runDart(allArgs, workingDirectory: workingDirectory, |
28 environment: environment); | 34 environment: environment); |
29 } | 35 } |
30 | 36 |
31 /// Runs Dart. | 37 /// Runs Dart. |
32 ProcessResult runDart(List<String> args, {String workingDirectory, | 38 ProcessResult runDart(List<String> args, {String workingDirectory, |
33 Map<String, String> environment}) { | 39 Map<String, String> environment}) { |
34 var allArgs = Platform.executableArguments.toList()..addAll(args); | 40 var allArgs = Platform.executableArguments.toList()..addAll(args); |
35 | 41 |
36 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 42 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
37 return Process.runSync(Platform.executable, allArgs, | 43 return Process.runSync(Platform.executable, allArgs, |
38 workingDirectory: workingDirectory, environment: environment); | 44 workingDirectory: workingDirectory, environment: environment); |
39 } | 45 } |
| 46 |
| 47 /// Runs Pub. |
| 48 ProcessResult runPub(List<String> args, {String workingDirectory, |
| 49 Map<String, String> environment}) { |
| 50 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
| 51 return Process.runSync(_pubPath, args, |
| 52 workingDirectory: workingDirectory, environment: environment); |
| 53 } |
| 54 |
| 55 /// Starts Pub. |
| 56 Future<Process> startPub(List<String> args, {String workingDirectory, |
| 57 Map<String, String> environment}) { |
| 58 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
| 59 return Process.start(_pubPath, args, |
| 60 workingDirectory: workingDirectory, environment: environment); |
| 61 } |
OLD | NEW |