Skip to content

Commit

Permalink
Integrate GoogleTest framework for unit tests (#197)
Browse files Browse the repository at this point in the history
* Update package/tests/CMakeLists.txt to pull gtest

Added option to toggle pulling gtest

* Updated README.md with info on building gtest

Updated build-test.sh to turn on building gtest
  • Loading branch information
quantum-shift authored Aug 18, 2021
1 parent d02f032 commit 89abe35
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/scripts/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ -z "$CMAKE" ]; then
fi

# For debugging, handy to print what we're doing
cmd="$CMAKE -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC $CMAKE_EXTRA /mnt"
cmd="$CMAKE -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC -DBUILD_GTESTS=ON $CMAKE_EXTRA /mnt"
echo $cmd
$cmd
make -j 4
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ endif()
set(BUILD_BENCHMARK_LOG "${BUILD_BENCHMARK_LOG}"
CACHE BOOL "Build binary that benchmarks spdlog speed" FORCE)

if(NOT BUILD_GTESTS)
set(BUILD_GTESTS OFF)
endif()
set(BUILD_GTESTS "${BUILD_GTESTS}"
CACHE BOOL "Add the value tests (dependent on gtest)" FORCE)

# Define a default build type when using a single-mode tool like make/ninja
# We make this default to Release, unless profiling is enabled, in which
# case do RelWithDebInfo (bcause you need the debug symbols)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ The tests in prmon now run in Python3. If your environment does not
support Python3 properly it is possible to use Python2 for the tests
by setting `-DPYTHON_TEST=python2`.

To enable pulling and building gtest framework as well as tests dependent on gtest,
build with `-DBUILD_GTESTS=ON`.

### Creating a package with CPack

A cpack based package can be created by invoking
Expand Down
15 changes: 15 additions & 0 deletions package/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ target_link_libraries(io-burner PRIVATE Threads::Threads)

add_executable(mem-burner mem-burner.cpp)

if (${CMAKE_VERSION} VERSION_GREATER "3.14.0" AND BUILD_GTESTS)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()

include(GoogleTest)

endif()

# Custom targets for handling scripted wrappers for tests
function(script_install)
cmake_parse_arguments(SCRIPT_INSTALL "" "SCRIPT;DESTINATION" "" ${ARGN})
Expand Down

0 comments on commit 89abe35

Please sign in to comment.