Skip to content

Commit

Permalink
refactor unit tests to use Catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
rabauke committed Mar 23, 2022
1 parent 0ccc4f4 commit 245983b
Show file tree
Hide file tree
Showing 13 changed files with 1,004 additions and 1,351 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/Catch2"]
path = external/Catch2
url = https://github.com/catchorg/Catch2.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include(CMakePackageConfigHelpers)
write_basic_package_version_file("${version_pkg_config}" COMPATIBILITY SameMajorVersion)
configure_package_config_file("cmake/Config.cmake.in" "${project_pkg_config}" INSTALL_DESTINATION "${pkg_config_install_dir}")

add_subdirectory(external/Catch2)
add_subdirectory(trng)
add_subdirectory(examples)
add_subdirectory(tests)
Expand Down
1 change: 1 addition & 0 deletions external/Catch2
Submodule Catch2 added at 216713
43 changes: 13 additions & 30 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
find_package(Boost)
add_executable(test_all test_all.cc test_engines.cc test_distributions.cc test_special_functions.cc test_int_math.cc test_linear_algebra.cc)
target_link_libraries(test_all PRIVATE trng4::trng4 Catch2::Catch2)
if (WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(TARGET test_all POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_RUNTIME_DLLS:test_all>
$<TARGET_FILE_DIR:test_all>
COMMAND_EXPAND_LISTS)
endif ()

if (Boost_FOUND)
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
set(CMAKE_MODULE_PATH ../external/Catch2/contrib ${CMAKE_MODULE_PATH})
include(CTest)
include(Catch)

add_executable(test_all test_all.cc test_engines.cc test_distributions.cc test_math.cc test_int_math.cc type_names.cc test_linear_algebra.cc)
target_link_libraries(test_all PUBLIC trng4::trng4 Boost::unit_test_framework)
if (WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(TARGET test_all POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_RUNTIME_DLLS:test_all>
$<TARGET_FILE_DIR:test_all>
COMMAND_EXPAND_LISTS)
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
target_compile_options(test_all PUBLIC "/bigobj")
endif ()
add_test(NAME run_test_all COMMAND test_all --log_level=test_suite CONFIGURATIONS Debug Release RelWithDebInfo)
if (WIN32)
set(exec_path_debug "PATH=${Boost_LIBRARY_DIR_DEBUG}$<SEMICOLON>$ENV{PATH}")
set(exec_path_release "PATH=${Boost_LIBRARY_DIR_RELEASE}$<SEMICOLON>$ENV{PATH}")
string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
if (build_type STREQUAL debug)
set_tests_properties(run_test_all PROPERTIES ENVIRONMENT "${exec_path_debug}")
elseif (build_type STREQUAL release)
set_tests_properties(run_test_all PROPERTIES ENVIRONMENT "${exec_path_release}")
elseif (build_type STREQUAL relwithdebinfo)
set_tests_properties(run_test_all PROPERTIES ENVIRONMENT "${exec_path_release}")
endif ()
endif ()
endif ()
catch_discover_tests(test_all)
7 changes: 4 additions & 3 deletions tests/test_all.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.

#define BOOST_TEST_MODULE test all
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch2/catch_reporter_sonarqube.hpp>
#include <catch2/catch_reporter_teamcity.hpp>
Loading

0 comments on commit 245983b

Please sign in to comment.