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; }