Index: pkg/testing/lib/src/test_dart.dart |
diff --git a/pkg/testing/lib/src/test_dart.dart b/pkg/testing/lib/src/test_dart.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8c89ed5fa9a097e9f70a495c2583c1dc5fb042b9 |
--- /dev/null |
+++ b/pkg/testing/lib/src/test_dart.dart |
@@ -0,0 +1,83 @@ |
+// Copyright (c) 2016, 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.md file. |
+ |
+library testing.test_dart; |
+ |
+import 'dart:convert' show |
+ JSON; |
+ |
+import 'dart:io' show |
+ Platform; |
+ |
+import 'suite.dart' show |
+ Suite; |
+ |
+/// A suite that runs test.dart. |
+class TestDart extends Suite { |
+ final String common; |
+ |
+ final String processes; |
+ |
+ final List<String> commandLines; |
+ |
+ TestDart(String name, this.common, this.processes, this.commandLines) |
+ : super(name, "test_dart", |
+ // This suite doesn't know what it's status file is because test.dart |
+ // doesn't know. |
+ null); |
+ |
+ factory TestDart.fromJsonMap(Uri base, Map json, String name, String kind) { |
+ String common = json["common"] ?? ""; |
+ // TODO(ahe): Compute this value based on number of cores. |
+ String processes = json["processes"] ?? "-j16"; |
+ List<String> commandLines = json["command-lines"] ?? <String>[]; |
+ return new TestDart(name, common, processes, commandLines); |
+ } |
+ |
+ void writeFirstImportOn(StringSink sink) { |
+ sink.writeln("import 'dart:io' as io;"); |
+ sink.writeln( |
+ "import 'package:testing/src/stdio_process.dart' show StdioProcess;"); |
+ } |
+ |
+ void writeRunCommandOn(StringSink sink) { |
+ Uri dartVm; |
+ if (Platform.isMacOS) { |
+ dartVm = Uri.base.resolve("tools/sdks/mac/dart-sdk/bin/dart"); |
+ } else if (Platform.isWindows) { |
+ dartVm = Uri.base.resolve("tools/sdks/win/dart-sdk/bin/dart.exe"); |
+ } else if (Platform.isLinux) { |
+ dartVm = Uri.base.resolve("tools/sdks/linux/dart-sdk/bin/dart"); |
+ } else { |
+ throw "Operating system not supported: ${Platform.operatingSystem}"; |
+ } |
+ List<String> processedArguments = <String>[]; |
+ processedArguments.add(Uri.base.resolve( |
+ "tools/testing/dart/package_testing_support.dart").toFilePath()); |
+ for (String commandLine in commandLines) { |
+ String arguments = common; |
+ arguments += " $processes"; |
+ arguments += " $commandLine"; |
+ processedArguments.add(arguments); |
+ } |
+ String executable = JSON.encode(dartVm.toFilePath()); |
+ String arguments = JSON.encode(processedArguments); |
+ sink.write(""" |
+ { |
+ print('Running $arguments'); |
+ StdioProcess process = await StdioProcess.run($executable, $arguments, |
+ suppressOutput: false, timeout: null); |
+ if (process.exitCode != 0) { |
+ print(process.output); |
+ io.exitCode = 1; |
+ } |
+ } |
+"""); |
+ } |
+ |
+ String toString() { |
+ return "TestDart($name, ${JSON.encode(common)}, ${JSON.encode(processes)}," |
+ " ${JSON.encode(commandLines)})"; |
+ } |
+} |