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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import '../../../pkg/unittest/lib/unittest.dart'; | 10 import '../../../pkg/unittest/lib/unittest.dart'; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // Make sure the error string mentions the conflicting dependers. | 62 // Make sure the error string mentions the conflicting dependers. |
| 63 if (!x.toString().contains(package1)) return false; | 63 if (!x.toString().contains(package1)) return false; |
| 64 if (!x.toString().contains(package2)) return false; | 64 if (!x.toString().contains(package2)) return false; |
| 65 | 65 |
| 66 return true; | 66 return true; |
| 67 }, "is a SourceMismatchException"); | 67 }, "is a SourceMismatchException"); |
| 68 } | 68 } |
| 69 | 69 |
| 70 MockSource source1; | 70 MockSource source1; |
| 71 MockSource source2; | 71 MockSource source2; |
| 72 Source versionlessSource; | |
| 73 | 72 |
| 74 main() { | 73 main() { |
| 75 initConfig(); | 74 initConfig(); |
| 76 | 75 |
| 77 testResolve('no dependencies', { | 76 testResolve('no dependencies', { |
| 78 'myapp 0.0.0': {} | 77 'myapp 0.0.0': {} |
| 79 }, result: { | 78 }, result: { |
| 80 'myapp from root': '0.0.0' | 79 'myapp from root': '0.0.0' |
| 81 }); | 80 }); |
| 82 | 81 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 'bang 1.0.0': {}, | 143 'bang 1.0.0': {}, |
| 145 'whoop 1.0.0': {}, | 144 'whoop 1.0.0': {}, |
| 146 'zoop 1.0.0': {} | 145 'zoop 1.0.0': {} |
| 147 }, result: { | 146 }, result: { |
| 148 'myapp from root': '0.0.0', | 147 'myapp from root': '0.0.0', |
| 149 'foo': '1.0.1', | 148 'foo': '1.0.1', |
| 150 'bar': '1.0.0', | 149 'bar': '1.0.0', |
| 151 'bang': '1.0.0' | 150 'bang': '1.0.0' |
| 152 }); | 151 }); |
| 153 | 152 |
| 154 testResolve('from versionless source', { | |
| 155 'myapp 0.0.0': { | |
| 156 'foo from versionless': 'any' | |
| 157 }, | |
| 158 'foo 1.2.3 from versionless': {} | |
| 159 }, result: { | |
| 160 'myapp from root': '0.0.0', | |
| 161 'foo from versionless': '1.2.3' | |
| 162 }); | |
| 163 | |
| 164 testResolve('transitively through versionless source', { | |
| 165 'myapp 0.0.0': { | |
| 166 'foo from versionless': 'any' | |
| 167 }, | |
| 168 'foo 1.2.3 from versionless': { | |
| 169 'bar': '>=1.0.0' | |
| 170 }, | |
| 171 'bar 1.1.0': {} | |
| 172 }, result: { | |
| 173 'myapp from root': '0.0.0', | |
| 174 'foo from versionless': '1.2.3', | |
| 175 'bar': '1.1.0' | |
| 176 }); | |
| 177 | |
| 178 testResolve('with compatible locked dependency', { | 153 testResolve('with compatible locked dependency', { |
| 179 'myapp 0.0.0': { | 154 'myapp 0.0.0': { |
| 180 'foo': 'any' | 155 'foo': 'any' |
| 181 }, | 156 }, |
| 182 'foo 1.0.0': { 'bar': '1.0.0' }, | 157 'foo 1.0.0': { 'bar': '1.0.0' }, |
| 183 'foo 1.0.1': { 'bar': '1.0.1' }, | 158 'foo 1.0.1': { 'bar': '1.0.1' }, |
| 184 'foo 1.0.2': { 'bar': '1.0.2' }, | 159 'foo 1.0.2': { 'bar': '1.0.2' }, |
| 185 'bar 1.0.0': {}, | 160 'bar 1.0.0': {}, |
| 186 'bar 1.0.1': {}, | 161 'bar 1.0.1': {}, |
| 187 'bar 1.0.2': {} | 162 'bar 1.0.2': {} |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 // TODO(rnystrom): More stuff to test: | 394 // TODO(rnystrom): More stuff to test: |
| 420 // - Depending on a non-existent package. | 395 // - Depending on a non-existent package. |
| 421 // - Test that only a certain number requests are sent to the mock source so we | 396 // - Test that only a certain number requests are sent to the mock source so we |
| 422 // can keep track of server traffic. | 397 // can keep track of server traffic. |
| 423 | 398 |
| 424 testResolve(description, packages, {lockfile, result, Matcher error}) { | 399 testResolve(description, packages, {lockfile, result, Matcher error}) { |
| 425 test(description, () { | 400 test(description, () { |
| 426 var cache = new SystemCache('.'); | 401 var cache = new SystemCache('.'); |
| 427 source1 = new MockSource('mock1'); | 402 source1 = new MockSource('mock1'); |
| 428 source2 = new MockSource('mock2'); | 403 source2 = new MockSource('mock2'); |
| 429 versionlessSource = new MockVersionlessSource(); | |
| 430 cache.register(source1); | 404 cache.register(source1); |
| 431 cache.register(source2); | 405 cache.register(source2); |
| 432 cache.register(versionlessSource); | |
| 433 cache.sources.setDefault(source1.name); | 406 cache.sources.setDefault(source1.name); |
| 434 | 407 |
| 435 // Build the test package graph. | 408 // Build the test package graph. |
| 436 var root; | 409 var root; |
| 437 packages.forEach((nameVersion, dependencies) { | 410 packages.forEach((nameVersion, dependencies) { |
| 438 var parsed = parseSource(nameVersion, (isDev, nameVersion, source) { | 411 var parsed = parseSource(nameVersion, (isDev, nameVersion, source) { |
| 439 var parts = nameVersion.split(' '); | 412 var parts = nameVersion.split(' '); |
| 440 var name = parts[0]; | 413 var name = parts[0]; |
| 441 var version = parts[1]; | 414 var version = parts[1]; |
| 442 | 415 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 new PubspecEnvironment()); | 519 new PubspecEnvironment()); |
| 547 return new Package.inMemory(pubspec); | 520 return new Package.inMemory(pubspec); |
| 548 } | 521 } |
| 549 | 522 |
| 550 void addPackage(Package package) { | 523 void addPackage(Package package) { |
| 551 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); | 524 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); |
| 552 _packages[package.name][package.version] = package; | 525 _packages[package.name][package.version] = package; |
| 553 } | 526 } |
| 554 } | 527 } |
| 555 | 528 |
| 556 /// A source used for testing that doesn't natively understand versioning, | |
| 557 /// similar to how the Git and SDK sources work. | |
| 558 class MockVersionlessSource extends Source { | |
| 559 final Map<String, Package> _packages; | |
| 560 | |
| 561 final String name = 'versionless'; | |
| 562 final bool shouldCache = false; | |
| 563 | |
| 564 MockVersionlessSource() | |
| 565 : _packages = <String, Package>{}; | |
| 566 | |
| 567 Future<bool> install(PackageId id, String path) { | |
| 568 throw 'no'; | |
| 569 } | |
| 570 | |
| 571 Future<Pubspec> describe(PackageId id) { | |
| 572 return new Future<Pubspec>.immediate(_packages[id.description].pubspec); | |
| 573 } | |
| 574 | |
| 575 void addPackage(Package package) { | |
| 576 _packages[package.name] = package; | |
| 577 } | |
| 578 } | |
|
nweiz
2013/03/15 18:21:54
I don't understand why we're getting rid of this.
Bob Nystrom
2013/03/15 18:31:56
Per our discussion, I don't think these test anyth
| |
| 579 | |
| 580 void parseSource(String description, | 529 void parseSource(String description, |
| 581 callback(bool isDev, String name, Source source)) { | 530 callback(bool isDev, String name, Source source)) { |
| 582 var isDev = false; | 531 var isDev = false; |
| 583 | 532 |
| 584 if (description.startsWith("(dev) ")) { | 533 if (description.startsWith("(dev) ")) { |
| 585 description = description.substring("(dev) ".length); | 534 description = description.substring("(dev) ".length); |
| 586 isDev = true; | 535 isDev = true; |
| 587 } | 536 } |
| 588 | 537 |
| 589 var name = description; | 538 var name = description; |
| 590 var source = source1; | 539 var source = source1; |
| 591 | 540 |
| 592 var sourceNames = { | 541 var sourceNames = { |
| 593 'mock1': source1, | 542 'mock1': source1, |
| 594 'mock2': source2, | 543 'mock2': source2, |
| 595 'root': null, | 544 'root': null |
| 596 'versionless': versionlessSource | |
| 597 }; | 545 }; |
| 598 | 546 |
| 599 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); | 547 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); |
| 600 if (match != null) { | 548 if (match != null) { |
| 601 name = match[1]; | 549 name = match[1]; |
| 602 source = sourceNames[match[2]]; | 550 source = sourceNames[match[2]]; |
| 603 } | 551 } |
| 604 | 552 |
| 605 callback(isDev, name, source); | 553 callback(isDev, name, source); |
| 606 } | 554 } |
| OLD | NEW |