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

Unified Diff: sdk/lib/_internal/pub/test/test_pub.dart

Issue 354763006: Add a "pub global run" command. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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: sdk/lib/_internal/pub/test/test_pub.dart
diff --git a/sdk/lib/_internal/pub/test/test_pub.dart b/sdk/lib/_internal/pub/test/test_pub.dart
index 1f7d94ca492a4e34aa67915e3aef4a6cbaf2dc96..aaba6dc681bebdc5e7cf7e07ddb443293bb4ae77 100644
--- a/sdk/lib/_internal/pub/test/test_pub.dart
+++ b/sdk/lib/_internal/pub/test/test_pub.dart
@@ -225,7 +225,11 @@ Map<String, List<Map>> _servedPackages;
/// If [replace] is false, subsequent calls to [servePackages] will add to the
/// set of packages that are being served. Previous packages will continue to be
/// served. Otherwise, the previous packages will no longer be served.
-void servePackages(List<Map> pubspecs, {bool replace: false}) {
+///
+/// If [contents] is given, its contents are added to every served
+/// package.
+void servePackages(List<Map> pubspecs, {bool replace: false,
+ Iterable<d.Descriptor> contents}) {
if (_servedPackages == null || _servedPackageDir == null) {
_servedPackages = <String, List<Map>>{};
_servedApiPackageDir = d.dir('packages', []);
@@ -246,11 +250,11 @@ void servePackages(List<Map> pubspecs, {bool replace: false}) {
return awaitObject(pubspecs).then((resolvedPubspecs) {
if (replace) _servedPackages.clear();
- for (var spec in resolvedPubspecs) {
- var name = spec['name'];
- var version = spec['version'];
+ for (var pubspec in resolvedPubspecs) {
+ var name = pubspec['name'];
+ var version = pubspec['version'];
var versions = _servedPackages.putIfAbsent(name, () => []);
- versions.add(spec);
+ versions.add(pubspec);
}
_servedApiPackageDir.contents.clear();
@@ -273,10 +277,17 @@ void servePackages(List<Map> pubspecs, {bool replace: false}) {
_servedPackageDir.contents.add(d.dir(name, [
d.dir('versions', _servedPackages[name].map((pubspec) {
var version = pubspec['version'];
- return d.tar('$version.tar.gz', [
- d.file('pubspec.yaml', JSON.encode(pubspec)),
- d.libDir(name, '$name $version')
- ]);
+
+ var archiveContents = [
+ d.file('pubspec.yaml', JSON.encode(pubspec)),
+ d.libDir(name, '$name $version')
+ ];
+
+ if (contents != null) {
+ archiveContents.addAll(contents);
+ }
+
+ return d.tar('$version.tar.gz', archiveContents);
}))
]));
}
@@ -377,6 +388,35 @@ void pubUpgrade({Iterable<String> args, output, error, warning, int exitCode}) {
warning: warning, exitCode: exitCode);
}
+/// Schedules starting the "pub [global] run" process and validates the
+/// expected startup output.
+///
+/// If [global] is `true`, this invokes "pub global run", otherwise it does
+/// "pub run".
+///
+/// if [transformers] is given, it should contain a list of transformer IDs
+/// (like "myapp/src/transformer") and this will validate that the output for
+/// loading those is shown.
+///
+/// Returns the `pub run` process.
+ScheduledProcess pubRun({bool global: false, Iterable<String> args,
+ Iterable<String> transformers}) {
+ var pubArgs = global ? ["global", "run"] : ["run"];
+ pubArgs.addAll(args);
+ var pub = startPub(args: pubArgs);
+
+ // This isn't normally printed, but the pub test infrastructure runs pub in
+ // verbose mode, which enables this.
+ pub.stdout.expect(startsWith("Loading source assets"));
+
+ if (transformers != null) {
+ for (var transformer in transformers) {
+ pub.stdout.expect(startsWith("Loading $transformer transformers"));
nweiz 2014/07/02 00:12:03 Rather than requiring tests to pass in a list of t
Bob Nystrom 2014/07/02 18:00:53 Done.
+ }
+ }
+ return pub;
+}
+
/// Defines an integration test.
///
/// The [body] should schedule a series of operations which will be run
@@ -670,6 +710,42 @@ void ensureGit() {
}
}
+/// Schedules activating a global package [package] without running
+/// "pub global activate".
+///
+/// This is useful because global packages must be hosted, but the test hosted
+/// server doesn't serve barback. The other parameters here follow
+/// [createLockFile].
+void makeGlobalPackage(String package, String version,
+ Iterable<d.Descriptor> contents, {Iterable<String> pkg,
+ Map<String, String> hosted}) {
+ // Start the server so we know what port to use in the cache directory name.
+ servePackages([]);
+
+ // Create the package in the hosted cache.
+ d.hostedCache([
+ 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());
+
+ d.dir(cachePath, [
+ d.dir("global_packages", [
+ d.file("$package.lock", lockFile.serialize(null, sources))
+ ])
+ ]).create();
+}
+
/// Creates a lock file for [package] without running `pub get`.
///
/// [sandbox] is a list of path dependencies to be found in the sandbox
@@ -681,6 +757,27 @@ void ensureGit() {
/// 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(path.join(package, 'pubspec.lock'),
+ lockFile.serialize(null, sources)).create();
+}
+
+/// Creates a lock file for [package] without running `pub get`.
+///
+/// [sandbox] is a list of path dependencies to be found in the sandbox
+/// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory;
+/// each package listed here and all its dependencies will be linked to the
+/// version in the Dart repo.
+///
+/// [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}) {
var dependencies = {};
if (sandbox != null) {
@@ -697,8 +794,8 @@ void createLockFile(String package, {Iterable<String> sandbox,
if (package == 'barback') {
if (_barbackDir == null) {
throw new StateError("createLockFile() can only create a lock file "
- "with a barback dependency within a withBarbackVersions() "
- "block.");
+ "with a barback dependency within a withBarbackVersions() "
+ "block.");
nweiz 2014/07/02 00:12:03 Fix this indentation.
Bob Nystrom 2014/07/02 18:00:53 Done.
}
packagePath = _barbackDir;
} else {
@@ -707,7 +804,7 @@ void createLockFile(String package, {Iterable<String> sandbox,
dependencies[package] = packagePath;
var pubspec = loadYaml(
- readTextFile(path.join(packagePath, 'pubspec.yaml')));
+ readTextFile(path.join(packagePath, 'pubspec.yaml')));
nweiz 2014/07/02 00:12:02 Also this indentation.
Bob Nystrom 2014/07/02 18:00:53 Done.
var packageDeps = pubspec['dependencies'];
if (packageDeps == null) return;
packageDeps.keys.forEach(_addPackage);
@@ -732,12 +829,7 @@ void createLockFile(String package, {Iterable<String> sandbox,
});
}
- var sources = new SourceRegistry();
- sources.register(new HostedSource());
- sources.register(new PathSource());
-
- d.file(path.join(package, 'pubspec.lock'),
- lockFile.serialize(null, sources)).create();
+ return lockFile;
}
/// Uses [client] as the mock HTTP client for this test.

Powered by Google App Engine
This is Rietveld 408576698