From e77a227cbf72e7e8422bb7e6a5abfc8e00b8f89f Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 00:42:04 +0100 Subject: [PATCH] Connect unit tests with CTest --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 10 +++++++--- tests/MainT.cpp | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4b982fc..55fdb1a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ if (SFIZZ_BENCHMARKS) endif() if (SFIZZ_TESTS) + enable_testing () add_subdirectory (tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 497ca0e2..82d1fcf5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,11 @@ ############################### # Test application +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/catch2") + +include(CTest) +include(Catch) + set(SFIZZ_TEST_SOURCES DirectRegionT.cpp RegionValuesT.cpp @@ -47,8 +52,7 @@ set(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_fast_math(sfizz_tests) - -file(COPY "." DESTINATION ${CMAKE_BINARY_DIR}/tests) +catch_discover_tests(sfizz_tests) diff --git a/tests/MainT.cpp b/tests/MainT.cpp index a72f67db..156e3ac5 100644 --- a/tests/MainT.cpp +++ b/tests/MainT.cpp @@ -3,8 +3,28 @@ #define CATCH_CONFIG_RUNNER #include "catch2/catch.hpp" +#include + +static bool moveToTestsDirectory(const fs::path& searchedPath); + 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); 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; +}