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

Unified Diff: test/test_pub.dart

Issue 1281043004: Make LockFile immutable. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: test/test_pub.dart
diff --git a/test/test_pub.dart b/test/test_pub.dart
index 86376eafb1ba80e3a73f529d41504c4444e9bb97..98bd83f81c402a77ff649973144d6c2f0f67c710 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -691,21 +691,23 @@ void makeGlobalPackage(String package, String version,
d.dir("$package-$version", contents)
]).create();
- var lockFile = _createLockFile(pkg: pkg, hosted: hosted);
-
- // Add the root package to the lockfile.
- var id = new PackageId(package, "hosted", new Version.parse(version),
- package);
- lockFile.packages[package] = id;
-
// Write the lockfile to the global cache.
var sources = new SourceRegistry();
sources.register(new HostedSource());
sources.register(new PathSource());
+ var lockFile = _createLockFile(sources, pkg: pkg, hosted: hosted);
+
+ // Add the root package to the lockfile.
+ var id = new PackageId(package, "hosted", new Version.parse(version),
+ package);
+ var packages = lockFile.packages.values.toList();
+ packages.add(id);
+ lockFile = new LockFile(packages, sources);
Bob Nystrom 2015/08/07 21:50:56 This code is a bit grungy. How about adding a meth
nweiz 2015/08/07 22:16:07 Done.
+
d.dir(cachePath, [
d.dir("global_packages", [
- d.file("$package.lock", lockFile.serialize(null, sources))
+ d.file("$package.lock", lockFile.serialize(null))
])
]).create();
}
@@ -721,14 +723,14 @@ void makeGlobalPackage(String package, String version,
/// hosted packages.
void createLockFile(String package, {Iterable<String> sandbox,
Iterable<String> pkg, Map<String, String> hosted}) {
- var lockFile = _createLockFile(sandbox: sandbox, pkg: pkg, hosted: hosted);
-
var sources = new SourceRegistry();
sources.register(new HostedSource());
sources.register(new PathSource());
- d.file(p.join(package, 'pubspec.lock'),
- lockFile.serialize(null, sources)).create();
+ var lockFile = _createLockFile(sources,
+ sandbox: sandbox, pkg: pkg, hosted: hosted);
+
+ d.file(p.join(package, 'pubspec.lock'), lockFile.serialize(null)).create();
}
/// Creates a lock file for [package] without running `pub get`.
@@ -740,8 +742,8 @@ void createLockFile(String package, {Iterable<String> sandbox,
///
/// [hosted] is a list of package names to version strings for dependencies on
/// hosted packages.
-LockFile _createLockFile({Iterable<String> sandbox,
-Iterable<String> pkg, Map<String, String> hosted}) {
+LockFile _createLockFile(SourceRegistry sources, {Iterable<String> sandbox,
+ Iterable<String> pkg, Map<String, String> hosted}) {
var dependencies = {};
if (sandbox != null) {
@@ -778,23 +780,22 @@ Iterable<String> pkg, Map<String, String> hosted}) {
pkg.forEach(_addPackage);
}
- var lockFile = new LockFile.empty();
- dependencies.forEach((name, dependencyPath) {
- var id = new PackageId(name, 'path', new Version(0, 0, 0), {
+ var packages = dependencies.keys.map((name) {
+ var dependencyPath = dependencies[name];
+ return new PackageId(name, 'path', new Version(0, 0, 0), {
'path': dependencyPath,
'relative': p.isRelative(dependencyPath)
});
- lockFile.packages[name] = id;
- });
+ }).toList();
if (hosted != null) {
hosted.forEach((name, version) {
var id = new PackageId(name, 'hosted', new Version.parse(version), name);
- lockFile.packages[name] = id;
+ packages.add(id);
});
}
- return lockFile;
+ return new LockFile(packages, sources);
}
/// Returns the path to the version of [package] used by pub.

Powered by Google App Engine
This is Rietveld 408576698