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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if (error == null) { | 454 if (error == null) { |
455 future.handleException((ex) { | 455 future.handleException((ex) { |
456 print(ex); | 456 print(ex); |
457 print(future.stackTrace); | 457 print(future.stackTrace); |
458 return true; | 458 return true; |
459 }); | 459 }); |
460 } | 460 } |
461 }); | 461 }); |
462 } | 462 } |
463 | 463 |
464 /** | 464 /// A source used for testing. This both creates mock package objects and acts |
465 * A source used for testing. This both creates mock package objects and acts as | 465 /// as a source for them. |
466 * a source for them. | 466 /// |
467 * | 467 /// In order to support testing packages that have the same name but different |
468 * In order to support testing packages that have the same name but different | 468 /// descriptions, a package's name is calculated by taking the description |
469 * descriptions, a package's name is calculated by taking the description string | 469 /// string and stripping off any trailing hyphen followed by non-hyphen |
470 * and stripping off any trailing hyphen followed by non-hyphen characters. | 470 /// characters. |
471 */ | |
472 class MockSource extends Source { | 471 class MockSource extends Source { |
473 final Map<String, Map<Version, Package>> _packages; | 472 final Map<String, Map<Version, Package>> _packages; |
474 | 473 |
475 final String name; | 474 final String name; |
476 bool get shouldCache => true; | 475 bool get shouldCache => true; |
477 | 476 |
478 MockSource(this.name) | 477 MockSource(this.name) |
479 : _packages = <String, Map<Version, Package>>{}; | 478 : _packages = <String, Map<Version, Package>>{}; |
480 | 479 |
481 Future<List<Version>> getVersions(String name, String description) { | 480 Future<List<Version>> getVersions(String name, String description) { |
(...skipping 26 matching lines...) Expand all Loading... |
508 description, new Version.parse(version), dependencies); | 507 description, new Version.parse(version), dependencies); |
509 return new Package.inMemory(pubspec); | 508 return new Package.inMemory(pubspec); |
510 } | 509 } |
511 | 510 |
512 void addPackage(Package package) { | 511 void addPackage(Package package) { |
513 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); | 512 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); |
514 _packages[package.name][package.version] = package; | 513 _packages[package.name][package.version] = package; |
515 } | 514 } |
516 } | 515 } |
517 | 516 |
518 /** | 517 /// A source used for testing that doesn't natively understand versioning, |
519 * A source used for testing that doesn't natively understand versioning, | 518 /// similar to how the Git and SDK sources work. |
520 * similar to how the Git and SDK sources work. | |
521 */ | |
522 class MockVersionlessSource extends Source { | 519 class MockVersionlessSource extends Source { |
523 final Map<String, Package> _packages; | 520 final Map<String, Package> _packages; |
524 | 521 |
525 final String name = 'versionless'; | 522 final String name = 'versionless'; |
526 final bool shouldCache = false; | 523 final bool shouldCache = false; |
527 | 524 |
528 MockVersionlessSource() | 525 MockVersionlessSource() |
529 : _packages = <String, Package>{}; | 526 : _packages = <String, Package>{}; |
530 | 527 |
531 Future<bool> install(PackageId id, String path) { | 528 Future<bool> install(PackageId id, String path) { |
(...skipping 22 matching lines...) Expand all Loading... |
554 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); | 551 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); |
555 if (match == null) return new Pair<String, Source>(name, source1); | 552 if (match == null) return new Pair<String, Source>(name, source1); |
556 switch (match[2]) { | 553 switch (match[2]) { |
557 case 'mock1': return new Pair<String, Source>(match[1], source1); | 554 case 'mock1': return new Pair<String, Source>(match[1], source1); |
558 case 'mock2': return new Pair<String, Source>(match[1], source2); | 555 case 'mock2': return new Pair<String, Source>(match[1], source2); |
559 case 'root': return new Pair<String, Source>(match[1], rootSource); | 556 case 'root': return new Pair<String, Source>(match[1], rootSource); |
560 case 'versionless': | 557 case 'versionless': |
561 return new Pair<String, Source>(match[1], versionlessSource); | 558 return new Pair<String, Source>(match[1], versionlessSource); |
562 } | 559 } |
563 } | 560 } |
OLD | NEW |