Files
sdk/pkg/front_end/test/tool_git_test.dart
T
Paul Berry 1b1392cf01 [messages] Migrate packages to new diagnostic.dart files.
Translates the code in the following packages:
- `_fe_analyzer_shared`
- `_js_interop_checks`
- `dart2wasm`
- `front_end`
- `vm`

so that it imports diagnostic codes from
`package:front_end/src/codes/diagnostic.dart` or
`package:_fe_analyzer_shared/src/messages/diagnostic.dart`, using the
prefix `diag`, rather than using the old constant declarations in
`package:front_end/src/codes/cfe_codes.dart` and
`package:_fe_analyzer_shared/src/messages/codes.dart`.

This CL was created by the following steps:

- Run the script
  `pkg/analyzer_utilities/tool/messages/use_prefixed_import_instead_of_code.dart`.

- Execute `dart fix --apply --code=unused_import,unnecessary_import`
  on each of the above package directories (this removes imports that
  are no longer necessary due to the change).

- Add `diag` to `pkg/front_end/test/spell_checking_list_code.txt`.

- Use `dart format` to fix formatting errors left behind by
  `use_prefixed_import_instead_of_code.dart`.

Change-Id: I6a6a69645d7659259db1acce35c8ee3bb6e347c9
Tested: standard trybots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475929
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-28 06:13:24 -08:00

144 lines
3.7 KiB
Dart

// 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/cfe`.
import "dart:io";
import "package:expect/expect.dart";
import "package:front_end/src/codes/diagnostic.dart" as diag;
const String toolPath = "pkg/front_end/tool/cfe";
const List<String> subtools = const <String>[
"abcompile",
"compile",
"compile-platform",
"log",
"logd",
"outline",
"parser",
"scanner",
"dump-ir",
"testing",
"generate-messages",
];
/// An unsafe tool is a tool that shouldn't be run during this test. Please
/// document below why the tool shouldn't be run, and how it is tested.
const List<String> unsafeTools = const <String>[
// This modifies the source code in the repository, and that could cause
// other tests to fail. This tool is tested as we invoke it everytime we edit
// messages.yaml.
"generate-messages",
// This is a daemon process that never terminates. It's not currently tested
// directly.
"logd",
// This would eventually run this test again, recursively, and never
// finish. As this tool is part of the workflow for testing Fasta, we assume
// is exercised sufficiently.
"testing",
];
void main() {
if (!Platform.isMacOS && !Platform.isLinux) {
// The tool is a shell script and only works on Mac and Linux.
return;
}
Set<String> testedSubtools = new Set<String>.from(
subtools,
).difference(new Set<String>.from(unsafeTools));
String usage = diag.fastaUsageShort.problemMessage;
Map expectations = {
"abcompile": {
"exitCode": 1,
"stdout": """[]
Expected -DbRoot=/absolute/path/to/other/sdk/repo
""",
"stderr": "",
},
"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] dart-library-uri libraries.json vm_outline.dill platform.dill outline.dill
Compiles Dart SDK platform to the Dill/Kernel IR format.
$usage
Error: Expected five arguments.
""",
"stderr": "",
},
"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": ""},
"scanner": {"exitCode": 0, "stderr": ""},
"dump-ir": {
"exitCode": 2,
"stdout": "",
"stderr": "Usage: dump-ir dillFile [output]\n",
},
};
for (String subtool in testedSubtools) {
print("Testing $subtool");
ProcessResult result = Process.runSync(
"/bin/bash",
<String>[toolPath, subtool],
environment: <String, String>{"DART_VM": Platform.resolvedExecutable},
);
Map expectation = expectations.remove(subtool);
String combinedOutput =
"""
stdout:
${result.stdout}
stderr:
${result.stderr}
""";
Expect.equals(expectation["exitCode"], result.exitCode, combinedOutput);
switch (subtool) {
case "scanner":
Expect.isTrue(result.stdout.startsWith("Reading files took: "));
Expect.stringEquals(expectation["stderr"], result.stderr);
break;
default:
Expect.stringEquals(expectation["stdout"], result.stdout);
Expect.stringEquals(expectation["stderr"], result.stderr);
break;
}
}
Expect.isTrue(expectations.isEmpty);
}