浏览代码

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.
Boaz Brickner 1 年之前
父节点
当前提交
c99c9c41cf
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      toolchain/testing/file_test.cpp

+ 9 - 4
toolchain/testing/file_test.cpp

@@ -38,8 +38,10 @@ class ToolchainFileTest : public FileTestBase {
            llvm::raw_pwrite_stream& stdout, llvm::raw_pwrite_stream& stderr)
       -> ErrorOr<RunResult> 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_;
 };