| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 /// The path of the packages directory in the mock app used for tests. Relative | 251 /// The path of the packages directory in the mock app used for tests. Relative |
| 252 /// to the sandbox directory. | 252 /// to the sandbox directory. |
| 253 final String packagesPath = "$appPath/packages"; | 253 final String packagesPath = "$appPath/packages"; |
| 254 | 254 |
| 255 /// Set to true when the current batch of scheduled events should be aborted. | 255 /// Set to true when the current batch of scheduled events should be aborted. |
| 256 bool _abortScheduled = false; | 256 bool _abortScheduled = false; |
| 257 | 257 |
| 258 /// Enum identifying a pub command that can be run with a well-defined success | 258 /// Enum identifying a pub command that can be run with a well-defined success |
| 259 /// output. | 259 /// output. |
| 260 class RunCommand { | 260 class RunCommand { |
| 261 static final install = new RunCommand('install', 'installed'); | 261 static final get = new RunCommand('get', 'Got dependencies!'); |
| 262 static final update = new RunCommand('update', 'updated'); | 262 static final upgrade = new RunCommand('upgrade', 'Dependencies upgraded!'); |
| 263 | 263 |
| 264 final String name; | 264 final String name; |
| 265 final RegExp success; | 265 final RegExp success; |
| 266 RunCommand(this.name, String verb) | 266 RunCommand(this.name, String message) |
| 267 : success = new RegExp("Dependencies $verb!\$"); | 267 : success = new RegExp("$message\$"); |
| 268 } | 268 } |
| 269 | 269 |
| 270 /// Many tests validate behavior that is the same between pub install and | 270 /// Many tests validate behavior that is the same between pub get and |
| 271 /// update have the same behavior. Instead of duplicating those tests, this | 271 /// upgrade have the same behavior. Instead of duplicating those tests, this |
| 272 /// takes a callback that defines install/update agnostic tests and runs them | 272 /// takes a callback that defines get/upgrade agnostic tests and runs them |
| 273 /// with both commands. | 273 /// with both commands. |
| 274 void forBothPubInstallAndUpdate(void callback(RunCommand command)) { | 274 void forBothPubGetAndUpgrade(void callback(RunCommand command)) { |
| 275 group(RunCommand.install.name, () => callback(RunCommand.install)); | 275 group(RunCommand.get.name, () => callback(RunCommand.get)); |
| 276 group(RunCommand.update.name, () => callback(RunCommand.update)); | 276 group(RunCommand.upgrade.name, () => callback(RunCommand.upgrade)); |
| 277 } | 277 } |
| 278 | 278 |
| 279 /// Schedules an invocation of pub [command] and validates that it completes | 279 /// Schedules an invocation of pub [command] and validates that it completes |
| 280 /// in an expected way. | 280 /// in an expected way. |
| 281 /// | 281 /// |
| 282 /// By default, this validates that the command completes successfully and | 282 /// By default, this validates that the command completes successfully and |
| 283 /// understands the normal output of a successful pub command. If [warning] is | 283 /// understands the normal output of a successful pub command. If [warning] is |
| 284 /// given, it expects the command to complete successfully *and* print | 284 /// given, it expects the command to complete successfully *and* print |
| 285 /// [warning] to stderr. If [error] is given, it expects the command to *only* | 285 /// [warning] to stderr. If [error] is given, it expects the command to *only* |
| 286 /// print [error] to stderr. | 286 /// print [error] to stderr. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 299 var exitCode = null; | 299 var exitCode = null; |
| 300 if (error != null) exitCode = 1; | 300 if (error != null) exitCode = 1; |
| 301 | 301 |
| 302 // No success output on an error. | 302 // No success output on an error. |
| 303 if (error != null) output = null; | 303 if (error != null) output = null; |
| 304 if (warning != null) error = warning; | 304 if (warning != null) error = warning; |
| 305 | 305 |
| 306 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); | 306 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void pubInstall({Iterable<String> args, Pattern error, | 309 void pubGet({Iterable<String> args, Pattern error, |
| 310 Pattern warning}) { | 310 Pattern warning}) { |
| 311 pubCommand(RunCommand.install, args: args, error: error, warning: warning); | 311 pubCommand(RunCommand.get, args: args, error: error, warning: warning); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void pubUpdate({Iterable<String> args, Pattern error, | 314 void pubUpgrade({Iterable<String> args, Pattern error, |
| 315 Pattern warning}) { | 315 Pattern warning}) { |
| 316 pubCommand(RunCommand.update, args: args, error: error, warning: warning); | 316 pubCommand(RunCommand.upgrade, args: args, error: error, warning: warning); |
| 317 } | 317 } |
| 318 | 318 |
| 319 /// Defines an integration test. The [body] should schedule a series of | 319 /// Defines an integration test. The [body] should schedule a series of |
| 320 /// operations which will be run asynchronously. | 320 /// operations which will be run asynchronously. |
| 321 void integration(String description, void body()) => | 321 void integration(String description, void body()) => |
| 322 _integration(description, body, test); | 322 _integration(description, body, test); |
| 323 | 323 |
| 324 /// Like [integration], but causes only this test to run. | 324 /// Like [integration], but causes only this test to run. |
| 325 void solo_integration(String description, void body()) => | 325 void solo_integration(String description, void body()) => |
| 326 _integration(description, body, solo_test); | 326 _integration(description, body, solo_test); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 598 |
| 599 schedule(() { | 599 schedule(() { |
| 600 return gitlib.isInstalled.then((installed) { | 600 return gitlib.isInstalled.then((installed) { |
| 601 if (installed) return; | 601 if (installed) return; |
| 602 if (runningOnBuildbot) return; | 602 if (runningOnBuildbot) return; |
| 603 currentSchedule.abort(); | 603 currentSchedule.abort(); |
| 604 }); | 604 }); |
| 605 }, 'ensuring that Git is installed'); | 605 }, 'ensuring that Git is installed'); |
| 606 } | 606 } |
| 607 | 607 |
| 608 /// Create a lock file for [package] without running `pub install`. | 608 /// Create a lock file for [package] without running `pub get`. |
| 609 /// | 609 /// |
| 610 /// This creates a lock file with only path dependencies. [sandbox] is a list of | 610 /// This creates a lock file with only path dependencies. [sandbox] is a list of |
| 611 /// dependencies to be found in the sandbox directory. [pkg] is a list of | 611 /// dependencies to be found in the sandbox directory. [pkg] is a list of |
| 612 /// packages in the Dart repo's "pkg" directory; each package listed here and | 612 /// packages in the Dart repo's "pkg" directory; each package listed here and |
| 613 /// all its dependencies will be linked to the version in the Dart repo. | 613 /// all its dependencies will be linked to the version in the Dart repo. |
| 614 void createLockFile(String package, {Iterable<String> sandbox, | 614 void createLockFile(String package, {Iterable<String> sandbox, |
| 615 Iterable<String> pkg}) { | 615 Iterable<String> pkg}) { |
| 616 var dependencies = {}; | 616 var dependencies = {}; |
| 617 | 617 |
| 618 if (sandbox != null) { | 618 if (sandbox != null) { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 bool matches(item, Map matchState) { | 836 bool matches(item, Map matchState) { |
| 837 if (item is! Pair) return false; | 837 if (item is! Pair) return false; |
| 838 return _firstMatcher.matches(item.first, matchState) && | 838 return _firstMatcher.matches(item.first, matchState) && |
| 839 _lastMatcher.matches(item.last, matchState); | 839 _lastMatcher.matches(item.last, matchState); |
| 840 } | 840 } |
| 841 | 841 |
| 842 Description describe(Description description) { | 842 Description describe(Description description) { |
| 843 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 843 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 844 } | 844 } |
| 845 } | 845 } |
| OLD | NEW |