| 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:async'; |
| 7 import 'dart:io'; | 8 import 'dart:io'; |
| 8 import 'dart:isolate'; | |
| 9 | 9 |
| 10 import '../../pub/lock_file.dart'; | 10 import '../../pub/lock_file.dart'; |
| 11 import '../../pub/package.dart'; | 11 import '../../pub/package.dart'; |
| 12 import '../../pub/pubspec.dart'; | 12 import '../../pub/pubspec.dart'; |
| 13 import '../../pub/root_source.dart'; | 13 import '../../pub/root_source.dart'; |
| 14 import '../../pub/source.dart'; | 14 import '../../pub/source.dart'; |
| 15 import '../../pub/source_registry.dart'; | 15 import '../../pub/source_registry.dart'; |
| 16 import '../../pub/system_cache.dart'; | 16 import '../../pub/system_cache.dart'; |
| 17 import '../../pub/utils.dart'; | 17 import '../../pub/utils.dart'; |
| 18 import '../../pub/version.dart'; | 18 import '../../pub/version.dart'; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 if (actualId != expectedId) return false; | 445 if (actualId != expectedId) return false; |
| 446 } | 446 } |
| 447 return result.isEmpty; | 447 return result.isEmpty; |
| 448 }, 'packages to match $result'))); | 448 }, 'packages to match $result'))); |
| 449 } else if (error != null) { | 449 } else if (error != null) { |
| 450 expect(future, throwsA(error)); | 450 expect(future, throwsA(error)); |
| 451 } | 451 } |
| 452 | 452 |
| 453 // If we aren't expecting an error, print some debugging info if we get one. | 453 // If we aren't expecting an error, print some debugging info if we get one. |
| 454 if (error == null) { | 454 if (error == null) { |
| 455 future.handleException((ex) { | 455 future.catchError((ex) { |
| 456 print(ex); | 456 print(ex); |
| 457 print(future.stackTrace); | 457 print(future.stackTrace); |
| 458 return true; | |
| 459 }); | 458 }); |
| 460 } | 459 } |
| 461 }); | 460 }); |
| 462 } | 461 } |
| 463 | 462 |
| 464 /// A source used for testing. This both creates mock package objects and acts | 463 /// A source used for testing. This both creates mock package objects and acts |
| 465 /// as a source for them. | 464 /// as a source for them. |
| 466 /// | 465 /// |
| 467 /// In order to support testing packages that have the same name but different | 466 /// 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 | 467 /// descriptions, a package's name is calculated by taking the description |
| 469 /// string and stripping off any trailing hyphen followed by non-hyphen | 468 /// string and stripping off any trailing hyphen followed by non-hyphen |
| 470 /// characters. | 469 /// characters. |
| 471 class MockSource extends Source { | 470 class MockSource extends Source { |
| 472 final Map<String, Map<Version, Package>> _packages; | 471 final Map<String, Map<Version, Package>> _packages; |
| 473 | 472 |
| 474 final String name; | 473 final String name; |
| 475 bool get shouldCache => true; | 474 bool get shouldCache => true; |
| 476 | 475 |
| 477 MockSource(this.name) | 476 MockSource(this.name) |
| 478 : _packages = <String, Map<Version, Package>>{}; | 477 : _packages = <String, Map<Version, Package>>{}; |
| 479 | 478 |
| 480 Future<List<Version>> getVersions(String name, String description) { | 479 Future<List<Version>> getVersions(String name, String description) { |
| 481 return fakeAsync(() => _packages[description].keys); | 480 return fakeAsync(() => _packages[description].keys.toList()); |
| 482 } | 481 } |
| 483 | 482 |
| 484 Future<Pubspec> describe(PackageId id) { | 483 Future<Pubspec> describe(PackageId id) { |
| 485 return fakeAsync(() { | 484 return fakeAsync(() { |
| 486 return _packages[id.name][id.version].pubspec; | 485 return _packages[id.name][id.version].pubspec; |
| 487 }); | 486 }); |
| 488 } | 487 } |
| 489 | 488 |
| 490 Future<bool> install(PackageId id, String path) { | 489 Future<bool> install(PackageId id, String path) { |
| 491 throw 'no'; | 490 throw 'no'; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); | 550 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); |
| 552 if (match == null) return new Pair<String, Source>(name, source1); | 551 if (match == null) return new Pair<String, Source>(name, source1); |
| 553 switch (match[2]) { | 552 switch (match[2]) { |
| 554 case 'mock1': return new Pair<String, Source>(match[1], source1); | 553 case 'mock1': return new Pair<String, Source>(match[1], source1); |
| 555 case 'mock2': return new Pair<String, Source>(match[1], source2); | 554 case 'mock2': return new Pair<String, Source>(match[1], source2); |
| 556 case 'root': return new Pair<String, Source>(match[1], rootSource); | 555 case 'root': return new Pair<String, Source>(match[1], rootSource); |
| 557 case 'versionless': | 556 case 'versionless': |
| 558 return new Pair<String, Source>(match[1], versionlessSource); | 557 return new Pair<String, Source>(match[1], versionlessSource); |
| 559 } | 558 } |
| 560 } | 559 } |
| OLD | NEW |