Skip to content

Commit 28d76e6

Browse files
authored
Fix toolchain file_test_base multi-file integration. (#3780)
test_args will never contain %s; switch to filtering arguments, and handle the edge cases.
1 parent 1d720dc commit 28d76e6

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

testing/file_test/file_test_base.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ static auto CompareFailPrefix(llvm::StringRef filename, bool success) -> void {
7373
if (success) {
7474
EXPECT_FALSE(filename.starts_with("fail_"))
7575
<< "`" << filename
76-
<< "` succeeded; if this is correct, add a `fail_` prefix.";
76+
<< "` succeeded; if success is expected, remove the `fail_` "
77+
"prefix.";
7778
} else {
7879
EXPECT_TRUE(filename.starts_with("fail_"))
7980
<< "`" << filename
80-
<< "` failed; if this is correct, remove the `fail_` prefix.";
81+
<< "` failed; if failure is expected, add the `fail_` prefix.";
8182
}
8283
}
8384

toolchain/driver/testdata/fail_missing_file.carbon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Exceptions. See /LICENSE for license information.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
5-
// ARGS: compile nonexistent.carbon
5+
// ARGS: compile not_file.carbon
66
//
77
// AUTOUPDATE
8-
// CHECK:STDERR: nonexistent.carbon: ERROR: Error opening file for read: No such file or directory
8+
// CHECK:STDERR: not_file.carbon: ERROR: Error opening file for read: No such file or directory

toolchain/testing/file_test.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <string>
99

10+
#include "llvm/ADT/STLExtras.h"
1011
#include "llvm/ADT/SmallVector.h"
1112
#include "llvm/ADT/StringRef.h"
1213
#include "llvm/Support/FormatVariadic.h"
@@ -29,16 +30,18 @@ class ToolchainFileTest : public FileTestBase {
2930
llvm::raw_pwrite_stream& stderr) -> ErrorOr<RunResult> override {
3031
Driver driver(fs, stdout, stderr);
3132
auto driver_result = driver.RunCommand(test_args);
32-
if (std::find(test_args.begin(), test_args.end(), "%s") ==
33-
test_args.end()) {
34-
// Files weren't forwarded as an argument, so don't use per_file_success.
35-
// This primarily occurs in driver tests with invalid filename arguments,
36-
// which we wouldn't want to try validating.
37-
return {{.success = driver_result.success}};
38-
} else {
39-
return {{.success = driver_result.success,
40-
.per_file_success = std::move(driver_result.per_file_success)}};
41-
}
33+
34+
RunResult result{
35+
.success = driver_result.success,
36+
.per_file_success = std::move(driver_result.per_file_success)};
37+
// Drop entries that don't look like a file. Note this can empty out the
38+
// list.
39+
llvm::erase_if(result.per_file_success,
40+
[](std::pair<llvm::StringRef, bool> entry) {
41+
return entry.first == "." || entry.first == "-" ||
42+
entry.first.starts_with("not_file");
43+
});
44+
return result;
4245
}
4346

4447
auto GetDefaultArgs() -> llvm::SmallVector<std::string> override {

0 commit comments

Comments
 (0)