| 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/lock_file.dart'); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (result != null) { | 319 if (result != null) { |
| 320 result.forEach((name, version) { | 320 result.forEach((name, version) { |
| 321 result[name] = new Version.parse(version); | 321 result[name] = new Version.parse(version); |
| 322 }); | 322 }); |
| 323 } | 323 } |
| 324 | 324 |
| 325 var realLockFile = new LockFile.empty(); | 325 var realLockFile = new LockFile.empty(); |
| 326 if (lockfile != null) { | 326 if (lockfile != null) { |
| 327 lockfile.forEach((name, version) { | 327 lockfile.forEach((name, version) { |
| 328 version = new Version.parse(version); | 328 version = new Version.parse(version); |
| 329 realLockFile.packages[name] = new PackageId(source1, version, name); | 329 realLockFile.packages[name] = |
| 330 new PackageId(name, source1, version, name); |
| 330 }); | 331 }); |
| 331 } | 332 } |
| 332 | 333 |
| 333 // Resolve the versions. | 334 // Resolve the versions. |
| 334 var future = resolveVersions(sources, root, realLockFile); | 335 var future = resolveVersions(sources, root, realLockFile); |
| 335 | 336 |
| 336 if (result != null) { | 337 if (result != null) { |
| 337 expect(future, completion(predicate((actualResult) { | 338 expect(future, completion(predicate((actualResult) { |
| 338 for (var id in actualResult) { | 339 for (var id in actualResult) { |
| 339 if (!result.containsKey(id.description)) return false; | 340 if (!result.containsKey(id.description)) return false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 */ | 377 */ |
| 377 class MockSource extends Source { | 378 class MockSource extends Source { |
| 378 final Map<String, Map<Version, Package>> _packages; | 379 final Map<String, Map<Version, Package>> _packages; |
| 379 | 380 |
| 380 final String name; | 381 final String name; |
| 381 bool get shouldCache => true; | 382 bool get shouldCache => true; |
| 382 | 383 |
| 383 MockSource(this.name) | 384 MockSource(this.name) |
| 384 : _packages = <String, Map<Version, Package>>{}; | 385 : _packages = <String, Map<Version, Package>>{}; |
| 385 | 386 |
| 386 Future<List<Version>> getVersions(String name) { | 387 Future<List<Version>> getVersions(String name, String description) { |
| 387 return fakeAsync(() => _packages[name].getKeys()); | 388 return fakeAsync(() => _packages[description].getKeys()); |
| 388 } | 389 } |
| 389 | 390 |
| 390 Future<Pubspec> describe(PackageId id) { | 391 Future<Pubspec> describe(PackageId id) { |
| 391 return fakeAsync(() { | 392 return fakeAsync(() { |
| 392 return _packages[id.name][id.version].pubspec; | 393 return _packages[id.name][id.version].pubspec; |
| 393 }); | 394 }); |
| 394 } | 395 } |
| 395 | 396 |
| 396 Future<bool> install(PackageId id, String path) { | 397 Future<bool> install(PackageId id, String path) { |
| 397 throw 'no'; | 398 throw 'no'; |
| 398 } | 399 } |
| 399 | 400 |
| 400 Package mockPackage(String description, String version, | 401 Package mockPackage(String description, String version, |
| 401 Map dependencyStrings) { | 402 Map dependencyStrings) { |
| 402 // Build the pubspec dependencies. | 403 // Build the pubspec dependencies. |
| 403 var dependencies = <PackageRef>[]; | 404 var dependencies = <PackageRef>[]; |
| 404 dependencyStrings.forEach((name, constraint) { | 405 dependencyStrings.forEach((name, constraint) { |
| 405 var parsed = parseSource(name); | 406 var parsed = parseSource(name); |
| 406 dependencies.add(new PackageRef( | 407 var description = parsed.first; |
| 407 parsed.last, new VersionConstraint.parse(constraint), parsed.first)); | 408 var packageName = description.replaceFirst(new RegExp(@"-[^-]+$"), ""); |
| 409 dependencies.add(new PackageRef(packageName, parsed.last, |
| 410 new VersionConstraint.parse(constraint), description)); |
| 408 }); | 411 }); |
| 409 | 412 |
| 410 var pubspec = new Pubspec( | 413 var pubspec = new Pubspec( |
| 411 description, new Version.parse(version), dependencies); | 414 description, new Version.parse(version), dependencies); |
| 412 return new Package.inMemory(pubspec); | 415 return new Package.inMemory(pubspec); |
| 413 } | 416 } |
| 414 | 417 |
| 415 void addPackage(Package package) { | 418 void addPackage(Package package) { |
| 416 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); | 419 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); |
| 417 _packages[package.name][package.version] = package; | 420 _packages[package.name][package.version] = package; |
| 418 } | 421 } |
| 419 | |
| 420 String packageName(String description) => | |
| 421 description.replaceFirst(new RegExp(@"-[^-]+$"), ""); | |
| 422 } | 422 } |
| 423 | 423 |
| 424 /** | 424 /** |
| 425 * A source used for testing that doesn't natively understand versioning, | 425 * A source used for testing that doesn't natively understand versioning, |
| 426 * similar to how the Git and SDK sources work. | 426 * similar to how the Git and SDK sources work. |
| 427 */ | 427 */ |
| 428 class MockVersionlessSource extends Source { | 428 class MockVersionlessSource extends Source { |
| 429 final Map<String, Package> _packages; | 429 final Map<String, Package> _packages; |
| 430 | 430 |
| 431 final String name = 'versionless'; | 431 final String name = 'versionless'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 459 Pair<String, Source> parseSource(String name) { | 459 Pair<String, Source> parseSource(String name) { |
| 460 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); | 460 var match = new RegExp(@"(.*) from (.*)").firstMatch(name); |
| 461 if (match == null) return new Pair<String, Source>(name, source1); | 461 if (match == null) return new Pair<String, Source>(name, source1); |
| 462 switch (match[2]) { | 462 switch (match[2]) { |
| 463 case 'mock1': return new Pair<String, Source>(match[1], source1); | 463 case 'mock1': return new Pair<String, Source>(match[1], source1); |
| 464 case 'mock2': return new Pair<String, Source>(match[1], source2); | 464 case 'mock2': return new Pair<String, Source>(match[1], source2); |
| 465 case 'versionless': | 465 case 'versionless': |
| 466 return new Pair<String, Source>(match[1], versionlessSource); | 466 return new Pair<String, Source>(match[1], versionlessSource); |
| 467 } | 467 } |
| 468 } | 468 } |
| OLD | NEW |