Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: sdk/lib/_internal/pub/test/test_pub.dart

Issue 15701006: Clean up tests that are duplicated between install and update. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 /// directory. 230 /// directory.
231 final String appPath = "myapp"; 231 final String appPath = "myapp";
232 232
233 /// The path of the packages directory in the mock app used for tests. Relative 233 /// The path of the packages directory in the mock app used for tests. Relative
234 /// to the sandbox directory. 234 /// to the sandbox directory.
235 final String packagesPath = "$appPath/packages"; 235 final String packagesPath = "$appPath/packages";
236 236
237 /// Set to true when the current batch of scheduled events should be aborted. 237 /// Set to true when the current batch of scheduled events should be aborted.
238 bool _abortScheduled = false; 238 bool _abortScheduled = false;
239 239
240 /// Many tests validate behavior that is the same between pub install and
241 /// update have the same behavior. Instead of duplicating those tests, this
242 /// takes a callback that defines install/update agnostic tests and runs them
243 /// with both commands.
244 void forBothPubInstallAndUpdate(void callback(String command)) {
245 group('install', () => callback('install'));
246 group('update', () => callback('update'));
247 }
248
249 /// Schedules an invocation of pub [command] and validates that it completes
250 /// in an expected way.
251 ///
252 /// By default, this validates that the command completes successfully and
253 /// understands the normal output of a successful pub command. If [warning] is
254 /// given, it expects the command to complete successfully *and* print
255 /// [warning] to stderr. If [error] is given, it expects the command to *only*
256 /// print [error] to stderr.
257 // TODO(rnystrom): Clean up other tests to call this when possible.
258 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.
259 Pattern warning}) {
260 var allArgs = [command];
261 if (args != null) allArgs.addAll(args);
262
263 var output;
264 switch (command) {
265 case 'install':
266 output = new RegExp("Dependencies installed!\$");
267 break;
268
269 case 'update':
270 output = new RegExp("Dependencies updated!\$");
271 break;
272
273 default:
274 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.
275 }
276
277 var exitCode = null;
278 if (error != null) exitCode = 1;
279
280 // No success output on an error.
281 if (error != null) output = null;
282 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.
283
284 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode);
285 }
286
240 /// Defines an integration test. The [body] should schedule a series of 287 /// Defines an integration test. The [body] should schedule a series of
241 /// operations which will be run asynchronously. 288 /// operations which will be run asynchronously.
242 void integration(String description, void body()) => 289 void integration(String description, void body()) =>
243 _integration(description, body, test); 290 _integration(description, body, test);
244 291
245 /// Like [integration], but causes only this test to run. 292 /// Like [integration], but causes only this test to run.
246 void solo_integration(String description, void body()) => 293 void solo_integration(String description, void body()) =>
247 _integration(description, body, solo_test); 294 _integration(description, body, solo_test);
248 295
249 void _integration(String description, void body(), [Function testFn]) { 296 void _integration(String description, void body(), [Function testFn]) {
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 bool matches(item, MatchState matchState) { 729 bool matches(item, MatchState matchState) {
683 if (item is! Pair) return false; 730 if (item is! Pair) return false;
684 return _firstMatcher.matches(item.first, matchState) && 731 return _firstMatcher.matches(item.first, matchState) &&
685 _lastMatcher.matches(item.last, matchState); 732 _lastMatcher.matches(item.last, matchState);
686 } 733 }
687 734
688 Description describe(Description description) { 735 Description describe(Description description) {
689 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 736 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
690 } 737 }
691 } 738 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/pub_install_and_update_test.dart ('k') | sdk/lib/_internal/pub/test/unknown_source_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698