OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Test infrastructure for testing pub. | 5 /// Test infrastructure for testing pub. |
6 /// | 6 /// |
7 /// Unlike typical unit tests, most pub tests are integration tests that stage | 7 /// Unlike typical unit tests, most pub tests are integration tests that stage |
8 /// some stuff on the file system, run pub, and then validate the results. This | 8 /// some stuff on the file system, run pub, and then validate the results. This |
9 /// library provides an API to build tests like that. | 9 /// library provides an API to build tests like that. |
10 library test_pub; | 10 library test_pub; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 /// | 212 /// |
213 /// By default, this validates that the command completes successfully and | 213 /// By default, this validates that the command completes successfully and |
214 /// understands the normal output of a successful pub command. If [warning] is | 214 /// understands the normal output of a successful pub command. If [warning] is |
215 /// given, it expects the command to complete successfully *and* print | 215 /// given, it expects the command to complete successfully *and* print |
216 /// [warning] to stderr. If [error] is given, it expects the command to *only* | 216 /// [warning] to stderr. If [error] is given, it expects the command to *only* |
217 /// print [error] to stderr. [output], [error], and [warning] may be strings, | 217 /// print [error] to stderr. [output], [error], and [warning] may be strings, |
218 /// [RegExp]s, or [Matcher]s. | 218 /// [RegExp]s, or [Matcher]s. |
219 /// | 219 /// |
220 /// If [exitCode] is given, expects the command to exit with that code. | 220 /// If [exitCode] is given, expects the command to exit with that code. |
221 // TODO(rnystrom): Clean up other tests to call this when possible. | 221 // TODO(rnystrom): Clean up other tests to call this when possible. |
222 void pubCommand(RunCommand command, | 222 void pubCommand(RunCommand command, {Iterable<String> args, output, error, |
223 {Iterable<String> args, output, error, warning, int exitCode}) { | 223 warning, int exitCode, Map<String, String> environment}) { |
224 if (error != null && warning != null) { | 224 if (error != null && warning != null) { |
225 throw new ArgumentError("Cannot pass both 'error' and 'warning'."); | 225 throw new ArgumentError("Cannot pass both 'error' and 'warning'."); |
226 } | 226 } |
227 | 227 |
228 var allArgs = [command.name]; | 228 var allArgs = [command.name]; |
229 if (args != null) allArgs.addAll(args); | 229 if (args != null) allArgs.addAll(args); |
230 | 230 |
231 if (output == null) output = command.success; | 231 if (output == null) output = command.success; |
232 | 232 |
233 if (error != null && exitCode == null) exitCode = 1; | 233 if (error != null && exitCode == null) exitCode = 1; |
234 | 234 |
235 // No success output on an error. | 235 // No success output on an error. |
236 if (error != null) output = null; | 236 if (error != null) output = null; |
237 if (warning != null) error = warning; | 237 if (warning != null) error = warning; |
238 | 238 |
239 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); | 239 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode, |
| 240 environment: environment); |
240 } | 241 } |
241 | 242 |
242 void pubGet({Iterable<String> args, output, error, warning, int exitCode}) { | 243 void pubGet({Iterable<String> args, output, error, warning, int exitCode, |
| 244 Map<String, String> environment}) { |
243 pubCommand(RunCommand.get, args: args, output: output, error: error, | 245 pubCommand(RunCommand.get, args: args, output: output, error: error, |
244 warning: warning, exitCode: exitCode); | 246 warning: warning, exitCode: exitCode, environment: environment); |
245 } | 247 } |
246 | 248 |
247 void pubUpgrade({Iterable<String> args, output, error, warning, int exitCode}) { | 249 void pubUpgrade({Iterable<String> args, output, error, warning, int exitCode, |
| 250 Map<String, String> environment}) { |
248 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, | 251 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, |
249 warning: warning, exitCode: exitCode); | 252 warning: warning, exitCode: exitCode, environment: environment); |
250 } | 253 } |
251 | 254 |
252 void pubDowngrade({Iterable<String> args, output, error, warning, | 255 void pubDowngrade({Iterable<String> args, output, error, warning, |
253 int exitCode}) { | 256 int exitCode, Map<String, String> environment}) { |
254 pubCommand(RunCommand.downgrade, args: args, output: output, error: error, | 257 pubCommand(RunCommand.downgrade, args: args, output: output, error: error, |
255 warning: warning, exitCode: exitCode); | 258 warning: warning, exitCode: exitCode, environment: environment); |
256 } | 259 } |
257 | 260 |
258 /// Schedules starting the "pub [global] run" process and validates the | 261 /// Schedules starting the "pub [global] run" process and validates the |
259 /// expected startup output. | 262 /// expected startup output. |
260 /// | 263 /// |
261 /// If [global] is `true`, this invokes "pub global run", otherwise it does | 264 /// If [global] is `true`, this invokes "pub global run", otherwise it does |
262 /// "pub run". | 265 /// "pub run". |
263 /// | 266 /// |
264 /// Returns the `pub run` process. | 267 /// Returns the `pub run` process. |
265 ScheduledProcess pubRun({bool global: false, Iterable<String> args}) { | 268 ScheduledProcess pubRun({bool global: false, Iterable<String> args}) { |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 _lastMatcher.matches(item.last, matchState); | 865 _lastMatcher.matches(item.last, matchState); |
863 } | 866 } |
864 | 867 |
865 Description describe(Description description) { | 868 Description describe(Description description) { |
866 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 869 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
867 } | 870 } |
868 } | 871 } |
869 | 872 |
870 /// A [StreamMatcher] that matches multiple lines of output. | 873 /// A [StreamMatcher] that matches multiple lines of output. |
871 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 874 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |