Look for the new snapshot error message from the Dart 2 VM. (#1938)

* Look for the new snapshot error message from the Dart 2 VM.

* Reformat.
diff --git a/lib/src/command/run.dart b/lib/src/command/run.dart
index 59585c7..c7c70c8 100644
--- a/lib/src/command/run.dart
+++ b/lib/src/command/run.dart
@@ -61,8 +61,8 @@
     // to actually execute will always have one.
     if (p.extension(executable) != ".dart") executable += ".dart";
 
-    var snapshotPath =
-        p.join(entrypoint.cachePath, "bin", package, "$executable.snapshot.dart2");
+    var snapshotPath = p.join(
+        entrypoint.cachePath, "bin", package, "$executable.snapshot.dart2");
 
     // Don't ever compile snapshots for mutable packages, since their code may
     // change later on.
diff --git a/lib/src/dart.dart b/lib/src/dart.dart
index 5b26b8f..11e6ae8 100644
--- a/lib/src/dart.dart
+++ b/lib/src/dart.dart
@@ -59,8 +59,8 @@
     // Don't leave partial results.
     deleteEntry(snapshotPath);
 
-    throw new ApplicationException(log.yellow("Failed to precompile $name:\n") +
-        result.stderr.join('\n'));
+    throw new ApplicationException(
+        log.yellow("Failed to precompile $name:\n") + result.stderr.join('\n'));
   }
 }
 
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart
index e317f0b..719872d 100644
--- a/lib/src/entrypoint.dart
+++ b/lib/src/entrypoint.dart
@@ -242,8 +242,8 @@
       deleteEntry(packagesPath);
     }
 
-    await Future
-        .wait(result.packages.map((id) => _get(id, packagesDir: packagesDir)));
+    await Future.wait(
+        result.packages.map((id) => _get(id, packagesDir: packagesDir)));
     _saveLockFile(result);
 
     if (packagesDir) _linkSelf();
@@ -304,7 +304,8 @@
       cleanDir(dir);
       return waitAndPrintErrors(executables[package].map((path) {
         var url = p.toUri(p.join(packageGraph.packages[package].dir, path));
-        return dart.snapshot(url, p.join(dir, p.basename(path) + '.snapshot.dart2'),
+        return dart.snapshot(
+            url, p.join(dir, p.basename(path) + '.snapshot.dart2'),
             packagesFile: p.toUri(packagesFile),
             name: '$package:${p.basenameWithoutExtension(path)}');
       }));
@@ -368,8 +369,8 @@
     // some executables do exist and some do not, the directory is corrupted and
     // it's good to start from scratch anyway.
     var executablesExist = executables.every((executable) {
-      var snapshotPath = p.join(
-          _snapshotPath, packageName, "${p.basename(executable)}.snapshot.dart2");
+      var snapshotPath = p.join(_snapshotPath, packageName,
+          "${p.basename(executable)}.snapshot.dart2");
       return fileExists(snapshotPath);
     });
     if (!executablesExist) return executables;
diff --git a/lib/src/executable.dart b/lib/src/executable.dart
index e14d875..cb146d8 100644
--- a/lib/src/executable.dart
+++ b/lib/src/executable.dart
@@ -168,7 +168,9 @@
         packageConfig: packageConfig);
   } on IsolateSpawnException catch (error) {
     if (recompile == null) rethrow;
-    if (!error.message.contains("Wrong script snapshot version")) rethrow;
+    if (!error.message.contains("Invalid kernel binary format version")) {
+      rethrow;
+    }
 
     log.fine("Precompiled executable is out of date.");
     await recompile();
diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart
index a621d1a..ce528df 100644
--- a/lib/src/global_packages.dart
+++ b/lib/src/global_packages.dart
@@ -387,7 +387,8 @@
             entrypoint.isCached ? _getPackagesFilePath(package) : null,
         // Don't use snapshots for executables activated from paths.
         snapshotPath: entrypoint.isCached
-            ? p.join(_directory, package, 'bin', '$executable.dart.snapshot.dart2')
+            ? p.join(
+                _directory, package, 'bin', '$executable.dart.snapshot.dart2')
             : null,
         recompile: () => _precompileExecutables(entrypoint, package));
   }
diff --git a/lib/src/io.dart b/lib/src/io.dart
index 43fe62d..5c48153 100644
--- a/lib/src/io.dart
+++ b/lib/src/io.dart
@@ -597,8 +597,8 @@
 /// exited already. This is useful to prevent Future chains from proceeding
 /// after you've decided to exit.
 Future flushThenExit(int status) {
-  return Future
-      .wait([stdout.close(), stderr.close()]).then((_) => exit(status));
+  return Future.wait([stdout.close(), stderr.close()])
+      .then((_) => exit(status));
 }
 
 /// Returns a [EventSink] that pipes all data to [consumer] and a [Future] that
diff --git a/lib/src/validator.dart b/lib/src/validator.dart
index e7aeccc..b8598d8 100644
--- a/lib/src/validator.dart
+++ b/lib/src/validator.dart
@@ -127,8 +127,7 @@
       validators.add(new SizeValidator(entrypoint, packageSize));
     }
 
-    return Future
-        .wait(validators.map((validator) => validator.validate()))
+    return Future.wait(validators.map((validator) => validator.validate()))
         .then((_) {
       var errors = validators.expand((validator) => validator.errors).toList();
       var warnings =
diff --git a/test/global/binstubs/outdated_snapshot_test.dart b/test/global/binstubs/outdated_snapshot_test.dart
index 9f4b1ba..5c9167a 100644
--- a/test/global/binstubs/outdated_snapshot_test.dart
+++ b/test/global/binstubs/outdated_snapshot_test.dart
@@ -28,7 +28,7 @@
     await d.dir(cachePath, [
       d.dir('global_packages', [
         d.dir('foo', [
-          d.dir('bin', [d.outOfDateSnapshot('script.dart.snapshot')])
+          d.dir('bin', [d.outOfDateSnapshot('script.dart.snapshot.dart2')])
         ])
       ])
     ]).create();
@@ -38,14 +38,15 @@
         ["arg1", "arg2"],
         environment: getEnvironment());
 
-    expect(process.stderr, emits(startsWith("Wrong script snapshot version")));
+    expect(process.stderr,
+        emits(contains("Invalid kernel binary format version.")));
     expect(process.stdout, emitsThrough("ok [arg1, arg2]"));
     await process.shouldExit();
 
     await d.dir(cachePath, [
       d.dir('global_packages/foo/bin', [
         d.file(
-            'script.dart.snapshot',
+            'script.dart.snapshot.dart2',
             isNot(equals(
                 readBinaryFile(testAssetPath('out-of-date.snapshot.dart2')))))
       ])
diff --git a/test/global/binstubs/utils.dart b/test/global/binstubs/utils.dart
index e8f9e6e..8f990e9 100644
--- a/test/global/binstubs/utils.dart
+++ b/test/global/binstubs/utils.dart
@@ -12,6 +12,16 @@
 /// their PATH, so we need to spawn the binstub process with a PATH that
 /// explicitly includes it.
 Map getEnvironment() {
+  // TODO(rnystrom): This doesn't do the right thing when running pub's tests
+  // from pub's own repo instead of from within the Dart SDK repo. This always
+  // sets up the PATH to point to the directory where the Dart VM was run from,
+  // which will be unrelated to the path where pub itself is located when
+  // running from pub's repo.
+  //
+  // However, pub's repo doesn't actually have the shell scripts required to
+  // run "pub". Those live in the Dart SDK repo. One fix would be to make shell
+  // scripts in pub's repo that can act like those scripts but invoke pub from
+  // source from the pub repo.
   var binDir = p.dirname(Platform.executable);
   var separator = Platform.isWindows ? ";" : ":";
   var path = "${Platform.environment["PATH"]}$separator$binDir";
diff --git a/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart b/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart
index 779f07b..3c32d8c 100644
--- a/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart
+++ b/test/global/run/recompiles_if_snapshot_is_out_of_date_test.dart
@@ -20,7 +20,7 @@
     await d.dir(cachePath, [
       d.dir('global_packages', [
         d.dir('foo', [
-          d.dir('bin', [d.outOfDateSnapshot('script.dart.snapshot')])
+          d.dir('bin', [d.outOfDateSnapshot('script.dart.snapshot.dart2')])
         ])
       ])
     ]).create();
@@ -35,7 +35,7 @@
     await d.dir(cachePath, [
       d.dir('global_packages', [
         d.dir('foo', [
-          d.dir('bin', [d.file('script.dart.snapshot', contains('ok'))])
+          d.dir('bin', [d.file('script.dart.snapshot.dart2', contains('ok'))])
         ])
       ])
     ]).validate();
diff --git a/test/global/run/runs_script_in_checked_mode_test.dart b/test/global/run/runs_script_in_checked_mode_test.dart
index 889eef6..86af689 100644
--- a/test/global/run/runs_script_in_checked_mode_test.dart
+++ b/test/global/run/runs_script_in_checked_mode_test.dart
@@ -18,8 +18,7 @@
     await runPub(args: ["global", "activate", "foo"]);
 
     var pub = await pubRun(global: true, args: ["--checked", "foo:script"]);
-    expect(pub.stderr,
-        emitsThrough(contains("Failed assertion")));
+    expect(pub.stderr, emitsThrough(contains("Failed assertion")));
     await pub.shouldExit(255);
   });
 }
diff --git a/test/test_pub.dart b/test/test_pub.dart
index c93bb8d..6c55a8d 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -200,8 +200,7 @@
 /// "pub run".
 ///
 /// Returns the `pub run` process.
-Future<PubProcess> pubRun(
-    {bool global: false, Iterable<String> args}) async {
+Future<PubProcess> pubRun({bool global: false, Iterable<String> args}) async {
   var pubArgs = global ? ["global", "run"] : ["run"];
   pubArgs.addAll(args);
   var pub = await startPub(args: pubArgs);
@@ -250,9 +249,7 @@
   assert(output == null || outputJson == null);
 
   var pub = await startPub(
-      args: args,
-      workingDirectory: workingDirectory,
-      environment: environment);
+      args: args, workingDirectory: workingDirectory, environment: environment);
   await pub.shouldExit(exitCode);
 
   expect(() async {