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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 /// | 405 /// |
406 /// Runs Pub with [args] and validates that its results match [output] (or | 406 /// Runs Pub with [args] and validates that its results match [output] (or |
407 /// [outputJson]), [error], and [exitCode]. | 407 /// [outputJson]), [error], and [exitCode]. |
408 /// | 408 /// |
409 /// [output] and [error] can be [String]s, [RegExp]s, or [Matcher]s. | 409 /// [output] and [error] can be [String]s, [RegExp]s, or [Matcher]s. |
410 /// | 410 /// |
411 /// If [outputJson] is given, validates that pub outputs stringified JSON | 411 /// If [outputJson] is given, validates that pub outputs stringified JSON |
412 /// matching that object, which can be a literal JSON object or any other | 412 /// matching that object, which can be a literal JSON object or any other |
413 /// [Matcher]. | 413 /// [Matcher]. |
414 void schedulePub({List args, output, error, outputJson, | 414 void schedulePub({List args, output, error, outputJson, |
415 Future<Uri> tokenEndpoint, int exitCode: exit_codes.SUCCESS}) { | 415 int exitCode: exit_codes.SUCCESS}) { |
416 // Cannot pass both output and outputJson. | 416 // Cannot pass both output and outputJson. |
417 assert(output == null || outputJson == null); | 417 assert(output == null || outputJson == null); |
418 | 418 |
419 var pub = startPub(args: args, tokenEndpoint: tokenEndpoint); | 419 var pub = startPub(args: args); |
420 pub.shouldExit(exitCode); | 420 pub.shouldExit(exitCode); |
421 | 421 |
422 var failures = []; | 422 var failures = []; |
423 var stderr; | 423 var stderr; |
424 | 424 |
425 expect(Future.wait([ | 425 expect(Future.wait([ |
426 pub.stdoutStream().toList(), | 426 pub.stdoutStream().toList(), |
427 pub.stderrStream().toList() | 427 pub.stderrStream().toList() |
428 ]).then((results) { | 428 ]).then((results) { |
429 var stdout = results[0].join("\n"); | 429 var stdout = results[0].join("\n"); |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 _lastMatcher.matches(item.last, matchState); | 967 _lastMatcher.matches(item.last, matchState); |
968 } | 968 } |
969 | 969 |
970 Description describe(Description description) { | 970 Description describe(Description description) { |
971 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 971 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
972 } | 972 } |
973 } | 973 } |
974 | 974 |
975 /// A [StreamMatcher] that matches multiple lines of output. | 975 /// A [StreamMatcher] that matches multiple lines of output. |
976 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 976 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |