| 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 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 | 11 |
| 12 import '../lib/src/lock_file.dart'; | 12 import '../lib/src/lock_file.dart'; |
| 13 import '../lib/src/log.dart' as log; |
| 13 import '../lib/src/package.dart'; | 14 import '../lib/src/package.dart'; |
| 14 import '../lib/src/pubspec.dart'; | 15 import '../lib/src/pubspec.dart'; |
| 15 import '../lib/src/sdk.dart' as sdk; | 16 import '../lib/src/sdk.dart' as sdk; |
| 16 import '../lib/src/source.dart'; | 17 import '../lib/src/source.dart'; |
| 17 import '../lib/src/source_registry.dart'; | 18 import '../lib/src/source_registry.dart'; |
| 18 import '../lib/src/system_cache.dart'; | 19 import '../lib/src/system_cache.dart'; |
| 19 import '../lib/src/utils.dart'; | 20 import '../lib/src/utils.dart'; |
| 20 import '../lib/src/version.dart'; | 21 import '../lib/src/version.dart'; |
| 21 import '../lib/src/solver/version_solver.dart'; | 22 import '../lib/src/solver/version_solver.dart'; |
| 22 import 'test_pub.dart'; | 23 import 'test_pub.dart'; |
| 23 | 24 |
| 24 MockSource source1; | 25 MockSource source1; |
| 25 MockSource source2; | 26 MockSource source2; |
| 26 | 27 |
| 27 main() { | 28 main() { |
| 28 initConfig(); | 29 initConfig(); |
| 29 | 30 |
| 31 // Uncomment this to debug failing tests. |
| 32 // log.showSolver(); |
| 33 |
| 30 // Since this test isn't run from the SDK, it can't find the "version" file | 34 // Since this test isn't run from the SDK, it can't find the "version" file |
| 31 // to load. Instead, just manually inject a version. | 35 // to load. Instead, just manually inject a version. |
| 32 sdk.version = new Version(1, 2, 3); | 36 sdk.version = new Version(1, 2, 3); |
| 33 | 37 |
| 34 group('basic graph', basicGraph); | 38 group('basic graph', basicGraph); |
| 35 group('with lockfile', withLockFile); | 39 group('with lockfile', withLockFile); |
| 36 group('root dependency', rootDependency); | 40 group('root dependency', rootDependency); |
| 37 group('dev dependency', devDependency); | 41 group('dev dependency', devDependency); |
| 38 group('unsolvable', unsolvable); | 42 group('unsolvable', unsolvable); |
| 39 group('backtracking', backtracking); | 43 group('backtracking', backtracking); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 'b 2.0.0': {}, | 481 'b 2.0.0': {}, |
| 478 'b 3.0.0': {}, | 482 'b 3.0.0': {}, |
| 479 'c 1.0.0': {}, | 483 'c 1.0.0': {}, |
| 480 }, result: { | 484 }, result: { |
| 481 'myapp from root': '0.0.0', | 485 'myapp from root': '0.0.0', |
| 482 'a': '1.0.0', | 486 'a': '1.0.0', |
| 483 'b': '3.0.0', | 487 'b': '3.0.0', |
| 484 'c': '1.0.0' | 488 'c': '1.0.0' |
| 485 }, maxTries: 2); | 489 }, maxTries: 2); |
| 486 | 490 |
| 491 // Tests that the backjumper will jump past unrelated selections when a |
| 492 // source conflict occurs. This test selects, in order: |
| 493 // - myapp -> a |
| 494 // - myapp -> b |
| 495 // - myapp -> c (1 of 5) |
| 496 // - b -> a |
| 497 // It selects a and b first because they have fewer versions than c. It |
| 498 // traverses b's dependency on a after selecting a version of c because |
| 499 // dependencies are traversed breadth-first (all of myapps's immediate deps |
| 500 // before any other their deps). |
| 501 // |
| 502 // This means it doesn't discover the source conflict until after selecting |
| 503 // c. When that happens, it should backjump past c instead of trying older |
| 504 // versions of it since they aren't related to the conflict. |
| 505 testResolve('backjump to conflicting source', { |
| 506 'myapp 0.0.0': { |
| 507 'a': 'any', |
| 508 'b': 'any', |
| 509 'c': 'any' |
| 510 }, |
| 511 'a 1.0.0': {}, |
| 512 'a 1.0.0 from mock2': {}, |
| 513 'b 1.0.0': { |
| 514 'a from mock2': 'any' |
| 515 }, |
| 516 'c 1.0.0': {}, |
| 517 'c 2.0.0': {}, |
| 518 'c 3.0.0': {}, |
| 519 'c 4.0.0': {}, |
| 520 'c 5.0.0': {}, |
| 521 }, error: sourceMismatch('myapp', 'b'), maxTries: 1); |
| 522 |
| 523 // Like the above test, but for a conflicting description. |
| 524 testResolve('backjump to conflicting description', { |
| 525 'myapp 0.0.0': { |
| 526 'a-x': 'any', |
| 527 'b': 'any', |
| 528 'c': 'any' |
| 529 }, |
| 530 'a-x 1.0.0': {}, |
| 531 'a-y 1.0.0': {}, |
| 532 'b 1.0.0': { |
| 533 'a-y': 'any' |
| 534 }, |
| 535 'c 1.0.0': {}, |
| 536 'c 2.0.0': {}, |
| 537 'c 3.0.0': {}, |
| 538 'c 4.0.0': {}, |
| 539 'c 5.0.0': {}, |
| 540 }, error: descriptionMismatch('myapp', 'b'), maxTries: 1); |
| 541 |
| 487 // Dependencies are ordered so that packages with fewer versions are tried | 542 // Dependencies are ordered so that packages with fewer versions are tried |
| 488 // first. Here, there are two valid solutions (either a or b must be | 543 // first. Here, there are two valid solutions (either a or b must be |
| 489 // downgraded once). The chosen one depends on which dep is traversed first. | 544 // downgraded once). The chosen one depends on which dep is traversed first. |
| 490 // Since b has fewer versions, it will be traversed first, which means a will | 545 // Since b has fewer versions, it will be traversed first, which means a will |
| 491 // come later. Since later selections are revised first, a gets downgraded. | 546 // come later. Since later selections are revised first, a gets downgraded. |
| 492 testResolve('traverse into package with fewer versions first', { | 547 testResolve('traverse into package with fewer versions first', { |
| 493 'myapp 0.0.0': { | 548 'myapp 0.0.0': { |
| 494 'a': 'any', | 549 'a': 'any', |
| 495 'b': 'any' | 550 'b': 'any' |
| 496 }, | 551 }, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 'bar': '2.0.0' | 667 'bar': '2.0.0' |
| 613 }, maxTries: 3); | 668 }, maxTries: 3); |
| 614 | 669 |
| 615 testResolve('ignores SDK constraints on bleeding edge', { | 670 testResolve('ignores SDK constraints on bleeding edge', { |
| 616 'myapp 0.0.0': {'sdk': badVersion } | 671 'myapp 0.0.0': {'sdk': badVersion } |
| 617 }, result: { | 672 }, result: { |
| 618 'myapp from root': '0.0.0' | 673 'myapp from root': '0.0.0' |
| 619 }, useBleedingEdgeSdkVersion: true); | 674 }, useBleedingEdgeSdkVersion: true); |
| 620 } | 675 } |
| 621 | 676 |
| 622 testResolve(description, packages, | 677 testResolve(description, packages, { |
| 623 {lockfile, result, FailMatcherBuilder error, int maxTries, | 678 lockfile, result, FailMatcherBuilder error, int maxTries, |
| 679 bool useBleedingEdgeSdkVersion}) { |
| 680 _testResolve(test, description, packages, lockfile: lockfile, result: result, |
| 681 error: error, maxTries: maxTries, |
| 682 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion); |
| 683 } |
| 684 |
| 685 solo_testResolve(description, packages, { |
| 686 lockfile, result, FailMatcherBuilder error, int maxTries, |
| 687 bool useBleedingEdgeSdkVersion}) { |
| 688 log.showSolver(); |
| 689 _testResolve(solo_test, description, packages, lockfile: lockfile, |
| 690 result: result, error: error, maxTries: maxTries, |
| 691 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion); |
| 692 } |
| 693 |
| 694 _testResolve(void testFn(String description, Function body), |
| 695 description, packages, { |
| 696 lockfile, result, FailMatcherBuilder error, int maxTries, |
| 624 bool useBleedingEdgeSdkVersion}) { | 697 bool useBleedingEdgeSdkVersion}) { |
| 625 if (maxTries == null) maxTries = 1; | 698 if (maxTries == null) maxTries = 1; |
| 626 if (useBleedingEdgeSdkVersion == null) useBleedingEdgeSdkVersion = false; | 699 if (useBleedingEdgeSdkVersion == null) useBleedingEdgeSdkVersion = false; |
| 627 | 700 |
| 628 test(description, () { | 701 testFn(description, () { |
| 629 var cache = new SystemCache('.'); | 702 var cache = new SystemCache('.'); |
| 630 source1 = new MockSource('mock1'); | 703 source1 = new MockSource('mock1'); |
| 631 source2 = new MockSource('mock2'); | 704 source2 = new MockSource('mock2'); |
| 632 cache.register(source1); | 705 cache.register(source1); |
| 633 cache.register(source2); | 706 cache.register(source2); |
| 634 cache.sources.setDefault(source1.name); | 707 cache.sources.setDefault(source1.name); |
| 635 | 708 |
| 636 // Build the test package graph. | 709 // Build the test package graph. |
| 637 var root; | 710 var root; |
| 638 packages.forEach((nameVersion, dependencies) { | 711 packages.forEach((nameVersion, dependencies) { |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 }; | 1062 }; |
| 990 | 1063 |
| 991 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); | 1064 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); |
| 992 if (match != null) { | 1065 if (match != null) { |
| 993 name = match[1]; | 1066 name = match[1]; |
| 994 source = sourceNames[match[2]]; | 1067 source = sourceNames[match[2]]; |
| 995 } | 1068 } |
| 996 | 1069 |
| 997 callback(isDev, name, source); | 1070 callback(isDev, name, source); |
| 998 } | 1071 } |
| OLD | NEW |