Chromium Code Reviews| 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/package.dart'); | 10 #import('../../pub/package.dart'); |
| 11 #import('../../pub/pubspec.dart'); | 11 #import('../../pub/pubspec.dart'); |
| 12 #import('../../pub/source.dart'); | 12 #import('../../pub/source.dart'); |
| 13 #import('../../pub/source_registry.dart'); | 13 #import('../../pub/source_registry.dart'); |
| 14 #import('../../pub/utils.dart'); | 14 #import('../../pub/utils.dart'); |
| 15 #import('../../pub/version.dart'); | 15 #import('../../pub/version.dart'); |
| 16 #import('../../pub/version_solver.dart'); | 16 #import('../../pub/version_solver.dart'); |
| 17 #import('../../../lib/unittest/unittest.dart'); | 17 #import('../../../lib/unittest/unittest.dart'); |
| 18 | 18 |
| 19 final noVersion = 'no version'; | 19 final noVersion = 'no version'; |
| 20 final disjointConstraint = 'disjoint'; | 20 final disjointConstraint = 'disjoint'; |
| 21 final sourceMismatch = 'source mismatch'; | 21 final sourceMismatch = 'source mismatch'; |
| 22 final descriptionMismatch = 'description mismatch'; | 22 final descriptionMismatch = 'description mismatch'; |
| 23 final couldNotSolve = 'unsolved'; | 23 final couldNotSolve = 'unsolved'; |
| 24 | 24 |
| 25 Source source1; | 25 Source source1; |
| 26 Source source2; | 26 Source source2; |
| 27 Source versionlessSource; | |
| 27 | 28 |
| 28 main() { | 29 main() { |
| 29 testResolve('no dependencies', { | 30 testResolve('no dependencies', { |
| 30 'myapp 0.0.0': {} | 31 'myapp 0.0.0': {} |
| 31 }, result: { | 32 }, result: { |
| 32 'myapp': '0.0.0' | 33 'myapp': '0.0.0' |
| 33 }); | 34 }); |
| 34 | 35 |
| 35 testResolve('simple dependency tree', { | 36 testResolve('simple dependency tree', { |
| 36 'myapp 0.0.0': { | 37 'myapp 0.0.0': { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 'bang 1.0.0': {}, | 97 'bang 1.0.0': {}, |
| 97 'whoop 1.0.0': {}, | 98 'whoop 1.0.0': {}, |
| 98 'zoop 1.0.0': {} | 99 'zoop 1.0.0': {} |
| 99 }, result: { | 100 }, result: { |
| 100 'myapp': '0.0.0', | 101 'myapp': '0.0.0', |
| 101 'foo': '1.0.1', | 102 'foo': '1.0.1', |
| 102 'bar': '1.0.0', | 103 'bar': '1.0.0', |
| 103 'bang': '1.0.0' | 104 'bang': '1.0.0' |
| 104 }); | 105 }); |
| 105 | 106 |
| 107 testResolve('from versionless source', { | |
| 108 'myapp 0.0.0': { | |
| 109 'foo from versionless': 'any' | |
| 110 }, | |
| 111 'foo 1.2.3 from versionless': {} | |
| 112 }, result: { | |
| 113 'myapp': '0.0.0', | |
| 114 'foo': '1.2.3' | |
| 115 }); | |
| 116 | |
| 117 testResolve('transitively through versionless source', { | |
| 118 'myapp 0.0.0': { | |
| 119 'foo from versionless': 'any' | |
| 120 }, | |
| 121 'foo 1.2.3 from versionless': { 'bar': '>=1.0.0' }, | |
|
Bob Nystrom
2012/07/11 16:55:13
Can you split this map onto the next line like the
nweiz
2012/07/11 19:11:37
Done.
| |
| 122 'bar 1.1.0': {} | |
| 123 }, result: { | |
| 124 'myapp': '0.0.0', | |
| 125 'foo': '1.2.3', | |
| 126 'bar': '1.1.0' | |
| 127 }); | |
| 128 | |
| 106 testResolve('dependency back onto root package', { | 129 testResolve('dependency back onto root package', { |
| 107 'myapp 1.0.0': { | 130 'myapp 1.0.0': { |
| 108 'foo': '1.0.0' | 131 'foo': '1.0.0' |
| 109 }, | 132 }, |
| 110 'foo 1.0.0': { | 133 'foo 1.0.0': { |
| 111 'myapp': '>=1.0.0' | 134 'myapp': '>=1.0.0' |
| 112 } | 135 } |
| 113 }, error: sourceMismatch); | 136 }, error: sourceMismatch); |
| 114 | 137 |
| 115 testResolve('no version that matches requirement', { | 138 testResolve('no version that matches requirement', { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // - Depending on a non-existent package. | 222 // - Depending on a non-existent package. |
| 200 // - Test that only a certain number requests are sent to the mock source so we | 223 // - Test that only a certain number requests are sent to the mock source so we |
| 201 // can keep track of server traffic. | 224 // can keep track of server traffic. |
| 202 } | 225 } |
| 203 | 226 |
| 204 testResolve(description, packages, [result, error]) { | 227 testResolve(description, packages, [result, error]) { |
| 205 test(description, () { | 228 test(description, () { |
| 206 var sources = new SourceRegistry(); | 229 var sources = new SourceRegistry(); |
| 207 source1 = new MockSource('mock1'); | 230 source1 = new MockSource('mock1'); |
| 208 source2 = new MockSource('mock2'); | 231 source2 = new MockSource('mock2'); |
| 232 versionlessSource = new MockVersionlessSource(); | |
| 209 sources.register(source1); | 233 sources.register(source1); |
| 210 sources.register(source2); | 234 sources.register(source2); |
| 235 sources.register(versionlessSource); | |
| 211 sources.setDefault(source1.name); | 236 sources.setDefault(source1.name); |
| 212 | 237 |
| 213 // Build the test package graph. | 238 // Build the test package graph. |
| 214 var root; | 239 var root; |
| 215 packages.forEach((nameVersion, dependencies) { | 240 packages.forEach((nameVersion, dependencies) { |
| 216 var parsed = parseSource(nameVersion); | 241 var parsed = parseSource(nameVersion); |
| 217 nameVersion = parsed.first; | 242 nameVersion = parsed.first; |
| 218 var source = parsed.last; | 243 var source = parsed.last; |
| 219 | 244 |
| 220 var parts = nameVersion.split(' '); | 245 var parts = nameVersion.split(' '); |
| 221 var name = parts[0]; | 246 var name = parts[0]; |
| 222 var version = parts[1]; | 247 var version = parts[1]; |
| 223 | 248 |
| 224 var package = source.mockPackage(name, version, dependencies); | 249 var package = source1.mockPackage(name, version, dependencies); |
| 225 if (name == 'myapp') { | 250 if (name == 'myapp') { |
| 226 // Don't add the root package to the server, so we can verify that Pub | 251 // Don't add the root package to the server, so we can verify that Pub |
| 227 // doesn't try to look up information about the local package on the | 252 // doesn't try to look up information about the local package on the |
| 228 // remote server. | 253 // remote server. |
| 229 root = package; | 254 root = package; |
| 230 } else { | 255 } else { |
| 231 source.addPackage(package); | 256 source.addPackage(package); |
| 232 } | 257 } |
| 233 }); | 258 }); |
| 234 | 259 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 parsed.last, new VersionConstraint.parse(constraint), parsed.first)); | 335 parsed.last, new VersionConstraint.parse(constraint), parsed.first)); |
| 311 }); | 336 }); |
| 312 | 337 |
| 313 var pubspec = new Pubspec(new Version.parse(version), dependencies); | 338 var pubspec = new Pubspec(new Version.parse(version), dependencies); |
| 314 return new Package.inMemory(description, pubspec); | 339 return new Package.inMemory(description, pubspec); |
| 315 } | 340 } |
| 316 | 341 |
| 317 void addPackage(Package package) { | 342 void addPackage(Package package) { |
| 318 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); | 343 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); |
| 319 _packages[package.name][package.version] = package; | 344 _packages[package.name][package.version] = package; |
| 320 return package; | |
| 321 } | 345 } |
| 322 | 346 |
| 323 String packageName(String description) => | 347 String packageName(String description) => |
| 324 description.replaceFirst(new RegExp(@"-[^-]+$"), ""); | 348 description.replaceFirst(new RegExp(@"-[^-]+$"), ""); |
| 325 } | 349 } |
| 326 | 350 |
| 351 /** | |
| 352 * A source used for testing that doesn't natively understand versioning, | |
| 353 * similar to how the Git and SDK sources work. | |
| 354 */ | |
| 355 class MockVersionlessSource extends Source { | |
| 356 final Map<String, Package> _packages; | |
| 357 | |
| 358 final String name = 'versionless'; | |
| 359 final bool shouldCache = false; | |
| 360 | |
| 361 MockVersionlessSource() | |
| 362 : _packages = <Package>{}; | |
| 363 | |
| 364 Future<bool> install(PackageId id, String path) { | |
| 365 throw 'no'; | |
| 366 } | |
| 367 | |
| 368 Future<Pubspec> describe(PackageId id) { | |
| 369 return new Future<Pubspec>.immediate(_packages[id.description].pubspec); | |
| 370 } | |
| 371 | |
| 372 void addPackage(Package package) { | |
| 373 _packages[package.name] = package; | |
| 374 } | |
| 375 } | |
| 376 | |
| 327 Future fakeAsync(callback()) { | 377 Future fakeAsync(callback()) { |
| 328 var completer = new Completer(); | 378 var completer = new Completer(); |
| 329 new Timer(0, (_) { | 379 new Timer(0, (_) { |
| 330 completer.complete(callback()); | 380 completer.complete(callback()); |
| 331 }); | 381 }); |
| 332 | 382 |
| 333 return completer.future; | 383 return completer.future; |
| 334 } | 384 } |
| 335 | 385 |
| 336 Pair<String, Source> parseSource(String name) { | 386 Pair<String, Source> parseSource(String name) { |
| 337 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); | 387 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); |
| 338 if (match == null) return new Pair<String, Source>(name, source1); | 388 if (match == null) return new Pair<String, Source>(name, source1); |
| 339 switch (match[2]) { | 389 switch (match[2]) { |
| 340 case 'mock1': return new Pair<String, Source>(match[1], source1); | 390 case 'mock1': return new Pair<String, Source>(match[1], source1); |
| 341 case 'mock2': return new Pair<String, Source>(match[1], source2); | 391 case 'mock2': return new Pair<String, Source>(match[1], source2); |
| 392 case 'versionless': | |
| 393 return new Pair<String, Source>(match[1], versionlessSource); | |
| 342 } | 394 } |
| 343 } | 395 } |
| OLD | NEW |