| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 72 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
| 73 /// enabled. | 73 /// enabled. |
| 74 Matcher isMinifiedDart2JSOutput = | 74 Matcher isMinifiedDart2JSOutput = |
| 75 isNot(contains("// The code supports the following hooks")); | 75 isNot(contains("// The code supports the following hooks")); |
| 76 | 76 |
| 77 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 77 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
| 78 /// disabled. | 78 /// disabled. |
| 79 Matcher isUnminifiedDart2JSOutput = | 79 Matcher isUnminifiedDart2JSOutput = |
| 80 contains("// The code supports the following hooks"); | 80 contains("// The code supports the following hooks"); |
| 81 | 81 |
| 82 /// The entrypoint for pub itself. |
| 83 final _entrypoint = new Entrypoint( |
| 84 pubRoot, new SystemCache.withSources(isOffline: true)); |
| 85 |
| 82 /// A map from package names to paths from which those packages should be loaded | 86 /// A map from package names to paths from which those packages should be loaded |
| 83 /// for [createLockFile]. | 87 /// for [createLockFile]. |
| 84 /// | 88 /// |
| 85 /// This allows older versions of dependencies than those that exist in the repo | 89 /// This allows older versions of dependencies than those that exist in the repo |
| 86 /// to be used when testing pub. | 90 /// to be used when testing pub. |
| 87 Map<String, String> _packageOverrides; | 91 Map<String, String> _packageOverrides; |
| 88 | 92 |
| 89 /// A map from barback versions to the paths of directories in the repo | 93 /// A map from barback versions to the paths to directories containing them. |
| 90 /// containing them. | |
| 91 /// | 94 /// |
| 92 /// This includes the latest version of barback from pkg as well as all old | 95 /// This includes the latest version of barback from pkg as well as all old |
| 93 /// versions of barback in third_party. | 96 /// versions of barback in third_party. |
| 94 final _barbackVersions = _findBarbackVersions(); | 97 final _barbackVersions = _findBarbackVersions(); |
| 95 | 98 |
| 96 /// Some older barback versions require older versions of barback's dependencies | 99 /// Some older barback versions require older versions of barback's dependencies |
| 97 /// than those that are in the repo. | 100 /// than those that are in the repo. |
| 98 /// | 101 /// |
| 99 /// This is a map from barback version ranges to the dependencies for those | 102 /// This is a map from barback version ranges to the dependencies for those |
| 100 /// barback versions. Each dependency version listed here should be included in | 103 /// barback versions. Each dependency version listed here should be included in |
| 101 /// third_party/pkg. | 104 /// third_party/pkg. |
| 102 final _barbackDeps = { | 105 final _barbackDeps = { |
| 103 new VersionConstraint.parse("<0.15.0"): { | 106 new VersionConstraint.parse("<0.15.0"): { |
| 104 "source_maps": "0.9.4" | 107 "source_maps": "0.9.4" |
| 105 } | 108 } |
| 106 }; | 109 }; |
| 107 | 110 |
| 108 /// Populates [_barbackVersions]. | 111 /// Populates [_barbackVersions]. |
| 109 Map<Version, String> _findBarbackVersions() { | 112 Map<Version, String> _findBarbackVersions() { |
| 110 var versions = {}; | 113 var versions = {}; |
| 111 var currentBarback = p.join(repoRoot, 'third_party', 'pkg', 'barback'); | |
| 112 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = | |
| 113 currentBarback; | |
| 114 | 114 |
| 115 for (var dir in listDir(p.join(repoRoot, 'third_party', 'pkg'))) { | 115 // It would be nice if this could use HostedSource's logic, but it's |
| 116 // asynchronous and this is a variable initializer. |
| 117 var currentBarback = packagePath('barback'); |
| 118 versions[_entrypoint.lockFile.packages['barback'].version] = currentBarback; |
| 119 |
| 120 for (var dir in listDir(p.join(pubRoot, 'third_party'))) { |
| 116 var basename = p.basename(dir); | 121 var basename = p.basename(dir); |
| 117 if (!basename.startsWith('barback-')) continue; | 122 if (!basename.startsWith('barback-')) continue; |
| 118 versions[new Version.parse(split1(basename, '-').last)] = dir; | 123 versions[new Version.parse(split1(basename, '-').last)] = dir; |
| 119 } | 124 } |
| 120 | 125 |
| 121 return versions; | 126 return versions; |
| 122 } | 127 } |
| 123 | 128 |
| 124 /// Runs the tests in [callback] against all versions of barback in the repo | 129 /// Runs the tests in [callback] against all versions of barback in the repo |
| 125 /// that match [versionConstraint]. | 130 /// that match [versionConstraint]. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 'No available barback version matches "$versionConstraint".'); | 141 'No available barback version matches "$versionConstraint".'); |
| 137 } | 142 } |
| 138 | 143 |
| 139 for (var version in validVersions) { | 144 for (var version in validVersions) { |
| 140 group("with barback $version", () { | 145 group("with barback $version", () { |
| 141 setUp(() { | 146 setUp(() { |
| 142 _packageOverrides = {}; | 147 _packageOverrides = {}; |
| 143 _packageOverrides['barback'] = _barbackVersions[version]; | 148 _packageOverrides['barback'] = _barbackVersions[version]; |
| 144 _barbackDeps.forEach((constraint, deps) { | 149 _barbackDeps.forEach((constraint, deps) { |
| 145 if (!constraint.allows(version)) return; | 150 if (!constraint.allows(version)) return; |
| 151 |
| 146 deps.forEach((packageName, version) { | 152 deps.forEach((packageName, version) { |
| 147 _packageOverrides[packageName] = p.join( | 153 _packageOverrides[packageName] = p.join( |
| 148 repoRoot, 'third_party', 'pkg', '$packageName-$version'); | 154 pubRoot, 'third_party', '$packageName-$version'); |
| 149 }); | 155 }); |
| 150 }); | 156 }); |
| 151 | 157 |
| 152 currentSchedule.onComplete.schedule(() { | 158 currentSchedule.onComplete.schedule(() { |
| 153 _packageOverrides = null; | 159 _packageOverrides = null; |
| 154 }); | 160 }); |
| 155 }); | 161 }); |
| 156 | 162 |
| 157 callback(); | 163 callback(); |
| 158 }); | 164 }); |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 if (hosted != null) { | 816 if (hosted != null) { |
| 811 hosted.forEach((name, version) { | 817 hosted.forEach((name, version) { |
| 812 var id = new PackageId(name, 'hosted', new Version.parse(version), name); | 818 var id = new PackageId(name, 'hosted', new Version.parse(version), name); |
| 813 lockFile.packages[name] = id; | 819 lockFile.packages[name] = id; |
| 814 }); | 820 }); |
| 815 } | 821 } |
| 816 | 822 |
| 817 return lockFile; | 823 return lockFile; |
| 818 } | 824 } |
| 819 | 825 |
| 820 /// Returns the path to [package] within the repo. | 826 /// Returns the path to the version of [package] used by pub. |
| 821 String packagePath(String package) => | 827 String packagePath(String package) { |
| 822 dirExists(p.join(repoRoot, 'pkg', package)) ? | 828 var id = _entrypoint.lockFile.packages[package]; |
| 823 p.join(repoRoot, 'pkg', package) : | 829 if (id == null) { |
| 824 p.join(repoRoot, 'third_party', 'pkg', package); | 830 throw new StateError( |
| 831 'The tests rely on "$package", but it\'s not in the lockfile.'); |
| 832 } |
| 833 |
| 834 return p.join( |
| 835 SystemCache.defaultDir, |
| 836 'hosted/pub.dartlang.org/$package-${id.version}'); |
| 837 } |
| 825 | 838 |
| 826 /// Uses [client] as the mock HTTP client for this test. | 839 /// Uses [client] as the mock HTTP client for this test. |
| 827 /// | 840 /// |
| 828 /// Note that this will only affect HTTP requests made via http.dart in the | 841 /// Note that this will only affect HTTP requests made via http.dart in the |
| 829 /// parent process. | 842 /// parent process. |
| 830 void useMockClient(MockClient client) { | 843 void useMockClient(MockClient client) { |
| 831 var oldInnerClient = innerHttpClient; | 844 var oldInnerClient = innerHttpClient; |
| 832 innerHttpClient = client; | 845 innerHttpClient = client; |
| 833 currentSchedule.onComplete.schedule(() { | 846 currentSchedule.onComplete.schedule(() { |
| 834 innerHttpClient = oldInnerClient; | 847 innerHttpClient = oldInnerClient; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 _lastMatcher.matches(item.last, matchState); | 1027 _lastMatcher.matches(item.last, matchState); |
| 1015 } | 1028 } |
| 1016 | 1029 |
| 1017 Description describe(Description description) { | 1030 Description describe(Description description) { |
| 1018 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1031 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 1019 } | 1032 } |
| 1020 } | 1033 } |
| 1021 | 1034 |
| 1022 /// A [StreamMatcher] that matches multiple lines of output. | 1035 /// A [StreamMatcher] that matches multiple lines of output. |
| 1023 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1036 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |