Implement autoupdate for file_test. (#3043)

I've migrated the toolchain autoupdate scripts here, I just need a
little more time to do the explorer side (which I need to check
performance, that may require multithreading as we do in the current
script). However, this felt substantial enough to share and it means I
can handle autoupdate in more of the toolchain, including preparatory
work for autoupdate on multi-file tests.

Once explorer is done I'll remove the old script.
This commit is contained in:
Jon Ross-Perkins
2023-08-02 21:32:21 +00:00
committed by GitHub
parent 90d2d7ef65
commit b5167b2d69
37 changed files with 934 additions and 402 deletions
+16 -15
View File
@@ -19,17 +19,16 @@ class ExplorerFileTest : public FileTestBase {
public:
using FileTestBase::FileTestBase;
auto RunWithFiles(const llvm::SmallVector<llvm::StringRef>& test_args,
const llvm::SmallVector<TestFile>& test_files,
llvm::raw_pwrite_stream& stdout,
llvm::raw_pwrite_stream& stderr) -> bool override {
auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
const llvm::SmallVector<TestFile>& test_files,
llvm::raw_pwrite_stream& stdout, llvm::raw_pwrite_stream& stderr)
-> ErrorOr<bool> override {
// Create the files in-memory.
llvm::vfs::InMemoryFileSystem fs(new llvm::vfs::InMemoryFileSystem());
for (const auto& test_file : test_files) {
if (!fs.addFile(test_file.filename, /*ModificationTime=*/0,
llvm::MemoryBuffer::getMemBuffer(test_file.content))) {
ADD_FAILURE() << "File is repeated: " << test_file.filename;
return false;
return ErrorBuilder() << "File is repeated: " << test_file.filename;
}
}
@@ -37,8 +36,7 @@ class ExplorerFileTest : public FileTestBase {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> prelude =
llvm::MemoryBuffer::getFile("explorer/data/prelude.carbon");
if (prelude.getError()) {
ADD_FAILURE() << prelude.getError().message();
return false;
return ErrorBuilder() << prelude.getError().message();
}
// TODO: This path is long with a prefix / because of the path expectations
// in tests. Change those to allow a shorter path (e.g., `prelude.carbon`)
@@ -46,15 +44,13 @@ class ExplorerFileTest : public FileTestBase {
static constexpr llvm::StringLiteral PreludePath =
"/explorer/data/prelude.carbon";
if (!fs.addFile(PreludePath, /*ModificationTime=*/0, std::move(*prelude))) {
ADD_FAILURE() << "Duplicate prelude.carbon";
return false;
return ErrorBuilder() << "Duplicate prelude.carbon";
}
llvm::SmallVector<const char*> args = {"explorer"};
for (auto arg : test_args) {
args.push_back(arg.data());
}
TestRawOstream trace_stream;
// Trace output is only checked for a few tests.
bool check_trace_output =
@@ -62,16 +58,19 @@ class ExplorerFileTest : public FileTestBase {
int exit_code = ExplorerMain(
args.size(), args.data(), /*install_path=*/"", PreludePath, stdout,
stderr, check_trace_output ? stdout : trace_stream, fs);
stderr, check_trace_output ? stdout : trace_stream_, fs);
return exit_code == EXIT_SUCCESS;
}
auto ValidateRun(const llvm::SmallVector<TestFile>& /*test_files*/)
-> void override {
// Skip trace test check as they use stdout stream instead of
// trace_stream_ostream
if (absl::GetFlag(FLAGS_trace)) {
EXPECT_FALSE(trace_stream.TakeStr().empty())
EXPECT_FALSE(trace_stream_.TakeStr().empty())
<< "Tracing should always do something";
}
return exit_code == EXIT_SUCCESS;
}
auto GetDefaultArgs() -> llvm::SmallVector<std::string> override {
@@ -83,6 +82,8 @@ class ExplorerFileTest : public FileTestBase {
args.push_back("%s");
return args;
}
TestRawOstream trace_stream_;
};
} // namespace