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>
This commit is contained in:
josh11b
2023-09-14 19:47:10 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 85d5b40429
commit e72226f31c
+5 -1
View File
@@ -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;
}