From c99c9c41cff74f9ea1a479b0f19d7fe97ab390bb Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Tue, 17 Dec 2024 17:37:31 +0100 Subject: [PATCH] Do not load prelude files to the test file system in no-prelude tests (#4697) These tests do not import prelude so the files do not need to exist, and only make the tests more complex, as they include extra unnecessary inputs. --- toolchain/testing/file_test.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/toolchain/testing/file_test.cpp b/toolchain/testing/file_test.cpp index eae4d78165ae..60279793483f 100644 --- a/toolchain/testing/file_test.cpp +++ b/toolchain/testing/file_test.cpp @@ -38,8 +38,10 @@ class ToolchainFileTest : public FileTestBase { llvm::raw_pwrite_stream& stdout, llvm::raw_pwrite_stream& stderr) -> ErrorOr override { CARBON_ASSIGN_OR_RETURN(auto prelude, installation_.ReadPreludeManifest()); - for (const auto& file : prelude) { - CARBON_RETURN_IF_ERROR(AddFile(*fs, file)); + if (!is_no_prelude()) { + for (const auto& file : prelude) { + CARBON_RETURN_IF_ERROR(AddFile(*fs, file)); + } } Driver driver(fs, &installation_, stdout, stderr); @@ -83,8 +85,7 @@ class ToolchainFileTest : public FileTestBase { // For `lex` and `parse`, we don't need to import the prelude; exclude it to // focus errors. In other phases we only do this for explicit "no_prelude" // tests. - if (component_ == "lex" || component_ == "parse" || - test_name().find("/no_prelude/") != llvm::StringRef::npos) { + if (component_ == "lex" || component_ == "parse" || is_no_prelude()) { args.push_back("--no-prelude-import"); } @@ -161,6 +162,10 @@ class ToolchainFileTest : public FileTestBase { return test_name; } + auto is_no_prelude() const -> bool { + return test_name().find("/no_prelude/") != llvm::StringRef::npos; + } + const llvm::StringRef component_; const InstallPaths installation_; };