| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library testing.test_dart; | 5 library testing.test_dart; |
| 6 | 6 |
| 7 import 'dart:convert' show | 7 import 'dart:convert' show JSON; |
| 8 JSON; | |
| 9 | 8 |
| 10 import 'dart:io' show | 9 import 'dart:io' show Platform; |
| 11 Platform; | |
| 12 | 10 |
| 13 import 'suite.dart' show | 11 import 'suite.dart' show Suite; |
| 14 Suite; | |
| 15 | 12 |
| 16 /// A suite that runs test.dart. | 13 /// A suite that runs test.dart. |
| 17 class TestDart extends Suite { | 14 class TestDart extends Suite { |
| 18 final String common; | 15 final String common; |
| 19 | 16 |
| 20 final String processes; | 17 final String processes; |
| 21 | 18 |
| 22 final List<String> commandLines; | 19 final List<String> commandLines; |
| 23 | 20 |
| 24 TestDart(String name, this.common, this.processes, this.commandLines) | 21 TestDart(String name, this.common, this.processes, this.commandLines) |
| 25 : super(name, "test_dart", | 22 : super( |
| 26 // This suite doesn't know what it's status file is because test.dart | 23 name, |
| 27 // doesn't know. | 24 "test_dart", |
| 28 null); | 25 // This suite doesn't know what it's status file is because |
| 26 // test.dart doesn't know. |
| 27 null); |
| 29 | 28 |
| 30 factory TestDart.fromJsonMap(Uri base, Map json, String name, String kind) { | 29 factory TestDart.fromJsonMap(Uri base, Map json, String name, String kind) { |
| 31 String common = json["common"] ?? ""; | 30 String common = json["common"] ?? ""; |
| 32 String processes = json["processes"] ?? "-j${Platform.numberOfProcessors}"; | 31 String processes = json["processes"] ?? "-j${Platform.numberOfProcessors}"; |
| 33 List<String> commandLines = json["command-lines"] ?? <String>[]; | 32 List<String> commandLines = json["command-lines"] ?? <String>[]; |
| 34 return new TestDart(name, common, processes, commandLines); | 33 return new TestDart(name, common, processes, commandLines); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void writeFirstImportOn(StringSink sink) { | 36 void writeFirstImportOn(StringSink sink) { |
| 38 sink.writeln("import 'dart:io' as io;"); | 37 sink.writeln("import 'dart:io' as io;"); |
| 39 sink.writeln( | 38 sink.writeln( |
| 40 "import 'package:testing/src/stdio_process.dart' show StdioProcess;"); | 39 "import 'package:testing/src/stdio_process.dart' show StdioProcess;"); |
| 41 } | 40 } |
| 42 | 41 |
| 43 void writeRunCommandOn(StringSink sink) { | 42 void writeRunCommandOn(StringSink sink) { |
| 44 Uri dartVm; | 43 Uri dartVm; |
| 45 if (Platform.isMacOS) { | 44 if (Platform.isMacOS) { |
| 46 dartVm = Uri.base.resolve("tools/sdks/mac/dart-sdk/bin/dart"); | 45 dartVm = Uri.base.resolve("tools/sdks/mac/dart-sdk/bin/dart"); |
| 47 } else if (Platform.isWindows) { | 46 } else if (Platform.isWindows) { |
| 48 dartVm = Uri.base.resolve("tools/sdks/win/dart-sdk/bin/dart.exe"); | 47 dartVm = Uri.base.resolve("tools/sdks/win/dart-sdk/bin/dart.exe"); |
| 49 } else if (Platform.isLinux) { | 48 } else if (Platform.isLinux) { |
| 50 dartVm = Uri.base.resolve("tools/sdks/linux/dart-sdk/bin/dart"); | 49 dartVm = Uri.base.resolve("tools/sdks/linux/dart-sdk/bin/dart"); |
| 51 } else { | 50 } else { |
| 52 throw "Operating system not supported: ${Platform.operatingSystem}"; | 51 throw "Operating system not supported: ${Platform.operatingSystem}"; |
| 53 } | 52 } |
| 54 List<String> processedArguments = <String>[]; | 53 List<String> processedArguments = <String>[]; |
| 55 processedArguments.add(Uri.base.resolve( | 54 processedArguments.add(Uri.base |
| 56 "tools/testing/dart/package_testing_support.dart").toFilePath()); | 55 .resolve("tools/testing/dart/package_testing_support.dart") |
| 56 .toFilePath()); |
| 57 for (String commandLine in commandLines) { | 57 for (String commandLine in commandLines) { |
| 58 String arguments = common; | 58 String arguments = common; |
| 59 arguments += " $processes"; | 59 arguments += " $processes"; |
| 60 arguments += " $commandLine"; | 60 arguments += " $commandLine"; |
| 61 processedArguments.add(arguments); | 61 processedArguments.add(arguments); |
| 62 } | 62 } |
| 63 String executable = JSON.encode(dartVm.toFilePath()); | 63 String executable = JSON.encode(dartVm.toFilePath()); |
| 64 String arguments = JSON.encode(processedArguments); | 64 String arguments = JSON.encode(processedArguments); |
| 65 sink.write(""" | 65 sink.write(""" |
| 66 { | 66 { |
| 67 print('Running $arguments'); | 67 print('Running $arguments'); |
| 68 StdioProcess process = await StdioProcess.run($executable, $arguments, | 68 StdioProcess process = await StdioProcess.run($executable, $arguments, |
| 69 suppressOutput: false, timeout: null); | 69 suppressOutput: false, timeout: null); |
| 70 if (process.exitCode != 0) { | 70 if (process.exitCode != 0) { |
| 71 print(process.output); | 71 print(process.output); |
| 72 io.exitCode = 1; | 72 io.exitCode = 1; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 """); | 75 """); |
| 76 } | 76 } |
| 77 | 77 |
| 78 String toString() { | 78 String toString() { |
| 79 return "TestDart($name, ${JSON.encode(common)}, ${JSON.encode(processes)}," | 79 return "TestDart($name, ${JSON.encode(common)}, ${JSON.encode(processes)}," |
| 80 " ${JSON.encode(commandLines)})"; | 80 " ${JSON.encode(commandLines)})"; |
| 81 } | 81 } |
| 82 } | 82 } |
| OLD | NEW |