Chromium Code Reviews| 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 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 import '../lib/src/exit_codes.dart' as exit_codes; | 28 import '../lib/src/exit_codes.dart' as exit_codes; |
| 29 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 29 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
| 30 // with the git descriptor method. Maybe we should try to clean up the top level | 30 // with the git descriptor method. Maybe we should try to clean up the top level |
| 31 // scope a bit? | 31 // scope a bit? |
| 32 import '../lib/src/git.dart' as gitlib; | 32 import '../lib/src/git.dart' as gitlib; |
| 33 import '../lib/src/http.dart'; | 33 import '../lib/src/http.dart'; |
| 34 import '../lib/src/io.dart'; | 34 import '../lib/src/io.dart'; |
| 35 import '../lib/src/lock_file.dart'; | 35 import '../lib/src/lock_file.dart'; |
| 36 import '../lib/src/log.dart' as log; | 36 import '../lib/src/log.dart' as log; |
| 37 import '../lib/src/package.dart'; | 37 import '../lib/src/package.dart'; |
| 38 import '../lib/src/pubspec.dart'; | |
| 38 import '../lib/src/source/hosted.dart'; | 39 import '../lib/src/source/hosted.dart'; |
| 39 import '../lib/src/source/path.dart'; | 40 import '../lib/src/source/path.dart'; |
| 40 import '../lib/src/source_registry.dart'; | 41 import '../lib/src/source_registry.dart'; |
| 41 import '../lib/src/system_cache.dart'; | 42 import '../lib/src/system_cache.dart'; |
| 42 import '../lib/src/utils.dart'; | 43 import '../lib/src/utils.dart'; |
| 43 import '../lib/src/validator.dart'; | 44 import '../lib/src/validator.dart'; |
| 44 import '../lib/src/version.dart'; | 45 import '../lib/src/version.dart'; |
| 45 import 'descriptor.dart' as d; | 46 import 'descriptor.dart' as d; |
| 46 | 47 |
| 47 /// This should be called at the top of a test file to set up an appropriate | 48 /// This should be called at the top of a test file to set up an appropriate |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 65 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 66 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
| 66 /// enabled. | 67 /// enabled. |
| 67 Matcher isMinifiedDart2JSOutput = | 68 Matcher isMinifiedDart2JSOutput = |
| 68 isNot(contains("// The code supports the following hooks")); | 69 isNot(contains("// The code supports the following hooks")); |
| 69 | 70 |
| 70 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 71 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
| 71 /// disabled. | 72 /// disabled. |
| 72 Matcher isUnminifiedDart2JSOutput = | 73 Matcher isUnminifiedDart2JSOutput = |
| 73 contains("// The code supports the following hooks"); | 74 contains("// The code supports the following hooks"); |
| 74 | 75 |
| 76 /// The directory containing the version of barback that should be used for this | |
| 77 /// test. | |
| 78 String _barbackDir; | |
| 79 | |
| 80 /// A map from barback versions to their locations in the repo. | |
|
Bob Nystrom
2014/05/27 17:49:47
"their locations in the repo" -> "paths of directo
nweiz
2014/05/27 20:40:47
Done.
| |
| 81 /// | |
| 82 /// This includes the latest version of barback from pkg as well as all old | |
| 83 /// versions of barback in third_party. | |
| 84 final _barbackVersions = _computeBarbackVersions(); | |
| 85 | |
| 86 /// Populates [_barbackVersions]. | |
| 87 Map<Version, String> _computeBarbackVersions() { | |
|
Bob Nystrom
2014/05/27 17:49:47
Nit: "compute" -> "find"?
nweiz
2014/05/27 20:40:47
Done.
| |
| 88 var versions = {}; | |
| 89 var currentBarback = path.join(repoRoot, 'pkg', 'barback'); | |
| 90 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = | |
| 91 currentBarback; | |
| 92 | |
| 93 for (var dir in listDir(path.join(repoRoot, 'third_party', 'pkg'))) { | |
| 94 var basename = path.basename(dir); | |
| 95 if (!basename.startsWith('barback')) continue; | |
| 96 versions[new Version.parse(split1(basename, '-').last)] = dir; | |
| 97 } | |
| 98 | |
| 99 return versions; | |
| 100 } | |
| 101 | |
| 102 /// Runs the tests in [callback] against all versions of barback in the repo | |
| 103 /// that match [versionConstraint]. | |
| 104 /// | |
| 105 /// This is used to test that pub doesn't accidentally break older versions of | |
| 106 /// barback that it's committed to supporting. Only versions `0.13.0` and later | |
| 107 /// will be tested. | |
| 108 void withBarbackVersions(String versionConstraint, void callback()) { | |
| 109 var constraint = new VersionConstraint.parse(versionConstraint); | |
| 110 | |
| 111 var validVersions = _barbackVersions.keys.where(constraint.allows); | |
| 112 if (validVersions.isEmpty) { | |
| 113 throw new ArgumentError( | |
| 114 'No available barback version matches "$versionConstraint".'); | |
| 115 } | |
| 116 | |
| 117 for (var version in validVersions) { | |
| 118 group("with barback $version", () { | |
| 119 setUp(() { | |
| 120 _barbackDir = _barbackVersions[version]; | |
| 121 }); | |
| 122 | |
| 123 callback(); | |
| 124 }); | |
| 125 } | |
| 126 } | |
| 127 | |
| 75 /// The completer for [port]. | 128 /// The completer for [port]. |
| 76 Completer<int> get _portCompleter { | 129 Completer<int> get _portCompleter { |
| 77 if (_portCompleterCache != null) return _portCompleterCache; | 130 if (_portCompleterCache != null) return _portCompleterCache; |
| 78 _portCompleterCache = new Completer<int>(); | 131 _portCompleterCache = new Completer<int>(); |
| 79 currentSchedule.onComplete.schedule(() { | 132 currentSchedule.onComplete.schedule(() { |
| 80 _portCompleterCache = null; | 133 _portCompleterCache = null; |
| 81 }, 'clearing the port completer'); | 134 }, 'clearing the port completer'); |
| 82 return _portCompleterCache; | 135 return _portCompleterCache; |
| 83 } | 136 } |
| 84 | 137 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 } | 673 } |
| 621 } | 674 } |
| 622 | 675 |
| 623 if (pkg != null) { | 676 if (pkg != null) { |
| 624 var pkgDir = path.absolute(path.join( | 677 var pkgDir = path.absolute(path.join( |
| 625 path.dirname(Platform.executable), | 678 path.dirname(Platform.executable), |
| 626 '..', '..', '..', '..', 'pkg')); | 679 '..', '..', '..', '..', 'pkg')); |
| 627 | 680 |
| 628 _addPackage(String package) { | 681 _addPackage(String package) { |
| 629 if (dependencies.containsKey(package)) return; | 682 if (dependencies.containsKey(package)) return; |
| 630 var packagePath = path.join(pkgDir, package); | 683 |
| 684 var packagePath; | |
| 685 if (package == 'barback') { | |
| 686 if (_barbackDir == null) { | |
| 687 throw new StateError("createLockFile() can only create a lock file " | |
| 688 "with a barback dependency within a withBarbackVersions() " | |
| 689 "block."); | |
| 690 } | |
| 691 packagePath = _barbackDir; | |
| 692 } else { | |
| 693 packagePath = path.join(pkgDir, package); | |
| 694 } | |
| 695 | |
| 631 dependencies[package] = packagePath; | 696 dependencies[package] = packagePath; |
| 632 var pubspec = loadYaml( | 697 var pubspec = loadYaml( |
| 633 readTextFile(path.join(packagePath, 'pubspec.yaml'))); | 698 readTextFile(path.join(packagePath, 'pubspec.yaml'))); |
| 634 var packageDeps = pubspec['dependencies']; | 699 var packageDeps = pubspec['dependencies']; |
| 635 if (packageDeps == null) return; | 700 if (packageDeps == null) return; |
| 636 packageDeps.keys.forEach(_addPackage); | 701 packageDeps.keys.forEach(_addPackage); |
| 637 } | 702 } |
| 638 | 703 |
| 639 pkg.forEach(_addPackage); | 704 pkg.forEach(_addPackage); |
| 640 } | 705 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 _lastMatcher.matches(item.last, matchState); | 908 _lastMatcher.matches(item.last, matchState); |
| 844 } | 909 } |
| 845 | 910 |
| 846 Description describe(Description description) { | 911 Description describe(Description description) { |
| 847 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 912 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 848 } | 913 } |
| 849 } | 914 } |
| 850 | 915 |
| 851 /// A [StreamMatcher] that matches multiple lines of output. | 916 /// A [StreamMatcher] that matches multiple lines of output. |
| 852 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 917 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |