| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 /// Set to true when the current batch of scheduled events should be aborted. | 322 /// Set to true when the current batch of scheduled events should be aborted. |
| 323 bool _abortScheduled = false; | 323 bool _abortScheduled = false; |
| 324 | 324 |
| 325 /// Enum identifying a pub command that can be run with a well-defined success | 325 /// Enum identifying a pub command that can be run with a well-defined success |
| 326 /// output. | 326 /// output. |
| 327 class RunCommand { | 327 class RunCommand { |
| 328 static final get = new RunCommand('get', new RegExp( | 328 static final get = new RunCommand('get', new RegExp( |
| 329 r'Got dependencies!|Changed \d+ dependenc(y|ies)!')); | 329 r'Got dependencies!|Changed \d+ dependenc(y|ies)!')); |
| 330 static final upgrade = new RunCommand('upgrade', new RegExp( | 330 static final upgrade = new RunCommand('upgrade', new RegExp( |
| 331 r'(No dependencies changed\.|Changed \d+ dependenc(y|ies)!)$')); | 331 r'(No dependencies changed\.|Changed \d+ dependenc(y|ies)!)$')); |
| 332 static final downgrade = new RunCommand('downgrade', new RegExp( |
| 333 r'(No dependencies changed\.|Changed \d+ dependenc(y|ies)!)$')); |
| 332 | 334 |
| 333 final String name; | 335 final String name; |
| 334 final RegExp success; | 336 final RegExp success; |
| 335 RunCommand(this.name, this.success); | 337 RunCommand(this.name, this.success); |
| 336 } | 338 } |
| 337 | 339 |
| 338 /// Runs the tests defined within [callback] using both pub get and pub upgrade. | 340 /// Runs the tests defined within [callback] using both pub get and pub upgrade. |
| 339 /// | 341 /// |
| 340 /// Many tests validate behavior that is the same between pub get and | 342 /// Many tests validate behavior that is the same between pub get and |
| 341 /// upgrade have the same behavior. Instead of duplicating those tests, this | 343 /// upgrade have the same behavior. Instead of duplicating those tests, this |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 void pubGet({Iterable<String> args, output, error, warning, int exitCode}) { | 383 void pubGet({Iterable<String> args, output, error, warning, int exitCode}) { |
| 382 pubCommand(RunCommand.get, args: args, output: output, error: error, | 384 pubCommand(RunCommand.get, args: args, output: output, error: error, |
| 383 warning: warning, exitCode: exitCode); | 385 warning: warning, exitCode: exitCode); |
| 384 } | 386 } |
| 385 | 387 |
| 386 void pubUpgrade({Iterable<String> args, output, error, warning, int exitCode}) { | 388 void pubUpgrade({Iterable<String> args, output, error, warning, int exitCode}) { |
| 387 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, | 389 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, |
| 388 warning: warning, exitCode: exitCode); | 390 warning: warning, exitCode: exitCode); |
| 389 } | 391 } |
| 390 | 392 |
| 393 void pubDowngrade({Iterable<String> args, output, error, warning, |
| 394 int exitCode}) { |
| 395 pubCommand(RunCommand.downgrade, args: args, output: output, error: error, |
| 396 warning: warning, exitCode: exitCode); |
| 397 } |
| 398 |
| 391 /// Schedules starting the "pub [global] run" process and validates the | 399 /// Schedules starting the "pub [global] run" process and validates the |
| 392 /// expected startup output. | 400 /// expected startup output. |
| 393 /// | 401 /// |
| 394 /// If [global] is `true`, this invokes "pub global run", otherwise it does | 402 /// If [global] is `true`, this invokes "pub global run", otherwise it does |
| 395 /// "pub run". | 403 /// "pub run". |
| 396 /// | 404 /// |
| 397 /// Returns the `pub run` process. | 405 /// Returns the `pub run` process. |
| 398 ScheduledProcess pubRun({bool global: false, Iterable<String> args}) { | 406 ScheduledProcess pubRun({bool global: false, Iterable<String> args}) { |
| 399 var pubArgs = global ? ["global", "run"] : ["run"]; | 407 var pubArgs = global ? ["global", "run"] : ["run"]; |
| 400 pubArgs.addAll(args); | 408 pubArgs.addAll(args); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 _lastMatcher.matches(item.last, matchState); | 1012 _lastMatcher.matches(item.last, matchState); |
| 1005 } | 1013 } |
| 1006 | 1014 |
| 1007 Description describe(Description description) { | 1015 Description describe(Description description) { |
| 1008 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1016 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 1009 } | 1017 } |
| 1010 } | 1018 } |
| 1011 | 1019 |
| 1012 /// A [StreamMatcher] that matches multiple lines of output. | 1020 /// A [StreamMatcher] that matches multiple lines of output. |
| 1013 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1021 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |