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

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

Issue 73463003: Support overrides in the version solver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
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_upgrade_test; 5 library pub_upgrade_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 group('basic graph', basicGraph); 35 group('basic graph', basicGraph);
36 group('with lockfile', withLockFile); 36 group('with lockfile', withLockFile);
37 group('root dependency', rootDependency); 37 group('root dependency', rootDependency);
38 group('dev dependency', devDependency); 38 group('dev dependency', devDependency);
39 group('unsolvable', unsolvable); 39 group('unsolvable', unsolvable);
40 group('bad source', badSource); 40 group('bad source', badSource);
41 group('backtracking', backtracking); 41 group('backtracking', backtracking);
42 group('SDK constraint', sdkConstraint); 42 group('SDK constraint', sdkConstraint);
43 group('pre-release', prerelease); 43 group('pre-release', prerelease);
44 group('override', override);
44 } 45 }
45 46
46 void basicGraph() { 47 void basicGraph() {
47 testResolve('no dependencies', { 48 testResolve('no dependencies', {
48 'myapp 0.0.0': {} 49 'myapp 0.0.0': {}
49 }, result: { 50 }, result: {
50 'myapp from root': '0.0.0' 51 'myapp from root': '0.0.0'
51 }); 52 });
52 53
53 testResolve('simple dependency tree', { 54 testResolve('simple dependency tree', {
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 'a 1.0.0': {}, 849 'a 1.0.0': {},
849 'a 1.1.0': {}, 850 'a 1.1.0': {},
850 'a 2.0.0-dev': {}, 851 'a 2.0.0-dev': {},
851 'a 2.0.0': {} 852 'a 2.0.0': {}
852 }, result: { 853 }, result: {
853 'myapp from root': '0.0.0', 854 'myapp from root': '0.0.0',
854 'a': '1.1.0' 855 'a': '1.1.0'
855 }); 856 });
856 } 857 }
857 858
858 testResolve(description, packages, { 859 void override() {
859 lockfile, result, FailMatcherBuilder error, int maxTries, 860 testResolve('chooses best version matching override constraint', {
860 bool useBleedingEdgeSdkVersion}) { 861 'myapp 0.0.0': {
861 _testResolve(test, description, packages, lockfile: lockfile, result: result, 862 'a': 'any'
862 error: error, maxTries: maxTries, 863 },
864 'a 1.0.0': {},
865 'a 2.0.0': {},
866 'a 3.0.0': {}
867 }, overrides: {
868 'a': '<3.0.0'
869 }, result: {
870 'myapp from root': '0.0.0',
871 'a': '2.0.0'
872 });
873
874 testResolve('uses override as dependency', {
875 'myapp 0.0.0': {},
876 'a 1.0.0': {},
877 'a 2.0.0': {},
878 'a 3.0.0': {}
879 }, overrides: {
880 'a': '<3.0.0'
881 }, result: {
882 'myapp from root': '0.0.0',
883 'a': '2.0.0'
884 });
885
886 testResolve('ignores other constraints on overridden package', {
887 'myapp 0.0.0': {
888 'b': 'any',
889 'c': 'any'
890 },
891 'a 1.0.0': {},
892 'a 2.0.0': {},
893 'a 3.0.0': {},
894 'b 1.0.0': {
895 'a': '1.0.0'
896 },
897 'c 1.0.0': {
898 'a': '3.0.0'
899 }
900 }, overrides: {
901 'a': '2.0.0'
902 }, result: {
903 'myapp from root': '0.0.0',
904 'a': '2.0.0',
905 'b': '1.0.0',
906 'c': '1.0.0'
907 });
908
909 testResolve('backtracks on overidden package for its constraints', {
910 'myapp 0.0.0': {
911 'shared': '2.0.0'
912 },
913 'a 1.0.0': {
914 'shared': 'any'
915 },
916 'a 2.0.0': {
917 'shared': '1.0.0'
918 },
919 'shared 1.0.0': {},
920 'shared 2.0.0': {}
921 }, overrides: {
922 'a': '<3.0.0'
923 }, result: {
924 'myapp from root': '0.0.0',
925 'a': '1.0.0',
926 'shared': '2.0.0'
927 }, maxTries: 2);
928
929 testResolve('override compatible with locked dependency', {
930 'myapp 0.0.0': {
931 'foo': 'any'
932 },
933 'foo 1.0.0': { 'bar': '1.0.0' },
934 'foo 1.0.1': { 'bar': '1.0.1' },
935 'foo 1.0.2': { 'bar': '1.0.2' },
936 'bar 1.0.0': {},
937 'bar 1.0.1': {},
938 'bar 1.0.2': {}
939 }, lockfile: {
940 'foo': '1.0.1'
941 }, overrides: {
942 'foo': '<1.0.2'
943 }, result: {
944 'myapp from root': '0.0.0',
945 'foo': '1.0.1',
946 'bar': '1.0.1'
947 });
948
949 testResolve('override incompatible with locked dependency', {
950 'myapp 0.0.0': {
951 'foo': 'any'
952 },
953 'foo 1.0.0': { 'bar': '1.0.0' },
954 'foo 1.0.1': { 'bar': '1.0.1' },
955 'foo 1.0.2': { 'bar': '1.0.2' },
956 'bar 1.0.0': {},
957 'bar 1.0.1': {},
958 'bar 1.0.2': {}
959 }, lockfile: {
960 'foo': '1.0.1'
961 }, overrides: {
962 'foo': '>1.0.1'
963 }, result: {
964 'myapp from root': '0.0.0',
965 'foo': '1.0.2',
966 'bar': '1.0.2'
967 });
968
969 testResolve('no version that matches override', {
970 'myapp 0.0.0': {},
971 'foo 2.0.0': {},
972 'foo 2.1.3': {}
973 }, overrides: {
974 'foo': '>=1.0.0 <2.0.0'
975 }, error: noVersion(['myapp']));
976
977 testResolve('override a bad source without error', {
978 'myapp 0.0.0': {
979 'foo from bad': 'any'
980 },
981 'foo 0.0.0': {}
982 }, overrides: {
983 'foo': 'any'
984 }, result: {
985 'myapp from root': '0.0.0',
986 'foo': '0.0.0'
987 });
988 }
989
990 testResolve(String description, Map packages, {
991 Map lockfile, Map overrides, Map result, FailMatcherBuilder error,
992 int maxTries, bool useBleedingEdgeSdkVersion}) {
993 _testResolve(test, description, packages, lockfile: lockfile,
994 overrides: overrides, result: result, error: error, maxTries: maxTries,
863 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion); 995 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion);
864 } 996 }
865 997
866 solo_testResolve(description, packages, { 998 solo_testResolve(String description, Map packages, {
867 lockfile, result, FailMatcherBuilder error, int maxTries, 999 Map lockfile, Map overrides, Map result, FailMatcherBuilder error,
868 bool useBleedingEdgeSdkVersion}) { 1000 int maxTries, bool useBleedingEdgeSdkVersion}) {
869 log.showSolver(); 1001 log.showSolver();
870 _testResolve(solo_test, description, packages, lockfile: lockfile, 1002 _testResolve(solo_test, description, packages, lockfile: lockfile,
871 result: result, error: error, maxTries: maxTries, 1003 overrides: overrides, result: result, error: error, maxTries: maxTries,
872 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion); 1004 useBleedingEdgeSdkVersion: useBleedingEdgeSdkVersion);
873 } 1005 }
874 1006
875 _testResolve(void testFn(String description, Function body), 1007 _testResolve(void testFn(String description, Function body),
876 description, packages, { 1008 String description, Map packages, {
877 lockfile, result, FailMatcherBuilder error, int maxTries, 1009 Map lockfile, Map overrides, Map result, FailMatcherBuilder error,
878 bool useBleedingEdgeSdkVersion}) { 1010 int maxTries, bool useBleedingEdgeSdkVersion}) {
879 if (maxTries == null) maxTries = 1; 1011 if (maxTries == null) maxTries = 1;
880 if (useBleedingEdgeSdkVersion == null) useBleedingEdgeSdkVersion = false; 1012 if (useBleedingEdgeSdkVersion == null) useBleedingEdgeSdkVersion = false;
881 1013
882 testFn(description, () { 1014 testFn(description, () {
883 var cache = new SystemCache('.'); 1015 var cache = new SystemCache('.');
884 source1 = new MockSource('mock1'); 1016 source1 = new MockSource('mock1');
885 source2 = new MockSource('mock2'); 1017 source2 = new MockSource('mock2');
886 cache.register(source1); 1018 cache.register(source1);
887 cache.register(source2); 1019 cache.register(source2);
888 cache.sources.setDefault(source1.name); 1020 cache.sources.setDefault(source1.name);
(...skipping 27 matching lines...) Expand all
916 // Parse the lockfile. 1048 // Parse the lockfile.
917 var realLockFile = new LockFile.empty(); 1049 var realLockFile = new LockFile.empty();
918 if (lockfile != null) { 1050 if (lockfile != null) {
919 lockfile.forEach((name, version) { 1051 lockfile.forEach((name, version) {
920 version = new Version.parse(version); 1052 version = new Version.parse(version);
921 realLockFile.packages[name] = 1053 realLockFile.packages[name] =
922 new PackageId(name, source1.name, version, name); 1054 new PackageId(name, source1.name, version, name);
923 }); 1055 });
924 } 1056 }
925 1057
1058 // Parse the overrides.
1059 var realOverrides = [];
1060 if (overrides != null) {
1061 overrides.forEach((spec, constraint) {
1062 realOverrides.add(parseSpec(spec).withConstraint(
1063 new VersionConstraint.parse(constraint)));
1064 });
1065 }
1066
926 // Make a version number like the continuous build's version. 1067 // Make a version number like the continuous build's version.
927 var previousVersion = sdk.version; 1068 var previousVersion = sdk.version;
928 if (useBleedingEdgeSdkVersion) { 1069 if (useBleedingEdgeSdkVersion) {
929 sdk.version = new Version(0, 1, 2, build: '0_r12345_juser'); 1070 sdk.version = new Version(0, 1, 2, build: '0_r12345_juser');
930 } 1071 }
931 1072
932 // Resolve the versions. 1073 // Resolve the versions.
933 var future = resolveVersions(cache.sources, root, 1074 var future = resolveVersions(cache.sources, root,
934 lockFile: realLockFile); 1075 lockFile: realLockFile, overrides: realOverrides);
935 1076
936 var matcher; 1077 var matcher;
937 if (result != null) { 1078 if (result != null) {
938 matcher = new SolveSuccessMatcher(result, maxTries); 1079 matcher = new SolveSuccessMatcher(result, maxTries);
939 } else if (error != null) { 1080 } else if (error != null) {
940 matcher = error(maxTries); 1081 matcher = error(maxTries);
941 } 1082 }
942 1083
943 future = future.whenComplete(() { 1084 future = future.whenComplete(() {
944 if (useBleedingEdgeSdkVersion) { 1085 if (useBleedingEdgeSdkVersion) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 } 1406 }
1266 1407
1267 var source = "mock1"; 1408 var source = "mock1";
1268 if (match[7] != null) { 1409 if (match[7] != null) {
1269 source = match[7]; 1410 source = match[7];
1270 if (source == "root") source = null; 1411 if (source == "root") source = null;
1271 } 1412 }
1272 1413
1273 return new PackageId(name, source, parsedVersion, description); 1414 return new PackageId(name, source, parsedVersion, description);
1274 } 1415 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698