| 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 testFn(description, () { | 882 testFn(description, () { |
| 883 var cache = new SystemCache('.'); | 883 var cache = new SystemCache('.'); |
| 884 source1 = new MockSource('mock1'); | 884 source1 = new MockSource('mock1'); |
| 885 source2 = new MockSource('mock2'); | 885 source2 = new MockSource('mock2'); |
| 886 cache.register(source1); | 886 cache.register(source1); |
| 887 cache.register(source2); | 887 cache.register(source2); |
| 888 cache.sources.setDefault(source1.name); | 888 cache.sources.setDefault(source1.name); |
| 889 | 889 |
| 890 // Build the test package graph. | 890 // Build the test package graph. |
| 891 var root; | 891 var root; |
| 892 packages.forEach((nameVersion, dependencies) { | 892 packages.forEach((description, dependencies) { |
| 893 var parsed = parseSource(nameVersion, (isDev, nameVersion, source) { | 893 var id = parseSpec(description); |
| 894 var parts = nameVersion.split(' '); | 894 var package = mockPackage(id, dependencies); |
| 895 var name = parts[0]; | 895 if (id.name == 'myapp') { |
| 896 var version = parts[1]; | 896 // Don't add the root package to the server, so we can verify that Pub |
| 897 | 897 // doesn't try to look up information about the local package on the |
| 898 var package = mockPackage(name, version, dependencies); | 898 // remote server. |
| 899 if (name == 'myapp') { | 899 root = package; |
| 900 // Don't add the root package to the server, so we can verify that Pub | 900 } else { |
| 901 // doesn't try to look up information about the local package on the | 901 (cache.sources[id.source] as MockSource).addPackage( |
| 902 // remote server. | 902 id.description, package); |
| 903 root = package; | 903 } |
| 904 } else { | |
| 905 (cache.sources[source] as MockSource).addPackage(name, package); | |
| 906 } | |
| 907 }); | |
| 908 }); | 904 }); |
| 909 | 905 |
| 910 // Clean up the expectation. | 906 // Clean up the expectation. |
| 911 if (result != null) { | 907 if (result != null) { |
| 912 var newResult = {}; | 908 var newResult = {}; |
| 913 result.forEach((name, version) { | 909 result.forEach((description, version) { |
| 914 parseSource(name, (isDev, name, source) { | 910 var id = parseSpec(description, version); |
| 915 version = new Version.parse(version); | 911 newResult[id.name] = id; |
| 916 newResult[name] = new PackageId(name, source, version, name); | |
| 917 }); | |
| 918 }); | 912 }); |
| 919 result = newResult; | 913 result = newResult; |
| 920 } | 914 } |
| 921 | 915 |
| 916 // Parse the lockfile. |
| 922 var realLockFile = new LockFile.empty(); | 917 var realLockFile = new LockFile.empty(); |
| 923 if (lockfile != null) { | 918 if (lockfile != null) { |
| 924 lockfile.forEach((name, version) { | 919 lockfile.forEach((name, version) { |
| 925 version = new Version.parse(version); | 920 version = new Version.parse(version); |
| 926 realLockFile.packages[name] = | 921 realLockFile.packages[name] = |
| 927 new PackageId(name, source1.name, version, name); | 922 new PackageId(name, source1.name, version, name); |
| 928 }); | 923 }); |
| 929 } | 924 } |
| 930 | 925 |
| 931 // Make a version number like the continuous build's version. | 926 // Make a version number like the continuous build's version. |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 Future<bool> get(PackageId id, String path) { | 1183 Future<bool> get(PackageId id, String path) { |
| 1189 throw new Exception('no'); | 1184 throw new Exception('no'); |
| 1190 } | 1185 } |
| 1191 | 1186 |
| 1192 void addPackage(String description, Package package) { | 1187 void addPackage(String description, Package package) { |
| 1193 _packages.putIfAbsent(description, () => new Map<Version, Package>()); | 1188 _packages.putIfAbsent(description, () => new Map<Version, Package>()); |
| 1194 _packages[description][package.version] = package; | 1189 _packages[description][package.version] = package; |
| 1195 } | 1190 } |
| 1196 } | 1191 } |
| 1197 | 1192 |
| 1198 Package mockPackage(String description, String version, | 1193 Package mockPackage(PackageId id, Map dependencyStrings) { |
| 1199 Map dependencyStrings) { | |
| 1200 var sdkConstraint = null; | 1194 var sdkConstraint = null; |
| 1201 | 1195 |
| 1202 // Build the pubspec dependencies. | 1196 // Build the pubspec dependencies. |
| 1203 var dependencies = <PackageDep>[]; | 1197 var dependencies = <PackageDep>[]; |
| 1204 var devDependencies = <PackageDep>[]; | 1198 var devDependencies = <PackageDep>[]; |
| 1205 | 1199 |
| 1206 dependencyStrings.forEach((name, constraint) { | 1200 dependencyStrings.forEach((description, constraint) { |
| 1207 parseSource(name, (isDev, name, source) { | 1201 var isDev = description.startsWith("(dev) "); |
| 1208 var packageName = name.replaceFirst(new RegExp(r"-[^-]+$"), ""); | 1202 if (isDev) { |
| 1209 constraint = new VersionConstraint.parse(constraint); | 1203 description = description.substring("(dev) ".length); |
| 1204 } |
| 1210 | 1205 |
| 1211 if (name == 'sdk') { | 1206 var dep = parseSpec(description).withConstraint( |
| 1212 sdkConstraint = constraint; | 1207 new VersionConstraint.parse(constraint)); |
| 1213 return; | |
| 1214 } | |
| 1215 | 1208 |
| 1216 var dep = new PackageDep(packageName, source, constraint, name); | 1209 if (dep.name == 'sdk') { |
| 1210 sdkConstraint = dep.constraint; |
| 1211 return; |
| 1212 } |
| 1217 | 1213 |
| 1218 if (isDev) { | 1214 if (isDev) { |
| 1219 devDependencies.add(dep); | 1215 devDependencies.add(dep); |
| 1220 } else { | 1216 } else { |
| 1221 dependencies.add(dep); | 1217 dependencies.add(dep); |
| 1222 } | 1218 } |
| 1223 }); | |
| 1224 }); | 1219 }); |
| 1225 | 1220 |
| 1226 var name = description.replaceFirst(new RegExp(r"-[^-]+$"), ""); | 1221 var pubspec = new Pubspec(id.name, id.version, dependencies, |
| 1227 var pubspec = new Pubspec( | 1222 devDependencies, new PubspecEnvironment(sdkConstraint), []); |
| 1228 name, new Version.parse(version), dependencies, devDependencies, | |
| 1229 new PubspecEnvironment(sdkConstraint), []); | |
| 1230 return new Package.inMemory(pubspec); | 1223 return new Package.inMemory(pubspec); |
| 1231 } | 1224 } |
| 1232 | 1225 |
| 1233 void parseSource(String description, | 1226 /// Creates a new [PackageId] parsed from [text], which looks something like |
| 1234 callback(bool isDev, String name, String source)) { | 1227 /// this: |
| 1235 var isDev = false; | 1228 /// |
| 1236 | 1229 /// foo-xyz 1.0.0 from mock |
| 1237 if (description.startsWith("(dev) ")) { | 1230 /// |
| 1238 description = description.substring("(dev) ".length); | 1231 /// The package name is "foo". A hyphenated suffix like "-xyz" here is part |
| 1239 isDev = true; | 1232 /// of the package description, but not its name, so the description here is |
| 1233 /// "foo-xyz". |
| 1234 /// |
| 1235 /// This is followed by an optional [Version]. If [version] is provided, then |
| 1236 /// it is parsed to a [Version], and [text] should *not* also contain a |
| 1237 /// version string. |
| 1238 /// |
| 1239 /// The "from mock" optional suffix is the name of a source for the package. |
| 1240 /// If omitted, it defaults to "mock1". |
| 1241 PackageId parseSpec(String text, [String version]) { |
| 1242 var pattern = new RegExp(r"(([a-z]*)(-[a-z]+)?)( ([^ ]+))?( from (.*))?$"); |
| 1243 var match = pattern.firstMatch(text); |
| 1244 if (match == null) { |
| 1245 throw new FormatException("Could not parse spec '$text'."); |
| 1240 } | 1246 } |
| 1241 | 1247 |
| 1242 var name = description; | 1248 var description = match[1]; |
| 1249 var name = match[2]; |
| 1250 |
| 1251 var parsedVersion; |
| 1252 if (version != null) { |
| 1253 // Spec string shouldn't also contain a version. |
| 1254 if (match[5] != null) { |
| 1255 throw new ArgumentError("Spec '$text' should not contain a version " |
| 1256 "since '$version' was passed in explicitly."); |
| 1257 } |
| 1258 parsedVersion = new Version.parse(version); |
| 1259 } else { |
| 1260 if (match[5] != null) { |
| 1261 parsedVersion = new Version.parse(match[5]); |
| 1262 } else { |
| 1263 parsedVersion = Version.none; |
| 1264 } |
| 1265 } |
| 1266 |
| 1243 var source = "mock1"; | 1267 var source = "mock1"; |
| 1244 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); | 1268 if (match[7] != null) { |
| 1245 if (match != null) { | 1269 source = match[7]; |
| 1246 name = match[1]; | |
| 1247 source = match[2]; | |
| 1248 if (source == "root") source = null; | 1270 if (source == "root") source = null; |
| 1249 } | 1271 } |
| 1250 | 1272 |
| 1251 callback(isDev, name, source); | 1273 return new PackageId(name, source, parsedVersion, description); |
| 1252 } | 1274 } |
| OLD | NEW |