From f23009f04f781a2d1e38fa6fda2ae5eeb5c0c6ed Mon Sep 17 00:00:00 2001 From: Austin Schuh Date: Fri, 16 Nov 2018 09:19:34 -0800 Subject: [PATCH] Make flatbuffer C++ tests work when vendored with bazel (#5040) Tests for third_party code are run out of the main workspace. This isn't an issue when the main workspace is the com_github_google_flatbuffers workspace, but is an issue when you are running the tests from another repository. To reproduce, use "git_repository" to add flatbuffers to a project and then run: bazel test @com_github_google_flatbuffers//:flatbuffers_test --- BUILD | 1 + tests/test.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 631452c79..2ba146664 100644 --- a/BUILD +++ b/BUILD @@ -143,6 +143,7 @@ cc_test( ], copts = [ "-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE", + "-DBAZEL_TEST_DATA_PATH", ], data = [ ":tests/include_test/include_test1.fbs", diff --git a/tests/test.cpp b/tests/test.cpp index 2730026bf..b14e56bd2 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -50,7 +50,12 @@ uint32_t lcg_rand() { } void lcg_reset() { lcg_seed = 48271; } -std::string test_data_path = "tests/"; +std::string test_data_path = +#ifdef BAZEL_TEST_DATA_PATH + "../com_github_google_flatbuffers/tests/"; +#else + "tests/"; +#endif // example of how to build up a serialized buffer algorithmically: flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {