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:
Richard Smith
2023-09-11 20:52:58 +00:00
committed by GitHub
parent 8aa3d960f5
commit 5c2e16b692
2 changed files with 9 additions and 9 deletions
+9 -8
View File
@@ -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());
}
-1
View File
@@ -5,5 +5,4 @@
// ARGS: compile --phase=lex nonexistent.carbon
//
// AUTOUPDATE
// CHECK:STDERR: nonexistent.carbon: Error opening file for read: No such file or directory