| 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_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 25 matching lines...) Expand all Loading... |
| 36 group('basic graph', basicGraph); | 36 group('basic graph', basicGraph); |
| 37 group('with lockfile', withLockFile); | 37 group('with lockfile', withLockFile); |
| 38 group('root dependency', rootDependency); | 38 group('root dependency', rootDependency); |
| 39 group('dev dependency', devDependency); | 39 group('dev dependency', devDependency); |
| 40 group('unsolvable', unsolvable); | 40 group('unsolvable', unsolvable); |
| 41 group('bad source', badSource); | 41 group('bad source', badSource); |
| 42 group('backtracking', backtracking); | 42 group('backtracking', backtracking); |
| 43 group('SDK constraint', sdkConstraint); | 43 group('SDK constraint', sdkConstraint); |
| 44 group('pre-release', prerelease); | 44 group('pre-release', prerelease); |
| 45 group('override', override); | 45 group('override', override); |
| 46 group('downgrade', downgrade); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void basicGraph() { | 49 void basicGraph() { |
| 49 testResolve('no dependencies', { | 50 testResolve('no dependencies', { |
| 50 'myapp 0.0.0': {} | 51 'myapp 0.0.0': {} |
| 51 }, result: { | 52 }, result: { |
| 52 'myapp from root': '0.0.0' | 53 'myapp from root': '0.0.0' |
| 53 }); | 54 }); |
| 54 | 55 |
| 55 testResolve('simple dependency tree', { | 56 testResolve('simple dependency tree', { |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 }, | 1051 }, |
| 1051 'foo 0.0.0': {} | 1052 'foo 0.0.0': {} |
| 1052 }, overrides: { | 1053 }, overrides: { |
| 1053 'foo': 'any' | 1054 'foo': 'any' |
| 1054 }, result: { | 1055 }, result: { |
| 1055 'myapp from root': '0.0.0', | 1056 'myapp from root': '0.0.0', |
| 1056 'foo': '0.0.0' | 1057 'foo': '0.0.0' |
| 1057 }); | 1058 }); |
| 1058 } | 1059 } |
| 1059 | 1060 |
| 1061 void downgrade() { |
| 1062 testResolve("downgrades a dependency to the lowest matching version", { |
| 1063 'myapp 0.0.0': { |
| 1064 'foo': '>=2.0.0 <3.0.0' |
| 1065 }, |
| 1066 'foo 1.0.0': {}, |
| 1067 'foo 2.0.0-dev': {}, |
| 1068 'foo 2.0.0': {}, |
| 1069 'foo 2.1.0': {} |
| 1070 }, lockfile: { |
| 1071 'foo': '2.1.0' |
| 1072 }, result: { |
| 1073 'myapp from root': '0.0.0', |
| 1074 'foo': '2.0.0' |
| 1075 }, downgrade: true); |
| 1076 |
| 1077 testResolve('use earliest allowed prerelease if no stable versions match ' |
| 1078 'while downgrading', { |
| 1079 'myapp 0.0.0': { |
| 1080 'a': '>=2.0.0-dev.1 <3.0.0' |
| 1081 }, |
| 1082 'a 1.0.0': {}, |
| 1083 'a 2.0.0-dev.1': {}, |
| 1084 'a 2.0.0-dev.2': {}, |
| 1085 'a 2.0.0-dev.3': {} |
| 1086 }, result: { |
| 1087 'myapp from root': '0.0.0', |
| 1088 'a': '2.0.0-dev.1' |
| 1089 }, downgrade: true); |
| 1090 } |
| 1091 |
| 1060 testResolve(String description, Map packages, { | 1092 testResolve(String description, Map packages, { |
| 1061 Map lockfile, Map overrides, Map result, FailMatcherBuilder error, | 1093 Map lockfile, Map overrides, Map result, FailMatcherBuilder error, |
| 1062 int maxTries}) { | 1094 int maxTries, bool downgrade: false}) { |
| 1063 _testResolve(test, description, packages, lockfile: lockfile, | 1095 _testResolve(test, description, packages, lockfile: lockfile, |
| 1064 overrides: overrides, result: result, error: error, maxTries: maxTries); | 1096 overrides: overrides, result: result, error: error, maxTries: maxTries, |
| 1097 downgrade: downgrade); |
| 1065 } | 1098 } |
| 1066 | 1099 |
| 1067 solo_testResolve(String description, Map packages, { | 1100 solo_testResolve(String description, Map packages, { |
| 1068 Map lockfile, Map overrides, Map result, FailMatcherBuilder error, | 1101 Map lockfile, Map overrides, Map result, FailMatcherBuilder error, |
| 1069 int maxTries}) { | 1102 int maxTries, bool downgrade: false}) { |
| 1070 log.verbosity = log.Verbosity.SOLVER; | 1103 log.verbosity = log.Verbosity.SOLVER; |
| 1071 _testResolve(solo_test, description, packages, lockfile: lockfile, | 1104 _testResolve(solo_test, description, packages, lockfile: lockfile, |
| 1072 overrides: overrides, result: result, error: error, maxTries: maxTries); | 1105 overrides: overrides, result: result, error: error, maxTries: maxTries, |
| 1106 downgrade: downgrade); |
| 1073 } | 1107 } |
| 1074 | 1108 |
| 1075 _testResolve(void testFn(String description, Function body), | 1109 _testResolve(void testFn(String description, Function body), |
| 1076 String description, Map packages, { | 1110 String description, Map packages, { |
| 1077 Map lockfile, Map overrides, Map result, FailMatcherBuilder error, | 1111 Map lockfile, Map overrides, Map result, FailMatcherBuilder error, |
| 1078 int maxTries}) { | 1112 int maxTries, bool downgrade: false}) { |
| 1079 if (maxTries == null) maxTries = 1; | 1113 if (maxTries == null) maxTries = 1; |
| 1080 | 1114 |
| 1081 testFn(description, () { | 1115 testFn(description, () { |
| 1082 var cache = new SystemCache('.'); | 1116 var cache = new SystemCache('.'); |
| 1083 source1 = new MockSource('mock1'); | 1117 source1 = new MockSource('mock1'); |
| 1084 source2 = new MockSource('mock2'); | 1118 source2 = new MockSource('mock2'); |
| 1085 cache.register(source1); | 1119 cache.register(source1); |
| 1086 cache.register(source2); | 1120 cache.register(source2); |
| 1087 cache.sources.setDefault(source1.name); | 1121 cache.sources.setDefault(source1.name); |
| 1088 | 1122 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1117 var realLockFile = new LockFile.empty(); | 1151 var realLockFile = new LockFile.empty(); |
| 1118 if (lockfile != null) { | 1152 if (lockfile != null) { |
| 1119 lockfile.forEach((name, version) { | 1153 lockfile.forEach((name, version) { |
| 1120 version = new Version.parse(version); | 1154 version = new Version.parse(version); |
| 1121 realLockFile.packages[name] = | 1155 realLockFile.packages[name] = |
| 1122 new PackageId(name, source1.name, version, name); | 1156 new PackageId(name, source1.name, version, name); |
| 1123 }); | 1157 }); |
| 1124 } | 1158 } |
| 1125 | 1159 |
| 1126 // Resolve the versions. | 1160 // Resolve the versions. |
| 1127 var future = resolveVersions(cache.sources, root, lockFile: realLockFile); | 1161 var future = resolveVersions( |
| 1162 downgrade ? SolveType.DOWNGRADE : SolveType.GET, |
| 1163 cache.sources, root, lockFile: realLockFile); |
| 1128 | 1164 |
| 1129 var matcher; | 1165 var matcher; |
| 1130 if (result != null) { | 1166 if (result != null) { |
| 1131 matcher = new SolveSuccessMatcher(result, maxTries); | 1167 matcher = new SolveSuccessMatcher(result, maxTries); |
| 1132 } else if (error != null) { | 1168 } else if (error != null) { |
| 1133 matcher = error(maxTries); | 1169 matcher = error(maxTries); |
| 1134 } | 1170 } |
| 1135 | 1171 |
| 1136 expect(future, completion(matcher)); | 1172 expect(future, completion(matcher)); |
| 1137 }); | 1173 }); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 /// that a source is only hit once for a given package and that pub | 1356 /// that a source is only hit once for a given package and that pub |
| 1321 /// internally caches the results. | 1357 /// internally caches the results. |
| 1322 final _requestedVersions = new Set<String>(); | 1358 final _requestedVersions = new Set<String>(); |
| 1323 | 1359 |
| 1324 /// Keeps track of which package pubspecs have been requested. Ensures that a | 1360 /// Keeps track of which package pubspecs have been requested. Ensures that a |
| 1325 /// source is only hit once for a given package and that pub internally | 1361 /// source is only hit once for a given package and that pub internally |
| 1326 /// caches the results. | 1362 /// caches the results. |
| 1327 final _requestedPubspecs = new Map<String, Set<Version>>(); | 1363 final _requestedPubspecs = new Map<String, Set<Version>>(); |
| 1328 | 1364 |
| 1329 final String name; | 1365 final String name; |
| 1366 final hasMultipleVersions = true; |
| 1330 | 1367 |
| 1331 MockSource(this.name); | 1368 MockSource(this.name); |
| 1332 | 1369 |
| 1333 dynamic parseDescription(String containingPath, description, | 1370 dynamic parseDescription(String containingPath, description, |
| 1334 {bool fromLockFile: false}) => description; | 1371 {bool fromLockFile: false}) => description; |
| 1335 | 1372 |
| 1336 bool descriptionsEqual(description1, description2) => | 1373 bool descriptionsEqual(description1, description2) => |
| 1337 description1 == description2; | 1374 description1 == description2; |
| 1338 | 1375 |
| 1339 Future<String> getDirectory(PackageId id) { | 1376 Future<String> getDirectory(PackageId id) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 } | 1510 } |
| 1474 | 1511 |
| 1475 var source = "mock1"; | 1512 var source = "mock1"; |
| 1476 if (match[7] != null) { | 1513 if (match[7] != null) { |
| 1477 source = match[7]; | 1514 source = match[7]; |
| 1478 if (source == "root") source = null; | 1515 if (source == "root") source = null; |
| 1479 } | 1516 } |
| 1480 | 1517 |
| 1481 return new PackageId(name, source, parsedVersion, description); | 1518 return new PackageId(name, source, parsedVersion, description); |
| 1482 } | 1519 } |
| OLD | NEW |