OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library('pub_update_test'); | 5 #library('pub_update_test'); |
6 | 6 |
7 #import('dart:io'); | 7 #import('dart:io'); |
8 #import('dart:isolate'); | 8 #import('dart:isolate'); |
9 | 9 |
10 #import('../../pub/lock_file.dart'); | |
10 #import('../../pub/package.dart'); | 11 #import('../../pub/package.dart'); |
11 #import('../../pub/pubspec.dart'); | 12 #import('../../pub/pubspec.dart'); |
12 #import('../../pub/source.dart'); | 13 #import('../../pub/source.dart'); |
13 #import('../../pub/source_registry.dart'); | 14 #import('../../pub/source_registry.dart'); |
14 #import('../../pub/utils.dart'); | 15 #import('../../pub/utils.dart'); |
15 #import('../../pub/version.dart'); | 16 #import('../../pub/version.dart'); |
16 #import('../../pub/version_solver.dart'); | 17 #import('../../pub/version_solver.dart'); |
17 #import('../../../lib/unittest/unittest.dart'); | 18 #import('../../../lib/unittest/unittest.dart'); |
18 | 19 |
19 final noVersion = 'no version'; | 20 final noVersion = 'no version'; |
(...skipping 101 matching lines...) Loading... | |
121 'foo 1.2.3 from versionless': { | 122 'foo 1.2.3 from versionless': { |
122 'bar': '>=1.0.0' | 123 'bar': '>=1.0.0' |
123 }, | 124 }, |
124 'bar 1.1.0': {} | 125 'bar 1.1.0': {} |
125 }, result: { | 126 }, result: { |
126 'myapp': '0.0.0', | 127 'myapp': '0.0.0', |
127 'foo': '1.2.3', | 128 'foo': '1.2.3', |
128 'bar': '1.1.0' | 129 'bar': '1.1.0' |
129 }); | 130 }); |
130 | 131 |
132 testResolve('with compatible locked dependency', { | |
133 'myapp 0.0.0': { | |
134 'foo': 'any' | |
135 }, | |
136 'foo 1.0.0': { 'bar': '1.0.0' }, | |
137 'foo 1.0.1': { 'bar': '1.0.1' }, | |
138 'foo 1.0.2': { 'bar': '1.0.2' }, | |
139 'bar 1.0.0': {}, | |
140 'bar 1.0.1': {}, | |
141 'bar 1.0.2': {} | |
142 }, lockfile: { | |
143 'foo': '1.0.1' | |
144 }, result: { | |
145 'myapp': '0.0.0', | |
146 'foo': '1.0.1', | |
147 'bar': '1.0.1' | |
148 }); | |
149 | |
150 testResolve('with incompatible locked dependency', { | |
151 'myapp 0.0.0': { | |
152 'foo': '>1.0.1' | |
153 }, | |
154 'foo 1.0.0': { 'bar': '1.0.0' }, | |
155 'foo 1.0.1': { 'bar': '1.0.1' }, | |
156 'foo 1.0.2': { 'bar': '1.0.2' }, | |
157 'bar 1.0.0': {}, | |
158 'bar 1.0.1': {}, | |
159 'bar 1.0.2': {} | |
160 }, lockfile: { | |
161 'foo': '1.0.1' | |
162 }, result: { | |
163 'myapp': '0.0.0', | |
164 'foo': '1.0.2', | |
Jennifer Messerly
2012/07/19 18:45:34
so if the lockfile is incompatible, it just gets u
nweiz
2012/07/19 18:56:54
Yes. This should only happen when the user modifie
Jennifer Messerly
2012/07/19 19:06:30
Makes sense
| |
165 'bar': '1.0.2' | |
166 }); | |
167 | |
168 testResolve('with unrelated locked dependency', { | |
169 'myapp 0.0.0': { | |
170 'foo': 'any' | |
171 }, | |
172 'foo 1.0.0': { 'bar': '1.0.0' }, | |
173 'foo 1.0.1': { 'bar': '1.0.1' }, | |
174 'foo 1.0.2': { 'bar': '1.0.2' }, | |
175 'bar 1.0.0': {}, | |
176 'bar 1.0.1': {}, | |
177 'bar 1.0.2': {}, | |
178 'baz 1.0.0': {} | |
179 }, lockfile: { | |
180 'baz': '1.0.0' | |
181 }, result: { | |
182 'myapp': '0.0.0', | |
183 'foo': '1.0.2', | |
184 'bar': '1.0.2' | |
185 }); | |
186 | |
131 testResolve('dependency back onto root package', { | 187 testResolve('dependency back onto root package', { |
132 'myapp 1.0.0': { | 188 'myapp 1.0.0': { |
133 'foo': '1.0.0' | 189 'foo': '1.0.0' |
134 }, | 190 }, |
135 'foo 1.0.0': { | 191 'foo 1.0.0': { |
136 'myapp': '>=1.0.0' | 192 'myapp': '>=1.0.0' |
137 } | 193 } |
138 }, error: sourceMismatch); | 194 }, error: sourceMismatch); |
139 | 195 |
140 testResolve('no version that matches requirement', { | 196 testResolve('no version that matches requirement', { |
(...skipping 78 matching lines...) Loading... | |
219 }, error: couldNotSolve); | 275 }, error: couldNotSolve); |
220 | 276 |
221 // TODO(rnystrom): More stuff to test: | 277 // TODO(rnystrom): More stuff to test: |
222 // - Two packages depend on the same package, but from different sources. Should | 278 // - Two packages depend on the same package, but from different sources. Should |
223 // fail. | 279 // fail. |
224 // - Depending on a non-existent package. | 280 // - Depending on a non-existent package. |
225 // - Test that only a certain number requests are sent to the mock source so we | 281 // - Test that only a certain number requests are sent to the mock source so we |
226 // can keep track of server traffic. | 282 // can keep track of server traffic. |
227 } | 283 } |
228 | 284 |
229 testResolve(description, packages, [result, error]) { | 285 testResolve(description, packages, [lockfile, result, error]) { |
230 test(description, () { | 286 test(description, () { |
231 var sources = new SourceRegistry(); | 287 var sources = new SourceRegistry(); |
232 source1 = new MockSource('mock1'); | 288 source1 = new MockSource('mock1'); |
233 source2 = new MockSource('mock2'); | 289 source2 = new MockSource('mock2'); |
234 versionlessSource = new MockVersionlessSource(); | 290 versionlessSource = new MockVersionlessSource(); |
235 sources.register(source1); | 291 sources.register(source1); |
236 sources.register(source2); | 292 sources.register(source2); |
237 sources.register(versionlessSource); | 293 sources.register(versionlessSource); |
238 sources.setDefault(source1.name); | 294 sources.setDefault(source1.name); |
239 | 295 |
(...skipping 19 matching lines...) Loading... | |
259 } | 315 } |
260 }); | 316 }); |
261 | 317 |
262 // Clean up the expectation. | 318 // Clean up the expectation. |
263 if (result != null) { | 319 if (result != null) { |
264 result.forEach((name, version) { | 320 result.forEach((name, version) { |
265 result[name] = new Version.parse(version); | 321 result[name] = new Version.parse(version); |
266 }); | 322 }); |
267 } | 323 } |
268 | 324 |
325 var realLockFile = new LockFile.empty(); | |
326 if (lockfile != null) { | |
327 lockfile.forEach((name, version) { | |
328 version = new Version.parse(version); | |
329 realLockFile.packages[name] = new PackageId(source1, version, name); | |
330 }); | |
331 } | |
332 | |
269 // Resolve the versions. | 333 // Resolve the versions. |
270 var future = resolveVersions(sources, root); | 334 var future = resolveVersions(sources, root, realLockFile); |
271 | 335 |
272 if (result != null) { | 336 if (result != null) { |
273 expect(future, completion(predicate((actualResult) { | 337 expect(future, completion(predicate((actualResult) { |
274 for (var id in actualResult) { | 338 for (var id in actualResult) { |
275 if (!result.containsKey(id.description)) return false; | 339 if (!result.containsKey(id.description)) return false; |
276 if (id.version != result.remove(id.description)) return false; | 340 if (id.version != result.remove(id.description)) return false; |
277 } | 341 } |
278 return result.isEmpty(); | 342 return result.isEmpty(); |
279 }, description: 'packages to match $result'))); | 343 }, description: 'packages to match $result'))); |
280 } else if (error == noVersion) { | 344 } else if (error == noVersion) { |
(...skipping 113 matching lines...) Loading... | |
394 Pair<String, Source> parseSource(String name) { | 458 Pair<String, Source> parseSource(String name) { |
395 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); | 459 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); |
396 if (match == null) return new Pair<String, Source>(name, source1); | 460 if (match == null) return new Pair<String, Source>(name, source1); |
397 switch (match[2]) { | 461 switch (match[2]) { |
398 case 'mock1': return new Pair<String, Source>(match[1], source1); | 462 case 'mock1': return new Pair<String, Source>(match[1], source1); |
399 case 'mock2': return new Pair<String, Source>(match[1], source2); | 463 case 'mock2': return new Pair<String, Source>(match[1], source2); |
400 case 'versionless': | 464 case 'versionless': |
401 return new Pair<String, Source>(match[1], versionlessSource); | 465 return new Pair<String, Source>(match[1], versionlessSource); |
402 } | 466 } |
403 } | 467 } |
OLD | NEW |