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 unittest.test.io; | 5 library unittest.test.io; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
11 import 'package:stack_trace/stack_trace.dart'; | 11 import 'package:stack_trace/stack_trace.dart'; |
12 | 12 |
13 /// The root directory of the `unittest` package. | 13 /// The root directory of the `unittest` package. |
14 final String packageDir = _computePackageDir(); | 14 final String packageDir = _computePackageDir(); |
15 String _computePackageDir() => | 15 String _computePackageDir() => |
16 p.dirname(p.dirname(_libraryPath(#unittest.test.io))); | 16 p.dirname(p.dirname(_libraryPath(#unittest.test.io))); |
17 | 17 |
18 /// Runs the unittest executable with the package root set properly. | 18 /// Runs the unittest executable with the package root set properly. |
19 ProcessResult runUnittest(List<String> args, {String workingDirectory}) { | 19 ProcessResult runUnittest(List<String> args, {String workingDirectory, |
| 20 Map<String, String> environment}) { |
20 var allArgs = [ | 21 var allArgs = [ |
21 p.join(packageDir, 'bin/unittest.dart'), | 22 p.join(packageDir, 'bin/unittest.dart'), |
22 "--package-root=${p.join(packageDir, 'packages')}" | 23 "--package-root=${p.join(packageDir, 'packages')}" |
23 ]..addAll(args); | 24 ]..addAll(args); |
24 | 25 |
| 26 if (environment == null) environment = {}; |
| 27 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); |
| 28 |
25 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 29 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
26 return runDart(allArgs, workingDirectory: workingDirectory); | 30 return runDart(allArgs, workingDirectory: workingDirectory, |
| 31 environment: environment); |
27 } | 32 } |
28 | 33 |
29 /// Runs Dart. | 34 /// Runs Dart. |
30 ProcessResult runDart(List<String> args, {String workingDirectory}) { | 35 ProcessResult runDart(List<String> args, {String workingDirectory, |
| 36 Map<String, String> environment}) { |
31 var allArgs = Platform.executableArguments.toList()..addAll(args); | 37 var allArgs = Platform.executableArguments.toList()..addAll(args); |
32 | 38 |
33 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 39 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
34 return Process.runSync(Platform.executable, allArgs, | 40 return Process.runSync(Platform.executable, allArgs, |
35 workingDirectory: workingDirectory); | 41 workingDirectory: workingDirectory, environment: environment); |
36 } | 42 } |
37 | 43 |
38 /// Returns the path to the library named [libraryName]. | 44 /// Returns the path to the library named [libraryName]. |
39 /// | 45 /// |
40 /// The library name must be globally unique, or the wrong library path may be | 46 /// The library name must be globally unique, or the wrong library path may be |
41 /// returned. | 47 /// returned. |
42 String _libraryPath(Symbol libraryName) { | 48 String _libraryPath(Symbol libraryName) { |
43 var lib = currentMirrorSystem().findLibrary(libraryName); | 49 var lib = currentMirrorSystem().findLibrary(libraryName); |
44 return p.fromUri(lib.uri); | 50 return p.fromUri(lib.uri); |
45 } | 51 } |
46 | 52 |
47 | 53 |
OLD | NEW |