Chromium Code Reviews| Index: sdk/lib/_internal/pub/test/test_pub.dart |
| diff --git a/sdk/lib/_internal/pub/test/test_pub.dart b/sdk/lib/_internal/pub/test/test_pub.dart |
| index 37bf6d0b452120365b208c03c6eebbf1cb734518..c61e4d40097a0c03ff9eadf237a90b9ecfea47dd 100644 |
| --- a/sdk/lib/_internal/pub/test/test_pub.dart |
| +++ b/sdk/lib/_internal/pub/test/test_pub.dart |
| @@ -237,6 +237,53 @@ final String packagesPath = "$appPath/packages"; |
| /// Set to true when the current batch of scheduled events should be aborted. |
| bool _abortScheduled = false; |
| +/// Many tests validate behavior that is the same between pub install and |
| +/// update have the same behavior. Instead of duplicating those tests, this |
| +/// takes a callback that defines install/update agnostic tests and runs them |
| +/// with both commands. |
| +void forBothPubInstallAndUpdate(void callback(String command)) { |
| + group('install', () => callback('install')); |
| + group('update', () => callback('update')); |
| +} |
| + |
| +/// Schedules an invocation of pub [command] and validates that it completes |
| +/// in an expected way. |
| +/// |
| +/// By default, this validates that the command completes successfully and |
| +/// understands the normal output of a successful pub command. If [warning] is |
| +/// given, it expects the command to complete successfully *and* print |
| +/// [warning] to stderr. If [error] is given, it expects the command to *only* |
| +/// print [error] to stderr. |
| +// TODO(rnystrom): Clean up other tests to call this when possible. |
| +void runPub(String command, {Iterable<String> args, Pattern error, |
|
nweiz
2013/05/23 20:54:57
Since [command] can only be one of a finite set of
Bob Nystrom
2013/05/23 23:44:44
Done.
|
| + Pattern warning}) { |
| + var allArgs = [command]; |
| + if (args != null) allArgs.addAll(args); |
| + |
| + var output; |
| + switch (command) { |
| + case 'install': |
| + output = new RegExp("Dependencies installed!\$"); |
| + break; |
| + |
| + case 'update': |
| + output = new RegExp("Dependencies updated!\$"); |
| + break; |
| + |
| + default: |
| + throw 'Unknown pub command "$command".'; |
|
nweiz
2013/05/23 20:54:57
Wrap this in Exception.
Bob Nystrom
2013/05/23 23:44:44
Done.
|
| + } |
| + |
| + var exitCode = null; |
| + if (error != null) exitCode = 1; |
| + |
| + // No success output on an error. |
| + if (error != null) output = null; |
| + if (warning != null) error = warning; |
|
nweiz
2013/05/23 20:54:57
We should probably document and assert that error
Bob Nystrom
2013/05/23 23:44:44
Done.
|
| + |
| + schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); |
| +} |
| + |
| /// Defines an integration test. The [body] should schedule a series of |
| /// operations which will be run asynchronously. |
| void integration(String description, void body()) => |