When there are split files, put unattached stdout at the end of the last file. (#3234)

This is consistent with the goal of trying to push unattached stdout to
the bottom of the test file. The current logic had a single file in
mind, and was not adapted for split file logic.

Addresses
https://github.com/carbon-language/carbon-lang/pull/3217#discussion_r1323584624

Note this depends on #3233
This commit is contained in:
Jon Ross-Perkins
2023-09-15 21:56:42 +00:00
committed by GitHub
parent 75282462d4
commit ec9d73e471
7 changed files with 41 additions and 30 deletions
+9 -5
View File
@@ -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_);
+4 -2
View File
@@ -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.
+4 -3
View File
@@ -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
+6 -5
View File
@@ -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() {}
@@ -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() {}
+6 -5
View File
@@ -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() {}
+6 -5
View File
@@ -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() {}