Connect unit tests with CTest

This commit is contained in:
Jean Pierre Cimalando 2021-03-18 00:42:04 +01:00
parent fe2fc45014
commit e77a227cbf
3 changed files with 28 additions and 3 deletions

View file

@ -61,6 +61,7 @@ if (SFIZZ_BENCHMARKS)
endif() endif()
if (SFIZZ_TESTS) if (SFIZZ_TESTS)
enable_testing ()
add_subdirectory (tests) add_subdirectory (tests)
endif() endif()

View file

@ -1,6 +1,11 @@
############################### ###############################
# Test application # Test application
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/catch2")
include(CTest)
include(Catch)
set(SFIZZ_TEST_SOURCES set(SFIZZ_TEST_SOURCES
DirectRegionT.cpp DirectRegionT.cpp
RegionValuesT.cpp RegionValuesT.cpp
@ -47,8 +52,7 @@ set(SFIZZ_TEST_SOURCES
) )
add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES}) add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES})
target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::spin_mutex sfizz::jsl) target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::spin_mutex sfizz::jsl sfizz::filesystem)
sfizz_enable_lto_if_needed(sfizz_tests) sfizz_enable_lto_if_needed(sfizz_tests)
sfizz_enable_fast_math(sfizz_tests) sfizz_enable_fast_math(sfizz_tests)
catch_discover_tests(sfizz_tests)
file(COPY "." DESTINATION ${CMAKE_BINARY_DIR}/tests)

View file

@ -3,8 +3,28 @@
#define CATCH_CONFIG_RUNNER #define CATCH_CONFIG_RUNNER
#include "catch2/catch.hpp" #include "catch2/catch.hpp"
#include <ghc/fs_std.hpp>
static bool moveToTestsDirectory(const fs::path& searchedPath);
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (!moveToTestsDirectory(fs::u8path("tests/TestFiles"))) {
std::cerr << "Failed to locate test files\n";
return 1;
}
int result = Catch::Session().run(argc, argv); int result = Catch::Session().run(argc, argv);
return result; return result;
} }
static bool moveToTestsDirectory(const fs::path& searchedPath)
{
while (!fs::exists(searchedPath)) {
fs::path cwdPath = fs::current_path();
fs::path newPath = cwdPath.parent_path();
if (cwdPath == newPath)
return false;
fs::current_path(newPath);
}
return true;
}