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 | 67 |
68 /// A [Matcher] that matches JavaScript generated by dart2js with minification | 68 /// A [Matcher] that matches JavaScript generated by dart2js with minification |
69 /// disabled. | 69 /// disabled. |
70 Matcher isUnminifiedDart2JSOutput = | 70 Matcher isUnminifiedDart2JSOutput = |
71 contains("// The code supports the following hooks"); | 71 contains("// The code supports the following hooks"); |
72 | 72 |
73 /// The entrypoint for pub itself. | 73 /// The entrypoint for pub itself. |
74 final _entrypoint = new Entrypoint( | 74 final _entrypoint = new Entrypoint( |
75 pubRoot, new SystemCache.withSources(isOffline: true)); | 75 pubRoot, new SystemCache.withSources(isOffline: true)); |
76 | 76 |
77 /// A map from package names to paths from which those packages should be loaded | |
78 /// for [createLockFile]. | |
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; | |
83 | |
84 /// A map from barback versions to the paths to directories containing them. | |
85 /// | |
86 /// This includes the latest version of barback from pkg as well as all old | |
87 /// versions of barback in third_party. | |
88 final _barbackVersions = _findBarbackVersions(); | |
89 | |
90 /// Some older barback versions require older versions of barback's dependencies | |
91 /// than those that are in the repo. | |
92 /// | |
93 /// This is a map from barback version ranges to the dependencies for those | |
94 /// barback versions. Each dependency version listed here should be included in | |
95 /// third_party/pkg. | |
96 final _barbackDeps = { | |
97 new VersionConstraint.parse("<0.15.0"): { | |
98 "source_maps": "0.9.4" | |
99 } | |
100 }; | |
101 | |
102 /// Populates [_barbackVersions]. | |
103 Map<Version, String> _findBarbackVersions() { | |
104 var versions = {}; | |
105 | |
106 var currentBarback; | |
107 var pkgPath; | |
108 if (runningFromDartRepo) { | |
109 currentBarback = p.join(dartRepoRoot, 'third_party', 'pkg', 'barback'); | |
110 pkgPath = p.join(dartRepoRoot, 'third_party', 'pkg'); | |
111 } else { | |
112 // It would be nice if this could use HostedSource's logic, but it's | |
113 // asynchronous and this is a variable initializer. | |
114 currentBarback = packagePath('barback'); | |
115 pkgPath = p.join(pubRoot, 'third_party'); | |
116 } | |
117 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = | |
118 currentBarback; | |
119 | |
120 for (var dir in listDir(pkgPath)) { | |
121 var basename = p.basename(dir); | |
122 if (!basename.startsWith('barback-')) continue; | |
123 versions[new Version.parse(split1(basename, '-').last)] = dir; | |
124 } | |
125 | |
126 return versions; | |
127 } | |
128 | |
129 /// Runs the tests in [callback] against all versions of barback in the repo | |
130 /// that match [versionConstraint]. | |
131 /// | |
132 /// This is used to test that pub doesn't accidentally break older versions of | |
133 /// barback that it's committed to supporting. Only versions `0.13.0` and later | |
134 /// will be tested. | |
135 void withBarbackVersions(String versionConstraint, void callback()) { | |
136 var constraint = new VersionConstraint.parse(versionConstraint); | |
137 | |
138 var validVersions = _barbackVersions.keys.where(constraint.allows); | |
139 if (validVersions.isEmpty) { | |
140 throw new ArgumentError( | |
141 'No available barback version matches "$versionConstraint".'); | |
142 } | |
143 | |
144 for (var version in validVersions) { | |
145 group("with barback $version", () { | |
146 setUp(() { | |
147 _packageOverrides = {}; | |
148 _packageOverrides['barback'] = _barbackVersions[version]; | |
149 _barbackDeps.forEach((constraint, deps) { | |
150 if (!constraint.allows(version)) return; | |
151 | |
152 deps.forEach((packageName, version) { | |
153 _packageOverrides[packageName] = runningFromDartRepo | |
154 ? p.join(dartRepoRoot, 'third_party/pkg/$packageName-$version') | |
155 : p.join(pubRoot, 'third_party/$packageName-$version'); | |
156 }); | |
157 }); | |
158 | |
159 currentSchedule.onComplete.schedule(() { | |
160 _packageOverrides = null; | |
161 }); | |
162 }); | |
163 | |
164 callback(); | |
165 }); | |
166 } | |
167 } | |
168 | |
169 /// The completer for [port]. | 77 /// The completer for [port]. |
170 Completer<int> get _portCompleter { | 78 Completer<int> get _portCompleter { |
171 if (_portCompleterCache != null) return _portCompleterCache; | 79 if (_portCompleterCache != null) return _portCompleterCache; |
172 _portCompleterCache = new Completer<int>(); | 80 _portCompleterCache = new Completer<int>(); |
173 currentSchedule.onComplete.schedule(() { | 81 currentSchedule.onComplete.schedule(() { |
174 _portCompleterCache = null; | 82 _portCompleterCache = null; |
175 }, 'clearing the port completer'); | 83 }, 'clearing the port completer'); |
176 return _portCompleterCache; | 84 return _portCompleterCache; |
177 } | 85 } |
178 | 86 |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 if (sandbox != null) { | 669 if (sandbox != null) { |
762 for (var package in sandbox) { | 670 for (var package in sandbox) { |
763 dependencies[package] = '../$package'; | 671 dependencies[package] = '../$package'; |
764 } | 672 } |
765 } | 673 } |
766 | 674 |
767 if (pkg != null) { | 675 if (pkg != null) { |
768 _addPackage(String package) { | 676 _addPackage(String package) { |
769 if (dependencies.containsKey(package)) return; | 677 if (dependencies.containsKey(package)) return; |
770 | 678 |
771 var path; | 679 var path = packagePath(package); |
772 if (package == 'barback' && _packageOverrides == null) { | |
773 throw new StateError("createLockFile() can only create a lock file " | |
774 "with a barback dependency within a withBarbackVersions() " | |
775 "block."); | |
776 } | |
777 | |
778 if (_packageOverrides.containsKey(package)) { | |
779 path = _packageOverrides[package]; | |
780 } else { | |
781 path = packagePath(package); | |
782 } | |
783 | |
784 dependencies[package] = path; | 680 dependencies[package] = path; |
785 var pubspec = loadYaml( | 681 var pubspec = loadYaml( |
786 readTextFile(p.join(path, 'pubspec.yaml'))); | 682 readTextFile(p.join(path, 'pubspec.yaml'))); |
787 var packageDeps = pubspec['dependencies']; | 683 var packageDeps = pubspec['dependencies']; |
788 if (packageDeps == null) return; | 684 if (packageDeps == null) return; |
789 packageDeps.keys.forEach(_addPackage); | 685 packageDeps.keys.forEach(_addPackage); |
790 } | 686 } |
791 | 687 |
792 pkg.forEach(_addPackage); | 688 pkg.forEach(_addPackage); |
793 } | 689 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 _lastMatcher.matches(item.last, matchState); | 916 _lastMatcher.matches(item.last, matchState); |
1021 } | 917 } |
1022 | 918 |
1023 Description describe(Description description) { | 919 Description describe(Description description) { |
1024 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 920 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
1025 } | 921 } |
1026 } | 922 } |
1027 | 923 |
1028 /// A [StreamMatcher] that matches multiple lines of output. | 924 /// A [StreamMatcher] that matches multiple lines of output. |
1029 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 925 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |