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'); | |
11 #import('../../pub/package.dart'); | 10 #import('../../pub/package.dart'); |
12 #import('../../pub/pubspec.dart'); | 11 #import('../../pub/pubspec.dart'); |
13 #import('../../pub/source.dart'); | 12 #import('../../pub/source.dart'); |
14 #import('../../pub/source_registry.dart'); | 13 #import('../../pub/source_registry.dart'); |
15 #import('../../pub/utils.dart'); | 14 #import('../../pub/utils.dart'); |
16 #import('../../pub/version.dart'); | 15 #import('../../pub/version.dart'); |
17 #import('../../pub/version_solver.dart'); | 16 #import('../../pub/version_solver.dart'); |
18 #import('../../../lib/unittest/unittest.dart'); | 17 #import('../../../lib/unittest/unittest.dart'); |
19 | 18 |
20 final noVersion = 'no version'; | 19 final noVersion = 'no version'; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 'foo 1.2.3 from versionless': { | 121 'foo 1.2.3 from versionless': { |
123 'bar': '>=1.0.0' | 122 'bar': '>=1.0.0' |
124 }, | 123 }, |
125 'bar 1.1.0': {} | 124 'bar 1.1.0': {} |
126 }, result: { | 125 }, result: { |
127 'myapp': '0.0.0', | 126 'myapp': '0.0.0', |
128 'foo': '1.2.3', | 127 'foo': '1.2.3', |
129 'bar': '1.1.0' | 128 'bar': '1.1.0' |
130 }); | 129 }); |
131 | 130 |
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', | |
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 | |
187 testResolve('dependency back onto root package', { | 131 testResolve('dependency back onto root package', { |
188 'myapp 1.0.0': { | 132 'myapp 1.0.0': { |
189 'foo': '1.0.0' | 133 'foo': '1.0.0' |
190 }, | 134 }, |
191 'foo 1.0.0': { | 135 'foo 1.0.0': { |
192 'myapp': '>=1.0.0' | 136 'myapp': '>=1.0.0' |
193 } | 137 } |
194 }, error: sourceMismatch); | 138 }, error: sourceMismatch); |
195 | 139 |
196 testResolve('no version that matches requirement', { | 140 testResolve('no version that matches requirement', { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 }, error: couldNotSolve); | 219 }, error: couldNotSolve); |
276 | 220 |
277 // TODO(rnystrom): More stuff to test: | 221 // TODO(rnystrom): More stuff to test: |
278 // - Two packages depend on the same package, but from different sources. Should | 222 // - Two packages depend on the same package, but from different sources. Should |
279 // fail. | 223 // fail. |
280 // - Depending on a non-existent package. | 224 // - Depending on a non-existent package. |
281 // - Test that only a certain number requests are sent to the mock source so we | 225 // - Test that only a certain number requests are sent to the mock source so we |
282 // can keep track of server traffic. | 226 // can keep track of server traffic. |
283 } | 227 } |
284 | 228 |
285 testResolve(description, packages, [lockfile, result, error]) { | 229 testResolve(description, packages, [result, error]) { |
286 test(description, () { | 230 test(description, () { |
287 var sources = new SourceRegistry(); | 231 var sources = new SourceRegistry(); |
288 source1 = new MockSource('mock1'); | 232 source1 = new MockSource('mock1'); |
289 source2 = new MockSource('mock2'); | 233 source2 = new MockSource('mock2'); |
290 versionlessSource = new MockVersionlessSource(); | 234 versionlessSource = new MockVersionlessSource(); |
291 sources.register(source1); | 235 sources.register(source1); |
292 sources.register(source2); | 236 sources.register(source2); |
293 sources.register(versionlessSource); | 237 sources.register(versionlessSource); |
294 sources.setDefault(source1.name); | 238 sources.setDefault(source1.name); |
295 | 239 |
(...skipping 19 matching lines...) Expand all Loading... |
315 } | 259 } |
316 }); | 260 }); |
317 | 261 |
318 // Clean up the expectation. | 262 // Clean up the expectation. |
319 if (result != null) { | 263 if (result != null) { |
320 result.forEach((name, version) { | 264 result.forEach((name, version) { |
321 result[name] = new Version.parse(version); | 265 result[name] = new Version.parse(version); |
322 }); | 266 }); |
323 } | 267 } |
324 | 268 |
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 | |
333 // Resolve the versions. | 269 // Resolve the versions. |
334 var future = resolveVersions(sources, root, realLockFile); | 270 var future = resolveVersions(sources, root); |
335 | 271 |
336 if (result != null) { | 272 if (result != null) { |
337 expect(future, completion(predicate((actualResult) { | 273 expect(future, completion(predicate((actualResult) { |
338 for (var id in actualResult) { | 274 for (var id in actualResult) { |
339 if (!result.containsKey(id.description)) return false; | 275 if (!result.containsKey(id.description)) return false; |
340 if (id.version != result.remove(id.description)) return false; | 276 if (id.version != result.remove(id.description)) return false; |
341 } | 277 } |
342 return result.isEmpty(); | 278 return result.isEmpty(); |
343 }, description: 'packages to match $result'))); | 279 }, description: 'packages to match $result'))); |
344 } else if (error == noVersion) { | 280 } else if (error == noVersion) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 Pair<String, Source> parseSource(String name) { | 394 Pair<String, Source> parseSource(String name) { |
459 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); | 395 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); |
460 if (match == null) return new Pair<String, Source>(name, source1); | 396 if (match == null) return new Pair<String, Source>(name, source1); |
461 switch (match[2]) { | 397 switch (match[2]) { |
462 case 'mock1': return new Pair<String, Source>(match[1], source1); | 398 case 'mock1': return new Pair<String, Source>(match[1], source1); |
463 case 'mock2': return new Pair<String, Source>(match[1], source2); | 399 case 'mock2': return new Pair<String, Source>(match[1], source2); |
464 case 'versionless': | 400 case 'versionless': |
465 return new Pair<String, Source>(match[1], versionlessSource); | 401 return new Pair<String, Source>(match[1], versionlessSource); |
466 } | 402 } |
467 } | 403 } |
OLD | NEW |