| 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 | 23 |
| 23 import '../lib/src/entrypoint.dart'; | 24 import '../lib/src/entrypoint.dart'; |
| 24 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 25 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
| 25 // with the git descriptor method. Maybe we should try to clean up the top level | 26 // with the git descriptor method. Maybe we should try to clean up the top level |
| 26 // scope a bit? | 27 // scope a bit? |
| 27 import '../lib/src/git.dart' as gitlib; | 28 import '../lib/src/git.dart' as gitlib; |
| 28 import '../lib/src/http.dart'; | 29 import '../lib/src/http.dart'; |
| 29 import '../lib/src/io.dart'; | 30 import '../lib/src/io.dart'; |
| 31 import '../lib/src/lock_file.dart'; |
| 30 import '../lib/src/log.dart' as log; | 32 import '../lib/src/log.dart' as log; |
| 33 import '../lib/src/package.dart'; |
| 31 import '../lib/src/safe_http_server.dart'; | 34 import '../lib/src/safe_http_server.dart'; |
| 32 import '../lib/src/system_cache.dart'; | 35 import '../lib/src/system_cache.dart'; |
| 33 import '../lib/src/utils.dart'; | 36 import '../lib/src/utils.dart'; |
| 34 import '../lib/src/validator.dart'; | 37 import '../lib/src/validator.dart'; |
| 38 import '../lib/src/version.dart'; |
| 35 import 'descriptor.dart' as d; | 39 import 'descriptor.dart' as d; |
| 36 | 40 |
| 37 /// This should be called at the top of a test file to set up an appropriate | 41 /// This should be called at the top of a test file to set up an appropriate |
| 38 /// test configuration for the machine running the tests. | 42 /// test configuration for the machine running the tests. |
| 39 initConfig() { | 43 initConfig() { |
| 40 useCompactVMConfiguration(); | 44 useCompactVMConfiguration(); |
| 41 filterStacks = true; | 45 filterStacks = true; |
| 42 unittestConfiguration.timeout = null; | 46 unittestConfiguration.timeout = null; |
| 43 } | 47 } |
| 44 | 48 |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 598 |
| 595 schedule(() { | 599 schedule(() { |
| 596 return gitlib.isInstalled.then((installed) { | 600 return gitlib.isInstalled.then((installed) { |
| 597 if (installed) return; | 601 if (installed) return; |
| 598 if (runningOnBuildbot) return; | 602 if (runningOnBuildbot) return; |
| 599 currentSchedule.abort(); | 603 currentSchedule.abort(); |
| 600 }); | 604 }); |
| 601 }, 'ensuring that Git is installed'); | 605 }, 'ensuring that Git is installed'); |
| 602 } | 606 } |
| 603 | 607 |
| 608 /// Create a lock file for [package] without running `pub install`. |
| 609 /// |
| 610 /// This creates a lock file with only path dependencies. [dependencies] is a |
| 611 /// map of dependency names to paths. [pkg] is a list of packages in the Dart |
| 612 /// repo's "pkg" directory; each package listed here and all its dependencies |
| 613 /// will be linked to the version in the Dart repo. |
| 614 void createLockFile(String package, Map<String, String> dependencies, |
| 615 {Iterable<String> pkg}) { |
| 616 if (pkg != null) { |
| 617 var pkgDir = path.absolute(path.join( |
| 618 path.dirname(Platform.executable), |
| 619 '..', '..', '..', '..', 'pkg')); |
| 620 |
| 621 _addPackage(String package) { |
| 622 if (dependencies.containsKey(package)) return; |
| 623 var packagePath = path.join(pkgDir, package); |
| 624 dependencies[package] = packagePath; |
| 625 var pubspec = loadYaml( |
| 626 readTextFile(path.join(packagePath, 'pubspec.yaml'))); |
| 627 var packageDeps = pubspec['dependencies']; |
| 628 if (packageDeps == null) return; |
| 629 packageDeps.keys.forEach(_addPackage); |
| 630 } |
| 631 |
| 632 pkg.forEach(_addPackage); |
| 633 } |
| 634 |
| 635 var lockFile = new LockFile.empty(); |
| 636 dependencies.forEach((name, dependencyPath) { |
| 637 var id = new PackageId(name, 'path', new Version(0, 0, 0), { |
| 638 'path': dependencyPath, |
| 639 'relative': path.isRelative(dependencyPath) |
| 640 }); |
| 641 lockFile.packages[name] = id; |
| 642 }); |
| 643 d.file(path.join(package, 'pubspec.lock'), lockFile.serialize()).create(); |
| 644 } |
| 645 |
| 604 /// Use [client] as the mock HTTP client for this test. | 646 /// Use [client] as the mock HTTP client for this test. |
| 605 /// | 647 /// |
| 606 /// Note that this will only affect HTTP requests made via http.dart in the | 648 /// Note that this will only affect HTTP requests made via http.dart in the |
| 607 /// parent process. | 649 /// parent process. |
| 608 void useMockClient(MockClient client) { | 650 void useMockClient(MockClient client) { |
| 609 var oldInnerClient = httpClient.inner; | 651 var oldInnerClient = httpClient.inner; |
| 610 httpClient.inner = client; | 652 httpClient.inner = client; |
| 611 currentSchedule.onComplete.schedule(() { | 653 currentSchedule.onComplete.schedule(() { |
| 612 httpClient.inner = oldInnerClient; | 654 httpClient.inner = oldInnerClient; |
| 613 }, 'de-activating the mock client'); | 655 }, 'de-activating the mock client'); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 bool matches(item, Map matchState) { | 828 bool matches(item, Map matchState) { |
| 787 if (item is! Pair) return false; | 829 if (item is! Pair) return false; |
| 788 return _firstMatcher.matches(item.first, matchState) && | 830 return _firstMatcher.matches(item.first, matchState) && |
| 789 _lastMatcher.matches(item.last, matchState); | 831 _lastMatcher.matches(item.last, matchState); |
| 790 } | 832 } |
| 791 | 833 |
| 792 Description describe(Description description) { | 834 Description describe(Description description) { |
| 793 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 835 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 794 } | 836 } |
| 795 } | 837 } |
| OLD | NEW |