[standalone] Restore --snapshot without --snapshot-kind generating a script snapshot.

Broken in d7845c6a6f44b371f3e6aff652b55c9365cd0a67

Issue #30790

Change-Id: Ifbe95a88e5b06d6d7fd1061bd26975262ac97515
Reviewed-on: https://dart-review.googlesource.com/6765
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc
index 141b055..75194d7 100644
--- a/runtime/bin/main_options.cc
+++ b/runtime/bin/main_options.cc
@@ -425,6 +425,11 @@
     return -1;
   }
 
+  // If --snapshot is given without --snapshot-kind, default to script snapshot.
+  if ((snapshot_filename_ != NULL) && (gen_snapshot_kind_ == kNone)) {
+    gen_snapshot_kind_ = kScript;
+  }
+
   return 0;
 }
 
diff --git a/tests/standalone/script_snapshot_not_executed_test.dart b/tests/standalone/script_snapshot_not_executed_test.dart
new file mode 100644
index 0000000..f002270
--- /dev/null
+++ b/tests/standalone/script_snapshot_not_executed_test.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "dart:io";
+
+void main(List<String> args) {
+  if (args.contains("--child")) {
+    print("Hello, pre-scanned world!");
+  } else {
+    runSnapshot(generateSnapshot());
+  }
+}
+
+generateSnapshot() {
+  var tempDir = Directory.systemTemp.createTempSync("script-snapshot");
+  var snapshotPath = tempDir.uri.resolve("hello.snapshot").toFilePath();
+
+  var exec = Platform.resolvedExecutable;
+  var args = new List();
+  args.addAll(Platform.executableArguments);
+  args.add("--snapshot=$snapshotPath");
+  args.add(Platform.script.toFilePath());
+  args.add("--child");
+  var result = Process.runSync(exec, args);
+  if (result.exitCode != 0) {
+    throw "Bad exit code: ${result.exitCode}";
+  }
+  if (result.stdout.contains("Hello, pre-scanned world!")) {
+    print(result.stdout);
+    throw "Should not have run the script.";
+  }
+
+  return snapshotPath;
+}
+
+runSnapshot(var snapshotPath) {
+  var exec = Platform.resolvedExecutable;
+  var args = new List();
+  args.addAll(Platform.executableArguments);
+  args.add(snapshotPath);
+  args.add("--child");
+  var result = Process.runSync(exec, args);
+  if (result.exitCode != 0) {
+    throw "Bad exit code: ${result.exitCode}";
+  }
+  if (!result.stdout.contains("Hello, pre-scanned world!")) {
+    print(result.stdout);
+    throw "Failed to run the snapshot.";
+  }
+}
diff --git a/tests/standalone/standalone.status b/tests/standalone/standalone.status
index 9a2f581..7d0480e 100644
--- a/tests/standalone/standalone.status
+++ b/tests/standalone/standalone.status
@@ -101,6 +101,9 @@
 [ $runtime != vm || $arch == arm || $arch == arm64 || ($system == windows && $mode == debug) ]
 fragmentation_test: Skip # VM test uses too much memory for small systems.
 
+[ $runtime != vm || $compiler != none ]
+script_snapshot_not_executed_test: SkipByDesign # Only makes sense running from source.
+
 [ $arch == simarm || $arch == simarmv6 || $arch == simarmv5te ]
 out_of_memory_test: Skip # passes on Mac, crashes on Linux
 oom_error_stacktrace_test: Skip # Fails on Linux