Chromium Code Reviews| Index: pkg/front_end/test/fasta/tool_test.dart |
| diff --git a/pkg/front_end/test/fasta/tool_test.dart b/pkg/front_end/test/fasta/tool_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..36033a5ea1eb7505b782e32bc844e6938f3e5394 |
| --- /dev/null |
| +++ b/pkg/front_end/test/fasta/tool_test.dart |
| @@ -0,0 +1,165 @@ |
| +// 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 file. |
| + |
| +/// Tests the tool `pkg/front_end/tool/fasta`. |
|
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
yay!
ahe
2017/08/24 11:52:02
Acknowledged.
|
| + |
| +import "dart:convert"; |
| + |
| +import "dart:io"; |
| + |
| +import "package:expect/expect.dart"; |
| + |
| +import "package:front_end/src/fasta/fasta_codes.dart" |
| + show messageFastaUsageShort; |
| + |
| +const String toolPath = "pkg/front_end/tool/fasta"; |
| + |
| +const List<String> subtools = const <String>[ |
| + "abcompile", |
| + "analyzer-compile", |
| + "compile", |
| + "compile-platform", |
| + "compile-platform-dartk", |
| + "log", |
| + "logd", |
| + "outline", |
| + "parser", |
| + "run", |
| + "scanner", |
| + "dump-partial", |
| + "dump-ir", |
| + "kernel-service", |
| + "testing", |
| + "generate-messages", |
| +]; |
| + |
| +const List<String> unsafeTools = const <String>[ |
|
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
Please document what does it mean for a tool to be
ahe
2017/08/24 11:52:02
Done.
|
| + "generate-messages", |
| + "logd", |
| + "testing", |
| +]; |
| + |
| +const JsonEncoder prettyJson = const JsonEncoder.withIndent(" "); |
| + |
| +main() { |
| + if (!Platform.isMacOS && !Platform.isLinux) { |
| + // The tool is a shell script and only works on Mac and Linux. |
|
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
should we replace it with a Dart script?
ahe
2017/08/24 11:52:02
Yes. I've added a TODO to the script.
|
| + return; |
| + } |
| + Set<String> testedSubtools = new Set<String>.from(subtools) |
| + .difference(new Set<String>.from(unsafeTools)); |
| + Map<String, Map<String, dynamic>> resultMap = |
| + <String, Map<String, dynamic>>{}; |
| + for (String subtool in testedSubtools) { |
| + print("Testing $subtool"); |
| + ProcessResult result = |
| + Process.runSync("/bin/bash", <String>[toolPath, subtool]); |
|
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
should we also run all tools with a good example s
ahe
2017/08/24 11:52:02
For now, I assume that happens as part of our regu
|
| + resultMap[subtool] = { |
| + "exitCode": result.exitCode, |
| + "stdout": result.stdout, |
| + "stderr": result.stderr, |
| + }; |
| + } |
| + Map<String, dynamic> scanner = resultMap["scanner"]; |
| + Expect.isTrue(scanner["stdout"].startsWith("Reading files took: ")); |
| + scanner.remove("stdout"); |
| + |
| + Map<String, dynamic> kernelService = resultMap["kernel-service"]; |
| + Expect.isTrue(kernelService["stderr"].startsWith("Usage: dart [")); |
| + kernelService.remove("stderr"); |
| + |
| + String jsonResult = prettyJson.convert(resultMap); |
| + String usage = messageFastaUsageShort.message; |
| + |
| + String jsonExpectation = prettyJson.convert({ |
| + "abcompile": { |
| + "exitCode": 1, |
| + "stdout": """[] |
| +Expected -DbRoot=/absolute/path/to/other/sdk/repo |
| +""", |
| + "stderr": "", |
| + }, |
| + "analyzer-compile": { |
| + "exitCode": 2, |
| + "stdout": "", |
| + "stderr": "'analyzer-compile' isn't supported anymore," |
| + " please use 'compile' instead.\n", |
| + }, |
| + "compile": { |
| + "exitCode": 1, |
| + "stdout": """Usage: compile [options] dartfile |
| + |
| +Compiles a Dart program to the Dill/Kernel IR format. |
| + |
| +$usage |
| +Error: No Dart file specified. |
| +""", |
| + "stderr": "", |
| + }, |
| + "compile-platform": { |
| + "exitCode": 1, |
| + "stdout": """ |
| +Usage: compile_platform [options] patched_sdk fullOutput outlineOutput |
| + |
| +Compiles Dart SDK platform to the Dill/Kernel IR format. |
| + |
| +$usage |
| +Error: Expected three arguments. |
| +""", |
| + "stderr": "", |
| + }, |
| + "compile-platform-dartk": { |
| + "exitCode": 2, |
| + "stdout": "", |
| + "stderr": "Usage: compile-platform-dartk file\n", |
| + }, |
| + "log": { |
| + "exitCode": 0, |
| + "stdout": "", |
| + "stderr": "", |
| + }, |
| + "outline": { |
| + "exitCode": 1, |
| + "stdout": """Usage: outline [options] dartfile |
| + |
| +Creates an outline of a Dart program in the Dill/Kernel IR format. |
| + |
| +$usage |
| +Error: No Dart file specified. |
| +""", |
| + "stderr": "", |
| + }, |
| + "parser": { |
| + "exitCode": 0, |
| + "stdout": "", |
| + "stderr": "", |
| + }, |
| + "run": { |
| + "exitCode": 2, |
| + "stdout": "", |
| + "stderr": "'run' isn't supported anymore," |
| + " please use 'kernel-service' instead.\n", |
| + }, |
| + "scanner": { |
| + "exitCode": 0, |
| + "stderr": "", |
| + }, |
| + "dump-partial": { |
| + "exitCode": 1, |
| + "stdout": "usage: pkg/front_end/tool/fasta dump_partial" |
| + " partial.dill [extra1.dill] ... [extraN.dill]\n", |
| + "stderr": "", |
| + }, |
| + "dump-ir": { |
| + "exitCode": 2, |
| + "stdout": "", |
| + "stderr": "Usage: dump-ir dillfile [output]\n", |
| + }, |
| + "kernel-service": { |
| + "exitCode": 255, |
| + "stdout": "", |
| + }, |
| + }); |
| + Expect.stringEquals(jsonExpectation, jsonResult); |
| +} |