mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:54:47 +01:00
Add AUTOUPDATE-SPLIT to help with format tests. (#4384)
Since formatting covers comments, and the CHECK lines are in comments, it can create recursive behaviors. This introduces AUTOUPDATE-SPLIT as a way of formally designating a split to exclusively be used for autoupdate output.
This commit is contained in:
@@ -232,8 +232,8 @@ auto FileTestBase::RunAutoupdater(const TestContext& context, bool dry_run)
|
||||
GetBazelCommand(BazelMode::Test, test_name_),
|
||||
GetBazelCommand(BazelMode::Dump, test_name_),
|
||||
context.input_content, filenames, *context.autoupdate_line_number,
|
||||
context.non_check_lines, context.stdout, context.stderr,
|
||||
GetDefaultFileRE(expected_filenames),
|
||||
context.autoupdate_split, context.non_check_lines, context.stdout,
|
||||
context.stderr, GetDefaultFileRE(expected_filenames),
|
||||
GetLineNumberReplacements(expected_filenames),
|
||||
[&](std::string& line) { DoExtraCheckReplacements(line); })
|
||||
.Run(dry_run);
|
||||
@@ -907,12 +907,30 @@ auto FileTestBase::ProcessTestFile(TestContext& context) -> ErrorOr<Success> {
|
||||
}
|
||||
|
||||
if (!found_autoupdate) {
|
||||
return ErrorBuilder() << "Missing AUTOUPDATE/NOAUTOUPDATE setting";
|
||||
return Error("Missing AUTOUPDATE/NOAUTOUPDATE setting");
|
||||
}
|
||||
|
||||
context.has_splits = split.has_splits();
|
||||
CARBON_RETURN_IF_ERROR(FinishSplit(test_name_, &split, &context.test_files));
|
||||
|
||||
// Validate AUTOUPDATE-SPLIT use, and remove it from test files if present.
|
||||
if (context.has_splits) {
|
||||
constexpr llvm::StringLiteral AutoupdateSplit = "AUTOUPDATE-SPLIT";
|
||||
for (const auto& test_file :
|
||||
llvm::ArrayRef(context.test_files).drop_back()) {
|
||||
if (test_file.filename == AutoupdateSplit) {
|
||||
return Error("AUTOUPDATE-SPLIT must be the last split");
|
||||
}
|
||||
}
|
||||
if (context.test_files.back().filename == AutoupdateSplit) {
|
||||
if (!context.autoupdate_line_number) {
|
||||
return Error("AUTOUPDATE-SPLIT requires AUTOUPDATE");
|
||||
}
|
||||
context.autoupdate_split = true;
|
||||
context.test_files.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Assume there is always a suffix `\n` in output.
|
||||
if (!context.expected_stdout.empty()) {
|
||||
context.expected_stdout.push_back(StrEq(""));
|
||||
|
||||
Reference in New Issue
Block a user