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 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 source1 = new MockSource('mock1'); | 1016 source1 = new MockSource('mock1'); |
1017 source2 = new MockSource('mock2'); | 1017 source2 = new MockSource('mock2'); |
1018 cache.register(source1); | 1018 cache.register(source1); |
1019 cache.register(source2); | 1019 cache.register(source2); |
1020 cache.sources.setDefault(source1.name); | 1020 cache.sources.setDefault(source1.name); |
1021 | 1021 |
1022 // Build the test package graph. | 1022 // Build the test package graph. |
1023 var root; | 1023 var root; |
1024 packages.forEach((description, dependencies) { | 1024 packages.forEach((description, dependencies) { |
1025 var id = parseSpec(description); | 1025 var id = parseSpec(description); |
1026 var package = mockPackage(id, dependencies); | 1026 var package = mockPackage(id, dependencies, |
| 1027 id.name == 'myapp' ? overrides : null); |
1027 if (id.name == 'myapp') { | 1028 if (id.name == 'myapp') { |
1028 // Don't add the root package to the server, so we can verify that Pub | 1029 // Don't add the root package to the server, so we can verify that Pub |
1029 // doesn't try to look up information about the local package on the | 1030 // doesn't try to look up information about the local package on the |
1030 // remote server. | 1031 // remote server. |
1031 root = package; | 1032 root = package; |
1032 } else { | 1033 } else { |
1033 (cache.sources[id.source] as MockSource).addPackage( | 1034 (cache.sources[id.source] as MockSource).addPackage( |
1034 id.description, package); | 1035 id.description, package); |
1035 } | 1036 } |
1036 }); | 1037 }); |
(...skipping 11 matching lines...) Expand all Loading... |
1048 // Parse the lockfile. | 1049 // Parse the lockfile. |
1049 var realLockFile = new LockFile.empty(); | 1050 var realLockFile = new LockFile.empty(); |
1050 if (lockfile != null) { | 1051 if (lockfile != null) { |
1051 lockfile.forEach((name, version) { | 1052 lockfile.forEach((name, version) { |
1052 version = new Version.parse(version); | 1053 version = new Version.parse(version); |
1053 realLockFile.packages[name] = | 1054 realLockFile.packages[name] = |
1054 new PackageId(name, source1.name, version, name); | 1055 new PackageId(name, source1.name, version, name); |
1055 }); | 1056 }); |
1056 } | 1057 } |
1057 | 1058 |
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 | |
1067 // Make a version number like the continuous build's version. | 1059 // Make a version number like the continuous build's version. |
1068 var previousVersion = sdk.version; | 1060 var previousVersion = sdk.version; |
1069 if (useBleedingEdgeSdkVersion) { | 1061 if (useBleedingEdgeSdkVersion) { |
1070 sdk.version = new Version(0, 1, 2, build: '0_r12345_juser'); | 1062 sdk.version = new Version(0, 1, 2, build: '0_r12345_juser'); |
1071 } | 1063 } |
1072 | 1064 |
1073 // Resolve the versions. | 1065 // Resolve the versions. |
1074 var future = resolveVersions(cache.sources, root, | 1066 var future = resolveVersions(cache.sources, root, lockFile: realLockFile); |
1075 lockFile: realLockFile, overrides: realOverrides); | |
1076 | 1067 |
1077 var matcher; | 1068 var matcher; |
1078 if (result != null) { | 1069 if (result != null) { |
1079 matcher = new SolveSuccessMatcher(result, maxTries); | 1070 matcher = new SolveSuccessMatcher(result, maxTries); |
1080 } else if (error != null) { | 1071 } else if (error != null) { |
1081 matcher = error(maxTries); | 1072 matcher = error(maxTries); |
1082 } | 1073 } |
1083 | 1074 |
1084 future = future.whenComplete(() { | 1075 future = future.whenComplete(() { |
1085 if (useBleedingEdgeSdkVersion) { | 1076 if (useBleedingEdgeSdkVersion) { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 Future<bool> get(PackageId id, String path) { | 1315 Future<bool> get(PackageId id, String path) { |
1325 throw new Exception('no'); | 1316 throw new Exception('no'); |
1326 } | 1317 } |
1327 | 1318 |
1328 void addPackage(String description, Package package) { | 1319 void addPackage(String description, Package package) { |
1329 _packages.putIfAbsent(description, () => new Map<Version, Package>()); | 1320 _packages.putIfAbsent(description, () => new Map<Version, Package>()); |
1330 _packages[description][package.version] = package; | 1321 _packages[description][package.version] = package; |
1331 } | 1322 } |
1332 } | 1323 } |
1333 | 1324 |
1334 Package mockPackage(PackageId id, Map dependencyStrings) { | 1325 Package mockPackage(PackageId id, Map dependencyStrings, Map overrides) { |
1335 var sdkConstraint = null; | 1326 var sdkConstraint = null; |
1336 | 1327 |
1337 // Build the pubspec dependencies. | 1328 // Build the pubspec dependencies. |
1338 var dependencies = <PackageDep>[]; | 1329 var dependencies = <PackageDep>[]; |
1339 var devDependencies = <PackageDep>[]; | 1330 var devDependencies = <PackageDep>[]; |
1340 | 1331 |
1341 dependencyStrings.forEach((description, constraint) { | 1332 dependencyStrings.forEach((spec, constraint) { |
1342 var isDev = description.startsWith("(dev) "); | 1333 var isDev = spec.startsWith("(dev) "); |
1343 if (isDev) { | 1334 if (isDev) { |
1344 description = description.substring("(dev) ".length); | 1335 spec = spec.substring("(dev) ".length); |
1345 } | 1336 } |
1346 | 1337 |
1347 var dep = parseSpec(description).withConstraint( | 1338 var dep = parseSpec(spec).withConstraint( |
1348 new VersionConstraint.parse(constraint)); | 1339 new VersionConstraint.parse(constraint)); |
1349 | 1340 |
1350 if (dep.name == 'sdk') { | 1341 if (dep.name == 'sdk') { |
1351 sdkConstraint = dep.constraint; | 1342 sdkConstraint = dep.constraint; |
1352 return; | 1343 return; |
1353 } | 1344 } |
1354 | 1345 |
1355 if (isDev) { | 1346 if (isDev) { |
1356 devDependencies.add(dep); | 1347 devDependencies.add(dep); |
1357 } else { | 1348 } else { |
1358 dependencies.add(dep); | 1349 dependencies.add(dep); |
1359 } | 1350 } |
1360 }); | 1351 }); |
1361 | 1352 |
| 1353 var dependencyOverrides = <PackageDep>[]; |
| 1354 if (overrides != null) { |
| 1355 overrides.forEach((spec, constraint) { |
| 1356 dependencyOverrides.add(parseSpec(spec).withConstraint( |
| 1357 new VersionConstraint.parse(constraint))); |
| 1358 }); |
| 1359 } |
| 1360 |
1362 var pubspec = new Pubspec(id.name, id.version, dependencies, | 1361 var pubspec = new Pubspec(id.name, id.version, dependencies, |
1363 devDependencies, new PubspecEnvironment(sdkConstraint), []); | 1362 devDependencies, dependencyOverrides, |
| 1363 new PubspecEnvironment(sdkConstraint), []); |
1364 return new Package.inMemory(pubspec); | 1364 return new Package.inMemory(pubspec); |
1365 } | 1365 } |
1366 | 1366 |
1367 /// Creates a new [PackageId] parsed from [text], which looks something like | 1367 /// Creates a new [PackageId] parsed from [text], which looks something like |
1368 /// this: | 1368 /// this: |
1369 /// | 1369 /// |
1370 /// foo-xyz 1.0.0 from mock | 1370 /// foo-xyz 1.0.0 from mock |
1371 /// | 1371 /// |
1372 /// The package name is "foo". A hyphenated suffix like "-xyz" here is part | 1372 /// The package name is "foo". A hyphenated suffix like "-xyz" here is part |
1373 /// of the package description, but not its name, so the description here is | 1373 /// of the package description, but not its name, so the description here is |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 } | 1406 } |
1407 | 1407 |
1408 var source = "mock1"; | 1408 var source = "mock1"; |
1409 if (match[7] != null) { | 1409 if (match[7] != null) { |
1410 source = match[7]; | 1410 source = match[7]; |
1411 if (source == "root") source = null; | 1411 if (source == "root") source = null; |
1412 } | 1412 } |
1413 | 1413 |
1414 return new PackageId(name, source, parsedVersion, description); | 1414 return new PackageId(name, source, parsedVersion, description); |
1415 } | 1415 } |
OLD | NEW |