Added GetRunfilesFile() to be able to reliably determine prelude location under various invocation scenarios

The logic is using bazel Runfiles API per Jon's suggestion.

One of the scenarios used by the fuzzing framework is to place the binary and its runfiles into a folder, resulting in a directory layout like this:

[temp dir]
fuzzer
fuzzer.runfiles/

Tested:
bazel test -c opt explorer/fuzzing:explorer_fuzzer
bazel build -c opt explorer/fuzzing:explorer_fuzzer + run the binary from various locations
This commit is contained in:
pk19604014
2022-05-02 10:36:21 -04:00
committed by GitHub
parent 309ec35f95
commit 150057f260
5 changed files with 50 additions and 1 deletions
+13
View File
@@ -36,6 +36,19 @@ TEST(FuzzerUtilTest, RunFuzzerOnCorpus) {
EXPECT_GT(file_count, 0);
}
TEST(FuzzerUtilTest, GetRunfilesFile) {
EXPECT_THAT(*Internal::GetRunfilesFile(
"carbon/explorer/fuzzing/fuzzer_corpus/empty.textproto"),
testing::EndsWith("/explorer/fuzzing/fuzzer_corpus/"
"empty.textproto"));
EXPECT_THAT(Internal::GetRunfilesFile(
"explorer/fuzzing/fuzzer_corpus/empty.textproto")
.error()
.message(),
testing::EndsWith("fuzzer_util_test.runfiles/explorer/fuzzing/"
"fuzzer_corpus/empty.textproto doesn't exist"));
}
} // namespace
} // namespace Carbon::Testing