OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library testing.discover; | 5 library testing.discover; |
6 | 6 |
7 import 'dart:io' show | 7 import 'dart:io' show Directory, FileSystemEntity, Platform, Process; |
8 Directory, | |
9 FileSystemEntity, | |
10 Platform, | |
11 Process; | |
12 | 8 |
13 import 'dart:async' show | 9 import 'dart:async' show Future, Stream, StreamController, StreamSubscription; |
14 Future, | |
15 Stream, | |
16 StreamController, | |
17 StreamSubscription; | |
18 | 10 |
19 import '../testing.dart' show | 11 import '../testing.dart' show TestDescription; |
20 TestDescription; | |
21 | 12 |
22 final Uri packageConfig = computePackageConfig(); | 13 final Uri packageConfig = computePackageConfig(); |
23 | 14 |
24 final Uri dartSdk = computeDartSdk(); | 15 final Uri dartSdk = computeDartSdk(); |
25 | 16 |
26 /// Common arguments when running a dart program. Returns a copy that can | 17 /// Common arguments when running a dart program. Returns a copy that can |
27 /// safely be modified by caller. | 18 /// safely be modified by caller. |
28 List<String> get dartArguments => <String>["-c", "--packages=$packageConfig"]; | 19 List<String> get dartArguments => <String>["-c", "--packages=$packageConfig"]; |
29 | 20 |
30 Stream<TestDescription> listTests(List<Uri> testRoots, {Pattern pattern}) { | 21 Stream<TestDescription> listTests(List<Uri> testRoots, {Pattern pattern}) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 return controller.stream; | 56 return controller.stream; |
66 } | 57 } |
67 | 58 |
68 Uri computePackageConfig() { | 59 Uri computePackageConfig() { |
69 String path = Platform.packageConfig; | 60 String path = Platform.packageConfig; |
70 if (path != null) return Uri.base.resolve(path); | 61 if (path != null) return Uri.base.resolve(path); |
71 return Uri.base.resolve(".packages"); | 62 return Uri.base.resolve(".packages"); |
72 } | 63 } |
73 | 64 |
74 Uri computeDartSdk() { | 65 Uri computeDartSdk() { |
75 String dartSdkPath = Platform.environment["DART_SDK"] | 66 String dartSdkPath = Platform.environment["DART_SDK"] ?? |
76 ?? const String.fromEnvironment("DART_SDK"); | 67 const String.fromEnvironment("DART_SDK"); |
77 if (dartSdkPath != null) { | 68 if (dartSdkPath != null) { |
78 return Uri.base.resolveUri(new Uri.file(dartSdkPath)); | 69 return Uri.base.resolveUri(new Uri.file(dartSdkPath)); |
79 } else { | 70 } else { |
80 return Uri.base.resolve(Platform.resolvedExecutable).resolve("../"); | 71 return Uri.base.resolve(Platform.resolvedExecutable).resolve("../"); |
81 } | 72 } |
82 } | 73 } |
83 | 74 |
84 Future<Process> startDart( | 75 Future<Process> startDart(Uri program, |
85 Uri program, | 76 [List<String> arguments, List<String> vmArguments]) { |
86 [List<String> arguments, | |
87 List<String> vmArguments]) { | |
88 List<String> allArguments = <String>[]; | 77 List<String> allArguments = <String>[]; |
89 allArguments.addAll(vmArguments ?? dartArguments); | 78 allArguments.addAll(vmArguments ?? dartArguments); |
90 allArguments.add(program.toFilePath()); | 79 allArguments.add(program.toFilePath()); |
91 if (arguments != null) { | 80 if (arguments != null) { |
92 allArguments.addAll(arguments); | 81 allArguments.addAll(arguments); |
93 } | 82 } |
94 return Process.start(Platform.resolvedExecutable, allArguments); | 83 return Process.start(Platform.resolvedExecutable, allArguments); |
95 } | 84 } |
OLD | NEW |