| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 /// The path of the packages directory in the mock app used for tests, relative | 307 /// The path of the packages directory in the mock app used for tests, relative |
| 308 /// to the sandbox directory. | 308 /// to the sandbox directory. |
| 309 final String packagesPath = "$appPath/packages"; | 309 final String packagesPath = "$appPath/packages"; |
| 310 | 310 |
| 311 /// Set to true when the current batch of scheduled events should be aborted. | 311 /// Set to true when the current batch of scheduled events should be aborted. |
| 312 bool _abortScheduled = false; | 312 bool _abortScheduled = false; |
| 313 | 313 |
| 314 /// Enum identifying a pub command that can be run with a well-defined success | 314 /// Enum identifying a pub command that can be run with a well-defined success |
| 315 /// output. | 315 /// output. |
| 316 class RunCommand { | 316 class RunCommand { |
| 317 static final get = new RunCommand('get', new RegExp(r'Got dependencies!$')); | 317 static final get = new RunCommand('get', new RegExp( |
| 318 r'Got dependencies!|Changed \d+ dependenc(y|ies)!')); |
| 318 static final upgrade = new RunCommand('upgrade', new RegExp( | 319 static final upgrade = new RunCommand('upgrade', new RegExp( |
| 319 r'(No dependencies changed\.|Changed \d+ dependenc(y|ies)!)$')); | 320 r'(No dependencies changed\.|Changed \d+ dependenc(y|ies)!)$')); |
| 320 | 321 |
| 321 final String name; | 322 final String name; |
| 322 final RegExp success; | 323 final RegExp success; |
| 323 RunCommand(this.name, this.success); | 324 RunCommand(this.name, this.success); |
| 324 } | 325 } |
| 325 | 326 |
| 326 /// Runs the tests defined within [callback] using both pub get and pub upgrade. | 327 /// Runs the tests defined within [callback] using both pub get and pub upgrade. |
| 327 /// | 328 /// |
| (...skipping 30 matching lines...) Expand all Loading... |
| 358 var exitCode = null; | 359 var exitCode = null; |
| 359 if (error != null) exitCode = 1; | 360 if (error != null) exitCode = 1; |
| 360 | 361 |
| 361 // No success output on an error. | 362 // No success output on an error. |
| 362 if (error != null) output = null; | 363 if (error != null) output = null; |
| 363 if (warning != null) error = warning; | 364 if (warning != null) error = warning; |
| 364 | 365 |
| 365 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); | 366 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void pubGet({Iterable<String> args, error, warning}) { | 369 void pubGet({Iterable<String> args, output, error, warning}) { |
| 369 pubCommand(RunCommand.get, args: args, error: error, warning: warning); | 370 pubCommand(RunCommand.get, args: args, output: output, error: error, |
| 371 warning: warning); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void pubUpgrade({Iterable<String> args, output, error, warning}) { | 374 void pubUpgrade({Iterable<String> args, output, error, warning}) { |
| 373 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, | 375 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, |
| 374 warning: warning); | 376 warning: warning); |
| 375 } | 377 } |
| 376 | 378 |
| 377 /// Defines an integration test. | 379 /// Defines an integration test. |
| 378 /// | 380 /// |
| 379 /// The [body] should schedule a series of operations which will be run | 381 /// The [body] should schedule a series of operations which will be run |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 _lastMatcher.matches(item.last, matchState); | 921 _lastMatcher.matches(item.last, matchState); |
| 920 } | 922 } |
| 921 | 923 |
| 922 Description describe(Description description) { | 924 Description describe(Description description) { |
| 923 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 925 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 924 } | 926 } |
| 925 } | 927 } |
| 926 | 928 |
| 927 /// A [StreamMatcher] that matches multiple lines of output. | 929 /// A [StreamMatcher] that matches multiple lines of output. |
| 928 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 930 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |