Skip to content

Commit

Permalink
Pass the path to the build_root/test folder as preprocessor symbol wh…
Browse files Browse the repository at this point in the history
…en compiling the tests.
  • Loading branch information
codereader committed Apr 19, 2021
1 parent 7e7a6fc commit aee0325
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ add_subdirectory(radiant)
pkg_check_modules(GTEST gtest)
pkg_check_modules(GTEST_MAIN gtest_main)
if (${GTEST_FOUND} AND ${GTEST_MAIN_FOUND})
include(CTest)
add_subdirectory(test)
endif()

Expand Down
10 changes: 8 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(GoogleTest)

add_executable(drtest
Basic.cpp
Brush.cpp
Expand Down Expand Up @@ -35,12 +37,16 @@ find_package(Threads REQUIRED)

target_compile_options(drtest PUBLIC ${SIGC_CFLAGS})

get_filename_component(TESTRESOURCEDIR "./resources" ABSOLUTE)
add_compile_definitions(TESTRESOURCEDIR="${TESTRESOURCEDIR}")
# Set up the paths such that the drtest executable can find the test resources
# and the core binary in the build workspace (in install/ and test/resources/)
get_filename_component(TEST_BASE_PATH "./" ABSOLUTE)
add_compile_definitions(TEST_BASE_PATH="${TEST_BASE_PATH}")

target_link_libraries(drtest PUBLIC
math xmlutil scenegraph module
${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}
${SIGC_LIBRARIES} ${GLEW_LIBRARIES} ${X11_LIBRARIES}
PRIVATE Threads::Threads)
install(TARGETS drtest)

gtest_discover_tests(drtest)
28 changes: 26 additions & 2 deletions test/TestContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ class TestContext :
virtual std::string getTestResourcePath() const
{
#if defined(POSIX)
#if defined(TESTRESOURCEDIR)
fs::path testResourcePath(TESTRESOURCEDIR);
#if defined(TEST_BASE_PATH)
fs::path testResourcePath(TEST_BASE_PATH);
testResourcePath /= "resources/";
#else
// make check will compile the test binary to $top_builddir/test/.libs/
fs::path testResourcePath = getApplicationPath();
Expand All @@ -91,8 +92,30 @@ class TestContext :
return _tempDataPath;
}

std::string getRuntimeDataPath() const override
{
// Allow special build settings to override the runtime data path
// this is needed to run the test binary through ctest from the build root
#ifdef TEST_BASE_PATH
fs::path runtimeDataPath(TEST_BASE_PATH);
runtimeDataPath /= "../install/";
return runtimeDataPath.string();
#else
return ApplicationContextBase::getRuntimeDataPath();
#endif
}

std::vector<std::string> getLibraryPaths() const override
{
#ifdef TEST_BASE_PATH
fs::path libraryPath(TEST_BASE_PATH);
libraryPath /= "../radiantcore/";

return
{
libraryPath.string(),
};
#else
auto libBasePath = os::standardPathWithSlash(getLibraryBasePath());

// Don't load modules from the plugins/ folder, as these
Expand All @@ -102,6 +125,7 @@ class TestContext :
{
libBasePath + MODULES_DIR,
};
#endif
}
};

Expand Down

0 comments on commit aee0325

Please sign in to comment.