| 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 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 import 'dart:convert'; | 12 import 'dart:convert'; |
| 13 import 'dart:io'; | 13 import 'dart:io'; |
| 14 import 'dart:math'; | 14 import 'dart:math'; |
| 15 | 15 |
| 16 import 'package:http/testing.dart'; | 16 import 'package:http/testing.dart'; |
| 17 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
| 18 import 'package:scheduled_test/scheduled_process.dart'; | 18 import 'package:scheduled_test/scheduled_process.dart'; |
| 19 import 'package:scheduled_test/scheduled_server.dart'; | 19 import 'package:scheduled_test/scheduled_server.dart'; |
| 20 import 'package:scheduled_test/scheduled_test.dart'; | 20 import 'package:scheduled_test/scheduled_test.dart'; |
| 21 import 'package:unittest/compact_vm_config.dart'; | 21 import 'package:unittest/compact_vm_config.dart'; |
| 22 import 'package:yaml/yaml.dart'; | 22 import 'package:yaml/yaml.dart'; |
| 23 | 23 |
| 24 import '../lib/src/entrypoint.dart'; | 24 import '../lib/src/entrypoint.dart'; |
| 25 import '../lib/src/exit_codes.dart' as exit_codes; |
| 25 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 26 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
| 26 // with the git descriptor method. Maybe we should try to clean up the top level | 27 // with the git descriptor method. Maybe we should try to clean up the top level |
| 27 // scope a bit? | 28 // scope a bit? |
| 28 import '../lib/src/git.dart' as gitlib; | 29 import '../lib/src/git.dart' as gitlib; |
| 29 import '../lib/src/http.dart'; | 30 import '../lib/src/http.dart'; |
| 30 import '../lib/src/io.dart'; | 31 import '../lib/src/io.dart'; |
| 31 import '../lib/src/lock_file.dart'; | 32 import '../lib/src/lock_file.dart'; |
| 32 import '../lib/src/log.dart' as log; | 33 import '../lib/src/log.dart' as log; |
| 33 import '../lib/src/package.dart'; | 34 import '../lib/src/package.dart'; |
| 34 import '../lib/src/source/hosted.dart'; | 35 import '../lib/src/source/hosted.dart'; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 path.join(sandboxDir, symlink)), | 376 path.join(sandboxDir, symlink)), |
| 376 'symlinking $target to $symlink'); | 377 'symlinking $target to $symlink'); |
| 377 } | 378 } |
| 378 | 379 |
| 379 /// Schedules a call to the Pub command-line utility. | 380 /// Schedules a call to the Pub command-line utility. |
| 380 /// | 381 /// |
| 381 /// Runs Pub with [args] and validates that its results match [output] (or | 382 /// Runs Pub with [args] and validates that its results match [output] (or |
| 382 /// [outputJson]), [error], and [exitCode]. If [outputJson] is given, validates | 383 /// [outputJson]), [error], and [exitCode]. If [outputJson] is given, validates |
| 383 /// that pub outputs stringified JSON matching that object. | 384 /// that pub outputs stringified JSON matching that object. |
| 384 void schedulePub({List args, Pattern output, Pattern error, outputJson, | 385 void schedulePub({List args, Pattern output, Pattern error, outputJson, |
| 385 Future<Uri> tokenEndpoint, int exitCode: 0}) { | 386 Future<Uri> tokenEndpoint, int exitCode: exit_codes.SUCCESS}) { |
| 386 // Cannot pass both output and outputJson. | 387 // Cannot pass both output and outputJson. |
| 387 assert(output == null || outputJson == null); | 388 assert(output == null || outputJson == null); |
| 388 | 389 |
| 389 var pub = startPub(args: args, tokenEndpoint: tokenEndpoint); | 390 var pub = startPub(args: args, tokenEndpoint: tokenEndpoint); |
| 390 pub.shouldExit(exitCode); | 391 pub.shouldExit(exitCode); |
| 391 | 392 |
| 392 var failures = []; | 393 var failures = []; |
| 393 var stderr; | 394 var stderr; |
| 394 | 395 |
| 395 expect(Future.wait([ | 396 expect(Future.wait([ |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 bool matches(item, Map matchState) { | 859 bool matches(item, Map matchState) { |
| 859 if (item is! Pair) return false; | 860 if (item is! Pair) return false; |
| 860 return _firstMatcher.matches(item.first, matchState) && | 861 return _firstMatcher.matches(item.first, matchState) && |
| 861 _lastMatcher.matches(item.last, matchState); | 862 _lastMatcher.matches(item.last, matchState); |
| 862 } | 863 } |
| 863 | 864 |
| 864 Description describe(Description description) { | 865 Description describe(Description description) { |
| 865 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 866 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 866 } | 867 } |
| 867 } | 868 } |
| OLD | NEW |