Просмотр исходного кода

Make toolchain/testing/file_test more robust (#3235)

Support `toolchain/` being a subdirectory rather than the project root.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
josh11b 2 лет назад
Родитель
Сommit
e72226f31c
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      toolchain/testing/file_test.cpp

+ 5 - 1
toolchain/testing/file_test.cpp

@@ -88,7 +88,11 @@ class ToolchainFileTest : public FileTestBase {
  private:
   // Returns the toolchain subdirectory being tested.
   static auto GetComponent(llvm::StringRef test_name) -> llvm::StringRef {
-    CARBON_CHECK(test_name.consume_front("toolchain/"));
+    // This handles cases where the toolchain directory may be copied into a
+    // repository that doesn't put it at the root.
+    auto pos = test_name.find("toolchain/");
+    CARBON_CHECK(pos != llvm::StringRef::npos) << test_name;
+    test_name = test_name.drop_front(pos + strlen("toolchain/"));
     test_name = test_name.take_front(test_name.find("/"));
     return test_name;
   }