Issue 1734: Streams not flushed if not running actual benchmarks (#1735)

Consistently flush Out and Err streams, otherwise they might not get flushed
and the output lost when using custom streams.

Fixes #1734.
This commit is contained in:
Benny Tordrup 2024-01-09 15:59:10 +01:00 committed by GitHub
parent 96d820f73f
commit 54e4327190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -577,12 +577,16 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
Err << "A custom file reporter was provided but "
"--benchmark_out=<file> was not specified."
<< std::endl;
Out.flush();
Err.flush();
std::exit(1);
}
if (!fname.empty()) {
output_file.open(fname);
if (!output_file.is_open()) {
Err << "invalid file name: '" << fname << "'" << std::endl;
Out.flush();
Err.flush();
std::exit(1);
}
if (!file_reporter) {
@ -597,10 +601,16 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
}
std::vector<internal::BenchmarkInstance> benchmarks;
if (!FindBenchmarksInternal(spec, &benchmarks, &Err)) return 0;
if (!FindBenchmarksInternal(spec, &benchmarks, &Err)) {
Out.flush();
Err.flush();
return 0;
}
if (benchmarks.empty()) {
Err << "Failed to match any benchmarks against regex: " << spec << "\n";
Out.flush();
Err.flush();
return 0;
}
@ -611,6 +621,8 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
internal::RunBenchmarks(benchmarks, display_reporter, file_reporter);
}
Out.flush();
Err.flush();
return benchmarks.size();
}