| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 67 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
| 68 /// enabled. | 68 /// enabled. |
| 69 Matcher isMinifiedDart2JSOutput = | 69 Matcher isMinifiedDart2JSOutput = |
| 70 isNot(contains("// The code supports the following hooks")); | 70 isNot(contains("// The code supports the following hooks")); |
| 71 | 71 |
| 72 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 72 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
| 73 /// disabled. | 73 /// disabled. |
| 74 Matcher isUnminifiedDart2JSOutput = | 74 Matcher isUnminifiedDart2JSOutput = |
| 75 contains("// The code supports the following hooks"); | 75 contains("// The code supports the following hooks"); |
| 76 | 76 |
| 77 /// The directory containing the version of barback that should be used for this | 77 /// A map from package names to paths from which those packages should be loaded |
| 78 /// test. | 78 /// for [createLockFile]. |
| 79 String _barbackDir; | 79 /// |
| 80 /// This allows older versions of dependencies than those that exist in the repo |
| 81 /// to be used when testing pub. |
| 82 Map<String, String> _packageOverrides; |
| 80 | 83 |
| 81 /// A map from barback versions to the paths of directories in the repo | 84 /// A map from barback versions to the paths of directories in the repo |
| 82 /// containing them. | 85 /// containing them. |
| 83 /// | 86 /// |
| 84 /// This includes the latest version of barback from pkg as well as all old | 87 /// This includes the latest version of barback from pkg as well as all old |
| 85 /// versions of barback in third_party. | 88 /// versions of barback in third_party. |
| 86 final _barbackVersions = _findBarbackVersions(); | 89 final _barbackVersions = _findBarbackVersions(); |
| 87 | 90 |
| 91 /// Some older barback versions require older versions of barback's dependencies |
| 92 /// than those that are in the repo. |
| 93 /// |
| 94 /// This is a map from barback version ranges to the dependencies for those |
| 95 /// barback versions. Each dependency version listed here should be included in |
| 96 /// third_party/pkg. |
| 97 final _barbackDeps = { |
| 98 new VersionConstraint.parse("<0.15.0"): { |
| 99 "source_maps": "0.9.4" |
| 100 } |
| 101 }; |
| 102 |
| 88 /// Populates [_barbackVersions]. | 103 /// Populates [_barbackVersions]. |
| 89 Map<Version, String> _findBarbackVersions() { | 104 Map<Version, String> _findBarbackVersions() { |
| 90 var versions = {}; | 105 var versions = {}; |
| 91 var currentBarback = path.join(repoRoot, 'pkg', 'barback'); | 106 var currentBarback = path.join(repoRoot, 'pkg', 'barback'); |
| 92 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = | 107 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = |
| 93 currentBarback; | 108 currentBarback; |
| 94 | 109 |
| 95 for (var dir in listDir(path.join(repoRoot, 'third_party', 'pkg'))) { | 110 for (var dir in listDir(path.join(repoRoot, 'third_party', 'pkg'))) { |
| 96 var basename = path.basename(dir); | 111 var basename = path.basename(dir); |
| 97 if (!basename.startsWith('barback')) continue; | 112 if (!basename.startsWith('barback')) continue; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 | 127 |
| 113 var validVersions = _barbackVersions.keys.where(constraint.allows); | 128 var validVersions = _barbackVersions.keys.where(constraint.allows); |
| 114 if (validVersions.isEmpty) { | 129 if (validVersions.isEmpty) { |
| 115 throw new ArgumentError( | 130 throw new ArgumentError( |
| 116 'No available barback version matches "$versionConstraint".'); | 131 'No available barback version matches "$versionConstraint".'); |
| 117 } | 132 } |
| 118 | 133 |
| 119 for (var version in validVersions) { | 134 for (var version in validVersions) { |
| 120 group("with barback $version", () { | 135 group("with barback $version", () { |
| 121 setUp(() { | 136 setUp(() { |
| 122 _barbackDir = _barbackVersions[version]; | 137 _packageOverrides = {}; |
| 138 _packageOverrides['barback'] = _barbackVersions[version]; |
| 139 _barbackDeps.forEach((constraint, deps) { |
| 140 if (!constraint.allows(version)) return; |
| 141 deps.forEach((packageName, version) { |
| 142 _packageOverrides[packageName] = path.join( |
| 143 repoRoot, 'third_party', 'pkg', '$packageName-$version'); |
| 144 }); |
| 145 }); |
| 146 |
| 147 currentSchedule.onComplete.schedule(() { |
| 148 _packageOverrides = null; |
| 149 }); |
| 123 }); | 150 }); |
| 124 | 151 |
| 125 callback(); | 152 callback(); |
| 126 }); | 153 }); |
| 127 } | 154 } |
| 128 } | 155 } |
| 129 | 156 |
| 130 /// The completer for [port]. | 157 /// The completer for [port]. |
| 131 Completer<int> get _portCompleter { | 158 Completer<int> get _portCompleter { |
| 132 if (_portCompleterCache != null) return _portCompleterCache; | 159 if (_portCompleterCache != null) return _portCompleterCache; |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 for (var package in sandbox) { | 809 for (var package in sandbox) { |
| 783 dependencies[package] = '../$package'; | 810 dependencies[package] = '../$package'; |
| 784 } | 811 } |
| 785 } | 812 } |
| 786 | 813 |
| 787 if (pkg != null) { | 814 if (pkg != null) { |
| 788 _addPackage(String package) { | 815 _addPackage(String package) { |
| 789 if (dependencies.containsKey(package)) return; | 816 if (dependencies.containsKey(package)) return; |
| 790 | 817 |
| 791 var packagePath; | 818 var packagePath; |
| 792 if (package == 'barback') { | 819 if (package == 'barback' && _packageOverrides == null) { |
| 793 if (_barbackDir == null) { | 820 throw new StateError("createLockFile() can only create a lock file " |
| 794 throw new StateError("createLockFile() can only create a lock file " | 821 "with a barback dependency within a withBarbackVersions() " |
| 795 "with a barback dependency within a withBarbackVersions() " | 822 "block."); |
| 796 "block."); | 823 } |
| 797 } | 824 |
| 798 packagePath = _barbackDir; | 825 if (_packageOverrides.containsKey(package)) { |
| 826 packagePath = _packageOverrides[package]; |
| 799 } else { | 827 } else { |
| 800 packagePath = path.join(pkgPath, package); | 828 packagePath = path.join(pkgPath, package); |
| 801 } | 829 } |
| 802 | 830 |
| 803 dependencies[package] = packagePath; | 831 dependencies[package] = packagePath; |
| 804 var pubspec = loadYaml( | 832 var pubspec = loadYaml( |
| 805 readTextFile(path.join(packagePath, 'pubspec.yaml'))); | 833 readTextFile(path.join(packagePath, 'pubspec.yaml'))); |
| 806 var packageDeps = pubspec['dependencies']; | 834 var packageDeps = pubspec['dependencies']; |
| 807 if (packageDeps == null) return; | 835 if (packageDeps == null) return; |
| 808 packageDeps.keys.forEach(_addPackage); | 836 packageDeps.keys.forEach(_addPackage); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 _lastMatcher.matches(item.last, matchState); | 1040 _lastMatcher.matches(item.last, matchState); |
| 1013 } | 1041 } |
| 1014 | 1042 |
| 1015 Description describe(Description description) { | 1043 Description describe(Description description) { |
| 1016 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1044 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 1017 } | 1045 } |
| 1018 } | 1046 } |
| 1019 | 1047 |
| 1020 /// A [StreamMatcher] that matches multiple lines of output. | 1048 /// A [StreamMatcher] that matches multiple lines of output. |
| 1021 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1049 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |