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 // TODO(nweiz): Remove this tag when we can get [packageDir] working without it | 5 // TODO(nweiz): Remove this tag when we can get [packageDir] working without it |
6 // (dart-lang/sdk#24022). | 6 // (dart-lang/sdk#24022). |
7 library test.test.io; | 7 library test.test.io; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 /// Returns a [StreamMatcher] that asserts that the stream emits strings | 90 /// Returns a [StreamMatcher] that asserts that the stream emits strings |
91 /// containing each string in [strings] in order. | 91 /// containing each string in [strings] in order. |
92 /// | 92 /// |
93 /// This expects each string in [strings] to match a different string in the | 93 /// This expects each string in [strings] to match a different string in the |
94 /// stream. | 94 /// stream. |
95 StreamMatcher containsInOrder(Iterable<String> strings) => | 95 StreamMatcher containsInOrder(Iterable<String> strings) => |
96 inOrder(strings.map((string) => consumeThrough(contains(string)))); | 96 inOrder(strings.map((string) => consumeThrough(contains(string)))); |
97 | 97 |
98 /// Runs the test executable with the package root set properly. | 98 /// Runs the test executable with the package root set properly. |
| 99 /// |
| 100 /// If [forwardStdio] is true, the standard output and error from the process |
| 101 /// will be printed as part of the parent test. This is used for debugging. |
99 ScheduledProcess runTest(List args, {String reporter, | 102 ScheduledProcess runTest(List args, {String reporter, |
100 int concurrency, Map<String, String> environment}) { | 103 int concurrency, Map<String, String> environment, |
| 104 bool forwardStdio: false}) { |
101 reporter ??= "expanded"; | 105 reporter ??= "expanded"; |
102 concurrency ??= 1; | 106 concurrency ??= 1; |
103 | 107 |
104 var allArgs = [ | 108 var allArgs = [ |
105 p.absolute(p.join(packageDir, 'bin/test.dart')), | 109 p.absolute(p.join(packageDir, 'bin/test.dart')), |
106 "--package-root=${p.join(packageDir, 'packages')}", | 110 "--package-root=${p.join(packageDir, 'packages')}", |
107 "--concurrency=$concurrency", | 111 "--concurrency=$concurrency", |
108 "--reporter=$reporter" | 112 "--reporter=$reporter" |
109 ]..addAll(args); | 113 ]..addAll(args); |
110 | 114 |
111 if (environment == null) environment = {}; | 115 if (environment == null) environment = {}; |
112 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); | 116 environment.putIfAbsent("_UNITTEST_USE_COLOR", () => "false"); |
113 | 117 |
114 return runDart(allArgs, | 118 var process = runDart(allArgs, |
115 environment: environment, | 119 environment: environment, |
116 description: "dart bin/test.dart"); | 120 description: "dart bin/test.dart"); |
| 121 |
| 122 if (forwardStdio) { |
| 123 process.stdoutStream().listen(print); |
| 124 process.stderrStream().listen(print); |
| 125 } |
| 126 |
| 127 return process; |
117 } | 128 } |
118 | 129 |
119 /// Runs Dart. | 130 /// Runs Dart. |
120 ScheduledProcess runDart(List args, {Map<String, String> environment, | 131 ScheduledProcess runDart(List args, {Map<String, String> environment, |
121 String description}) { | 132 String description}) { |
122 var allArgs = Platform.executableArguments.map((arg) { | 133 var allArgs = Platform.executableArguments.map((arg) { |
123 // The package root might be relative, so we need to make it absolute if | 134 // The package root might be relative, so we need to make it absolute if |
124 // we're going to run in a different working directory. | 135 // we're going to run in a different working directory. |
125 if (!arg.startsWith("--package-root=")) return arg; | 136 if (!arg.startsWith("--package-root=")) return arg; |
126 return "--package-root=" + | 137 return "--package-root=" + |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 var match; | 172 var match; |
162 while (match == null) { | 173 while (match == null) { |
163 var line = await pub.stdout.next(); | 174 var line = await pub.stdout.next(); |
164 match = _servingRegExp.firstMatch(line); | 175 match = _servingRegExp.firstMatch(line); |
165 } | 176 } |
166 _pubServePortCompleter.complete(int.parse(match[1])); | 177 _pubServePortCompleter.complete(int.parse(match[1])); |
167 }, "waiting for pub serve to emit its port number"); | 178 }, "waiting for pub serve to emit its port number"); |
168 | 179 |
169 return pub; | 180 return pub; |
170 } | 181 } |
OLD | NEW |