mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Fix oscillating autoupdate output for empty source files. (#3209)
toolchain/driver/testdata/fail_missing_file.carbon has no content after its AUTOUPDATE line. This caused it to oscillate between three states: 1) If there were no content lines after AUTOUPDATE, autoupdate would add a blank line and then its STDERR CHECK line. 2) If there was a (blank) content line after AUTOUPDATE, autoupdate would move the STDERR CHECK line to immediately after AUTOUPDATE, leaving a trailing blank line. 3) pre-commit would remove the trailing blank line, leaving no content lines after AUTOUPDATE. Handle the special case of no content lines after AUTOUPDATE by producing "early" STDERR check lines immediately after the AUTOUPDATE line, rather than before the next line, which might not exist. We already did this in the case where there were early STDOUT check lines.
This commit is contained in:
@@ -286,17 +286,18 @@ auto AutoupdateFileTest(
|
||||
.insert({non_check_line.line_number(), ++output_line_number})
|
||||
.second);
|
||||
|
||||
// If we just added the AUTOUPDATE line, include any early STDERR lines
|
||||
// now, so that the initial batch of CHECK lines have STDERR before
|
||||
// STDOUT. This also ensures we don't insert a blank line before the
|
||||
// STDERR checks if there are no more lines after AUTOUPDATE.
|
||||
if (autoupdate_line_number == non_check_line.line_number()) {
|
||||
add_check_lines(stderr_check_lines, stderr_check_line,
|
||||
non_check_line.line_number(), non_check_line.indent());
|
||||
}
|
||||
|
||||
// STDOUT check lines are placed after the line they refer to, or at the
|
||||
// end of the file if none of them refers to a line.
|
||||
if (reached_autoupdate && any_attached_stdout_lines) {
|
||||
// Include any early STDERR lines now, so that the initial batch of
|
||||
// CHECK lines have STDERR before STDOUT.
|
||||
if (autoupdate_line_number == non_check_line.line_number()) {
|
||||
add_check_lines(stderr_check_lines, stderr_check_line,
|
||||
non_check_line.line_number(),
|
||||
non_check_line.indent());
|
||||
}
|
||||
|
||||
add_check_lines(stdout_check_lines, stdout_check_line,
|
||||
non_check_line.line_number(), non_check_line.indent());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user