From e72226f31ce3c80908b3bac1d0bfbb52006e40c5 Mon Sep 17 00:00:00 2001 From: josh11b Date: Thu, 14 Sep 2023 12:47:10 -0700 Subject: [PATCH] Make toolchain/testing/file_test more robust (#3235) Support `toolchain/` being a subdirectory rather than the project root. --------- Co-authored-by: Jon Ross-Perkins --- toolchain/testing/file_test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/toolchain/testing/file_test.cpp b/toolchain/testing/file_test.cpp index 3855aef2dc7f..a7b58030ae7c 100644 --- a/toolchain/testing/file_test.cpp +++ b/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; }