diff --git a/testing/file_test/autoupdate.cpp b/testing/file_test/autoupdate.cpp index 8a4b9ba9e4fb..71ef731f268e 100644 --- a/testing/file_test/autoupdate.cpp +++ b/testing/file_test/autoupdate.cpp @@ -225,11 +225,13 @@ auto FileTestAutoupdater::AddCheckLines(CheckLines& check_lines, } } -auto FileTestAutoupdater::FinishFile() -> void { +auto FileTestAutoupdater::FinishFile(bool is_last_file) -> void { + bool include_stdout = any_attached_stdout_lines_ || is_last_file; + // At the end of each file, print any remaining lines which are associated // with the file. if (ShouldAddCheckLine(stderr_, INT_MAX) || - ShouldAddCheckLine(stdout_, INT_MAX)) { + (include_stdout && ShouldAddCheckLine(stdout_, INT_MAX))) { // Ensure there's a blank line before any trailing CHECKs. if (!new_lines_.empty() && !new_lines_.back()->is_blank()) { new_lines_.push_back(&blank_line_); @@ -237,7 +239,9 @@ auto FileTestAutoupdater::FinishFile() -> void { } AddCheckLines(stderr_, INT_MAX, ""); - AddCheckLines(stdout_, INT_MAX, ""); + if (include_stdout) { + AddCheckLines(stdout_, INT_MAX, ""); + } } new_last_line_numbers_.push_back(output_line_number_); @@ -292,7 +296,7 @@ auto FileTestAutoupdater::Run(bool dry_run) -> bool { // Loop through remaining content. while (non_check_line_ != non_check_lines_.end()) { if (output_file_number_ < non_check_line_->file_number()) { - FinishFile(); + FinishFile(/*is_last_file=*/false); StartSplitFile(); continue; } @@ -314,7 +318,7 @@ auto FileTestAutoupdater::Run(bool dry_run) -> bool { ++non_check_line_; } - FinishFile(); + FinishFile(/*is_last_file=*/true); for (auto& check_line : stdout_.lines) { check_line.RemapLineNumbers(output_line_remap_, new_last_line_numbers_); diff --git a/testing/file_test/autoupdate.h b/testing/file_test/autoupdate.h index 57d41ac557ad..169698fc59c5 100644 --- a/testing/file_test/autoupdate.h +++ b/testing/file_test/autoupdate.h @@ -160,8 +160,10 @@ class FileTestAutoupdater { auto AddCheckLines(CheckLines& check_lines, int to_line_number, llvm::StringRef indent) -> void; - // Adds remaining check lines for the current file. - auto FinishFile() -> void; + // Adds remaining check lines for the current file. stderr is always included, + // but stdout is only included when either any_attached_stdout_lines_ or + // is_last_file is true. + auto FinishFile(bool is_last_file) -> void; // Starts a new split file, updating file and line numbers. Advances past the // split line. diff --git a/testing/file_test/testdata/unattached_multi_file.carbon b/testing/file_test/testdata/unattached_multi_file.carbon index 3366a997a623..7c54423489e3 100644 --- a/testing/file_test/testdata/unattached_multi_file.carbon +++ b/testing/file_test/testdata/unattached_multi_file.carbon @@ -6,11 +6,12 @@ // CHECK:STDERR: unattached message 3 // CHECK:STDERR: unattached message 4 -// CHECK:STDOUT: 3 args: `default_args`, `a.carbon`, `b.carbon` -// CHECK:STDOUT: unattached message 1 -// CHECK:STDOUT: unattached message 2 // --- a.carbon aaa // --- b.carbon bbb + +// CHECK:STDOUT: 3 args: `default_args`, `a.carbon`, `b.carbon` +// CHECK:STDOUT: unattached message 1 +// CHECK:STDOUT: unattached message 2 diff --git a/toolchain/check/testdata/basics/multifile.carbon b/toolchain/check/testdata/basics/multifile.carbon index c2c30c0416b8..3347f8c10108 100644 --- a/toolchain/check/testdata/basics/multifile.carbon +++ b/toolchain/check/testdata/basics/multifile.carbon @@ -4,6 +4,12 @@ // // AUTOUPDATE +// --- a.carbon +fn A() {} + +// --- b.carbon +fn B() {} + // CHECK:STDOUT: file "a.carbon" { // CHECK:STDOUT: %.loc1 = fn_decl @A // CHECK:STDOUT: } @@ -20,8 +26,3 @@ // CHECK:STDOUT: !entry: // CHECK:STDOUT: return // CHECK:STDOUT: } -// --- a.carbon -fn A() {} - -// --- b.carbon -fn B() {} diff --git a/toolchain/check/testdata/basics/multifile_raw_and_textual_ir.carbon b/toolchain/check/testdata/basics/multifile_raw_and_textual_ir.carbon index 0f3faa5abebd..5bda8f220213 100644 --- a/toolchain/check/testdata/basics/multifile_raw_and_textual_ir.carbon +++ b/toolchain/check/testdata/basics/multifile_raw_and_textual_ir.carbon @@ -8,6 +8,12 @@ // // AUTOUPDATE +// --- a.carbon +fn A() {} + +// --- b.carbon +fn B() {} + // CHECK:STDOUT: - filename: a.carbon // CHECK:STDOUT: sem_ir: // CHECK:STDOUT: - cross_reference_irs_size: 1 @@ -88,8 +94,3 @@ // CHECK:STDOUT: !entry: // CHECK:STDOUT: return // CHECK:STDOUT: } -// --- a.carbon -fn A() {} - -// --- b.carbon -fn B() {} diff --git a/toolchain/check/testdata/basics/multifile_raw_ir.carbon b/toolchain/check/testdata/basics/multifile_raw_ir.carbon index 9fdc4a6530ce..0a2b3f1dce0a 100644 --- a/toolchain/check/testdata/basics/multifile_raw_ir.carbon +++ b/toolchain/check/testdata/basics/multifile_raw_ir.carbon @@ -8,6 +8,12 @@ // // AUTOUPDATE +// --- a.carbon +fn A() {} + +// --- b.carbon +fn B() {} + // CHECK:STDOUT: - filename: a.carbon // CHECK:STDOUT: sem_ir: // CHECK:STDOUT: - cross_reference_irs_size: 1 @@ -70,8 +76,3 @@ // CHECK:STDOUT: node+0, // CHECK:STDOUT: ], // CHECK:STDOUT: ] -// --- a.carbon -fn A() {} - -// --- b.carbon -fn B() {} diff --git a/toolchain/parse/testdata/basics/multifile.carbon b/toolchain/parse/testdata/basics/multifile.carbon index c05a8149a871..7b9bca444add 100644 --- a/toolchain/parse/testdata/basics/multifile.carbon +++ b/toolchain/parse/testdata/basics/multifile.carbon @@ -4,6 +4,12 @@ // // AUTOUPDATE +// --- a.carbon +fn A() {} + +// --- b.carbon +fn B() {} + // CHECK:STDOUT: - filename: a.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, @@ -24,8 +30,3 @@ // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 6}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] -// --- a.carbon -fn A() {} - -// --- b.carbon -fn B() {}