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

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

Issue 351703004: Improve pub's pubspec error messages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 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. 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 337
338 /// Schedules an invocation of pub [command] and validates that it completes 338 /// Schedules an invocation of pub [command] and validates that it completes
339 /// in an expected way. 339 /// in an expected way.
340 /// 340 ///
341 /// By default, this validates that the command completes successfully and 341 /// By default, this validates that the command completes successfully and
342 /// understands the normal output of a successful pub command. If [warning] is 342 /// understands the normal output of a successful pub command. If [warning] is
343 /// given, it expects the command to complete successfully *and* print 343 /// given, it expects the command to complete successfully *and* print
344 /// [warning] to stderr. If [error] is given, it expects the command to *only* 344 /// [warning] to stderr. If [error] is given, it expects the command to *only*
345 /// print [error] to stderr. [output], [error], and [warning] may be strings, 345 /// print [error] to stderr. [output], [error], and [warning] may be strings,
346 /// [RegExp]s, or [Matcher]s. 346 /// [RegExp]s, or [Matcher]s.
347 ///
348 /// If [exitCode] is given, expects the command to exit with that code.
347 // TODO(rnystrom): Clean up other tests to call this when possible. 349 // TODO(rnystrom): Clean up other tests to call this when possible.
348 void pubCommand(RunCommand command, 350 void pubCommand(RunCommand command,
349 {Iterable<String> args, output, error, warning}) { 351 {Iterable<String> args, output, error, warning, int exitCode}) {
350 if (error != null && warning != null) { 352 if (error != null && warning != null) {
351 throw new ArgumentError("Cannot pass both 'error' and 'warning'."); 353 throw new ArgumentError("Cannot pass both 'error' and 'warning'.");
352 } 354 }
353 355
354 var allArgs = [command.name]; 356 var allArgs = [command.name];
355 if (args != null) allArgs.addAll(args); 357 if (args != null) allArgs.addAll(args);
356 358
357 if (output == null) output = command.success; 359 if (output == null) output = command.success;
358 360
359 var exitCode = null; 361 if (error != null && exitCode == null) exitCode = 1;
360 if (error != null) exitCode = 1;
361 362
362 // No success output on an error. 363 // No success output on an error.
363 if (error != null) output = null; 364 if (error != null) output = null;
364 if (warning != null) error = warning; 365 if (warning != null) error = warning;
365 366
366 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode); 367 schedulePub(args: allArgs, output: output, error: error, exitCode: exitCode);
367 } 368 }
368 369
369 void pubGet({Iterable<String> args, output, error, warning}) { 370 void pubGet({Iterable<String> args, output, error, warning, int exitCode}) {
370 pubCommand(RunCommand.get, args: args, output: output, error: error, 371 pubCommand(RunCommand.get, args: args, output: output, error: error,
371 warning: warning); 372 warning: warning, exitCode: exitCode);
372 } 373 }
373 374
374 void pubUpgrade({Iterable<String> args, output, error, warning}) { 375 void pubUpgrade({Iterable<String> args, output, error, warning, int exitCode}) {
375 pubCommand(RunCommand.upgrade, args: args, output: output, error: error, 376 pubCommand(RunCommand.upgrade, args: args, output: output, error: error,
376 warning: warning); 377 warning: warning, exitCode: exitCode);
377 } 378 }
378 379
379 /// Defines an integration test. 380 /// Defines an integration test.
380 /// 381 ///
381 /// The [body] should schedule a series of operations which will be run 382 /// The [body] should schedule a series of operations which will be run
382 /// asynchronously. 383 /// asynchronously.
383 void integration(String description, void body()) => 384 void integration(String description, void body()) =>
384 _integration(description, body, test); 385 _integration(description, body, test);
385 386
386 /// Like [integration], but causes only this test to run. 387 /// Like [integration], but causes only this test to run.
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 _lastMatcher.matches(item.last, matchState); 922 _lastMatcher.matches(item.last, matchState);
922 } 923 }
923 924
924 Description describe(Description description) { 925 Description describe(Description description) {
925 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 926 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
926 } 927 }
927 } 928 }
928 929
929 /// A [StreamMatcher] that matches multiple lines of output. 930 /// A [StreamMatcher] that matches multiple lines of output.
930 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); 931 StreamMatcher emitsLines(String output) => inOrder(output.split("\n"));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698