Skip to content

Commit

Permalink
Make flatbuffer C++ tests work when vendored with bazel (#5040)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AustinSchuh authored and aardappel committed Nov 16, 2018
1 parent 30bae01 commit f23009f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ cc_test(
],
copts = [
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
"-DBAZEL_TEST_DATA_PATH",
],
data = [
":tests/include_test/include_test1.fbs",
Expand Down
7 changes: 6 additions & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f23009f

Please sign in to comment.