| 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'; | |
| 9 | 8 |
| 10 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 11 import 'package:unittest/src/util/io.dart'; | 10 import 'package:unittest/src/util/io.dart'; |
| 12 | 11 |
| 13 /// The path to the root directory of the `unittest` package. | 12 /// The path to the root directory of the `unittest` package. |
| 14 final String packageDir = p.dirname(p.dirname(libraryPath(#unittest.test.io))); | 13 final String packageDir = p.dirname(p.dirname(libraryPath(#unittest.test.io))); |
| 15 | 14 |
| 16 /// Runs the unittest executable with the package root set properly. | 15 /// Runs the unittest executable with the package root set properly. |
| 17 ProcessResult runUnittest(List<String> args, {String workingDirectory, | 16 ProcessResult runUnittest(List<String> args, {String workingDirectory, |
| 18 Map<String, String> environment}) { | 17 Map<String, String> environment}) { |
| 19 var allArgs = [ | 18 var allArgs = [ |
| 20 p.join(packageDir, 'bin/unittest.dart'), | 19 p.absolute(p.join(packageDir, 'bin/unittest.dart')), |
| 21 "--package-root=${p.join(packageDir, 'packages')}" | 20 "--package-root=${p.join(packageDir, 'packages')}" |
| 22 ]..addAll(args); | 21 ]..addAll(args); |
| 23 | 22 |
| 24 if (environment == null) environment = {}; | 23 if (environment == null) environment = {}; |
| 25 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); | 24 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); |
| 26 | 25 |
| 27 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 26 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
| 28 return runDart(allArgs, workingDirectory: workingDirectory, | 27 return runDart(allArgs, workingDirectory: workingDirectory, |
| 29 environment: environment); | 28 environment: environment); |
| 30 } | 29 } |
| 31 | 30 |
| 32 /// Runs Dart. | 31 /// Runs Dart. |
| 33 ProcessResult runDart(List<String> args, {String workingDirectory, | 32 ProcessResult runDart(List<String> args, {String workingDirectory, |
| 34 Map<String, String> environment}) { | 33 Map<String, String> environment}) { |
| 35 var allArgs = Platform.executableArguments.toList()..addAll(args); | 34 var allArgs = Platform.executableArguments.toList()..addAll(args); |
| 36 | 35 |
| 37 // TODO(nweiz): Use ScheduledProcess once it's compatible. | 36 // TODO(nweiz): Use ScheduledProcess once it's compatible. |
| 38 return Process.runSync(Platform.executable, allArgs, | 37 return Process.runSync(Platform.executable, allArgs, |
| 39 workingDirectory: workingDirectory, environment: environment); | 38 workingDirectory: workingDirectory, environment: environment); |
| 40 } | 39 } |
| OLD | NEW |