Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: sdk/lib/_internal/pub/test/version_solver_test.dart

Issue 14685002: Backjump on a source or description mismatch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added some more tests. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/solver/version_solver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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': 'any'
515 },
516 'b 2.0.0': {
517 'a from mock2': 'any'
518 },
519 'c 1.0.0': {},
520 'c 2.0.0': {},
521 'c 3.0.0': {},
522 'c 4.0.0': {},
523 'c 5.0.0': {},
524 }, result: {
525 'myapp from root': '0.0.0',
526 'a': '1.0.0',
527 'b': '1.0.0',
528 'c': '5.0.0'
529 }, maxTries: 2);
530
531 // Like the above test, but for a conflicting description.
532 testResolve('backjump to conflicting description', {
533 'myapp 0.0.0': {
534 'a-x': 'any',
535 'b': 'any',
536 'c': 'any'
537 },
538 'a-x 1.0.0': {},
539 'a-y 1.0.0': {},
540 'b 1.0.0': {
541 'a-x': 'any'
542 },
543 'b 2.0.0': {
544 'a-y': 'any'
545 },
546 'c 1.0.0': {},
547 'c 2.0.0': {},
548 'c 3.0.0': {},
549 'c 4.0.0': {},
550 'c 5.0.0': {},
551 }, result: {
552 'myapp from root': '0.0.0',
553 'a': '1.0.0',
554 'b': '1.0.0',
555 'c': '5.0.0'
556 }, maxTries: 2);
557
558 // Similar to the above two tests but where there is no solution. It should
559 // fail in this case with no backtracking.
560 testResolve('backjump to conflicting source', {
561 'myapp 0.0.0': {
562 'a': 'any',
563 'b': 'any',
564 'c': 'any'
565 },
566 'a 1.0.0': {},
567 'a 1.0.0 from mock2': {},
568 'b 1.0.0': {
569 'a from mock2': 'any'
570 },
571 'c 1.0.0': {},
572 'c 2.0.0': {},
573 'c 3.0.0': {},
574 'c 4.0.0': {},
575 'c 5.0.0': {},
576 }, error: sourceMismatch('myapp', 'b'), maxTries: 1);
577
578 testResolve('backjump to conflicting description', {
579 'myapp 0.0.0': {
580 'a-x': 'any',
581 'b': 'any',
582 'c': 'any'
583 },
584 'a-x 1.0.0': {},
585 'a-y 1.0.0': {},
586 'b 1.0.0': {
587 'a-y': 'any'
588 },
589 'c 1.0.0': {},
590 'c 2.0.0': {},
591 'c 3.0.0': {},
592 'c 4.0.0': {},
593 'c 5.0.0': {},
594 }, error: descriptionMismatch('myapp', 'b'), maxTries: 1);
595
487 // Dependencies are ordered so that packages with fewer versions are tried 596 // 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 597 // 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. 598 // 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 599 // 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. 600 // come later. Since later selections are revised first, a gets downgraded.
492 testResolve('traverse into package with fewer versions first', { 601 testResolve('traverse into package with fewer versions first', {
493 'myapp 0.0.0': { 602 'myapp 0.0.0': {
494 'a': 'any', 603 'a': 'any',
495 'b': 'any' 604 'b': 'any'
496 }, 605 },
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 'bar': '2.0.0' 721 'bar': '2.0.0'
613 }, maxTries: 3); 722 }, maxTries: 3);
614 723
615 testResolve('ignores SDK constraints on bleeding edge', { 724 testResolve('ignores SDK constraints on bleeding edge', {
616 'myapp 0.0.0': {'sdk': badVersion } 725 'myapp 0.0.0': {'sdk': badVersion }
617 }, result: { 726 }, result: {
618 'myapp from root': '0.0.0' 727 'myapp from root': '0.0.0'
619 }, useBleedingEdgeSdkVersion: true); 728 }, useBleedingEdgeSdkVersion: true);
620 } 729 }
621 730
622 testResolve(description, packages, 731 testResolve(description, packages, {
623 {lockfile, result, FailMatcherBuilder error, int maxTries, 732 lockfile, result, FailMatcherBuilder error, int maxTries,
733 bool useBleedingEdgeSdkVersion}) {
734 _testResolve(test, description, packages, lockfile: lockfile, result: result,
735 error: error, maxTries: maxTries,
736 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion);
737 }
738
739 solo_testResolve(description, packages, {
740 lockfile, result, FailMatcherBuilder error, int maxTries,
741 bool useBleedingEdgeSdkVersion}) {
742 log.showSolver();
743 _testResolve(solo_test, description, packages, lockfile: lockfile,
744 result: result, error: error, maxTries: maxTries,
745 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion);
746 }
747
748 _testResolve(void testFn(String description, Function body),
749 description, packages, {
750 lockfile, result, FailMatcherBuilder error, int maxTries,
624 bool useBleedingEdgeSdkVersion}) { 751 bool useBleedingEdgeSdkVersion}) {
625 if (maxTries == null) maxTries = 1; 752 if (maxTries == null) maxTries = 1;
626 if (useBleedingEdgeSdkVersion == null) useBleedingEdgeSdkVersion = false; 753 if (useBleedingEdgeSdkVersion == null) useBleedingEdgeSdkVersion = false;
627 754
628 test(description, () { 755 testFn(description, () {
629 var cache = new SystemCache('.'); 756 var cache = new SystemCache('.');
630 source1 = new MockSource('mock1'); 757 source1 = new MockSource('mock1');
631 source2 = new MockSource('mock2'); 758 source2 = new MockSource('mock2');
632 cache.register(source1); 759 cache.register(source1);
633 cache.register(source2); 760 cache.register(source2);
634 cache.sources.setDefault(source1.name); 761 cache.sources.setDefault(source1.name);
635 762
636 // Build the test package graph. 763 // Build the test package graph.
637 var root; 764 var root;
638 packages.forEach((nameVersion, dependencies) { 765 packages.forEach((nameVersion, dependencies) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 }; 1116 };
990 1117
991 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); 1118 var match = new RegExp(r"(.*) from (.*)").firstMatch(description);
992 if (match != null) { 1119 if (match != null) {
993 name = match[1]; 1120 name = match[1];
994 source = sourceNames[match[2]]; 1121 source = sourceNames[match[2]];
995 } 1122 }
996 1123
997 callback(isDev, name, source); 1124 callback(isDev, name, source);
998 } 1125 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/solver/version_solver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698