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_);