| 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. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
| 7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
| 8 /// tests like that. | 8 /// tests like that. |
| 9 library test_pub; | 9 library test_pub; |
| 10 | 10 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 group(RunCommand.upgrade.name, () => callback(RunCommand.upgrade)); | 320 group(RunCommand.upgrade.name, () => callback(RunCommand.upgrade)); |
| 321 } | 321 } |
| 322 | 322 |
| 323 /// Schedules an invocation of pub [command] and validates that it completes | 323 /// Schedules an invocation of pub [command] and validates that it completes |
| 324 /// in an expected way. | 324 /// in an expected way. |
| 325 /// | 325 /// |
| 326 /// By default, this validates that the command completes successfully and | 326 /// By default, this validates that the command completes successfully and |
| 327 /// understands the normal output of a successful pub command. If [warning] is | 327 /// understands the normal output of a successful pub command. If [warning] is |
| 328 /// given, it expects the command to complete successfully *and* print | 328 /// given, it expects the command to complete successfully *and* print |
| 329 /// [warning] to stderr. If [error] is given, it expects the command to *only* | 329 /// [warning] to stderr. If [error] is given, it expects the command to *only* |
| 330 /// print [error] to stderr. | 330 /// print [error] to stderr. [output], [error], and [warning] may be strings, |
| 331 /// [RegExp]s, or [Matcher]s. |
| 331 // TODO(rnystrom): Clean up other tests to call this when possible. | 332 // TODO(rnystrom): Clean up other tests to call this when possible. |
| 332 void pubCommand(RunCommand command, | 333 void pubCommand(RunCommand command, |
| 333 {Iterable<String> args, Pattern output, Pattern error, Pattern warning}) { | 334 {Iterable<String> args, output, error, warning}) { |
| 334 if (error != null && warning != null) { | 335 if (error != null && warning != null) { |
| 335 throw new ArgumentError("Cannot pass both 'error' and 'warning'."); | 336 throw new ArgumentError("Cannot pass both 'error' and 'warning'."); |
| 336 } | 337 } |
| 337 | 338 |
| 338 var allArgs = [command.name]; | 339 var allArgs = [command.name]; |
| 339 if (args != null) allArgs.addAll(args); | 340 if (args != null) allArgs.addAll(args); |
| 340 | 341 |
| 341 if (output == null) output = command.success; | 342 if (output == null) output = command.success; |
| 342 | 343 |
| 343 var exitCode = null; | 344 var exitCode = null; |
| 344 if (error != null) exitCode = 1; | 345 if (error != null) exitCode = 1; |
| 345 | 346 |
| 346 // No success output on an error. | 347 // No success output on an error. |
| 347 if (error != null) output = null; | 348 if (error != null) output = null; |
| 348 if (warning != null) error = warning; | 349 if (warning != null) error = warning; |
| 349 | 350 |
| 350 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); | 351 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); |
| 351 } | 352 } |
| 352 | 353 |
| 353 void pubGet({Iterable<String> args, Pattern error, | 354 void pubGet({Iterable<String> args, error, warning}) { |
| 354 Pattern warning}) { | |
| 355 pubCommand(RunCommand.get, args: args, error: error, warning: warning); | 355 pubCommand(RunCommand.get, args: args, error: error, warning: warning); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void pubUpgrade({Iterable<String> args, Pattern output, Pattern error, | 358 void pubUpgrade({Iterable<String> args, output, error, warning}) { |
| 359 Pattern warning}) { | |
| 360 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, | 359 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, |
| 361 warning: warning); | 360 warning: warning); |
| 362 } | 361 } |
| 363 | 362 |
| 364 /// Defines an integration test. The [body] should schedule a series of | 363 /// Defines an integration test. The [body] should schedule a series of |
| 365 /// operations which will be run asynchronously. | 364 /// operations which will be run asynchronously. |
| 366 void integration(String description, void body()) => | 365 void integration(String description, void body()) => |
| 367 _integration(description, body, test); | 366 _integration(description, body, test); |
| 368 | 367 |
| 369 /// Like [integration], but causes only this test to run. | 368 /// Like [integration], but causes only this test to run. |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 _lastMatcher.matches(item.last, matchState); | 908 _lastMatcher.matches(item.last, matchState); |
| 910 } | 909 } |
| 911 | 910 |
| 912 Description describe(Description description) { | 911 Description describe(Description description) { |
| 913 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 912 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 914 } | 913 } |
| 915 } | 914 } |
| 916 | 915 |
| 917 /// A [StreamMatcher] that matches multiple lines of output. | 916 /// A [StreamMatcher] that matches multiple lines of output. |
| 918 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 917 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |