From f65c3d1cd1af3f501aaf51e9015a0691e0fd4125 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 22 Jan 2025 01:17:28 +0100 Subject: [PATCH] fixed tests not building with catch2 versions >= 3.0 --- CHANGELOG.md | 4 ++++ CMakeLists.txt | 2 +- test/CMakeLists.txt | 19 ++++++++++++++----- test/distance/CMakeLists.txt | 12 ++++++++++-- test/distance/tests-DamerauLevenshtein.cpp | 8 +++++++- test/distance/tests-Hamming.cpp | 8 +++++++- test/distance/tests-Indel.cpp | 8 +++++++- test/distance/tests-Jaro.cpp | 8 +++++++- test/distance/tests-JaroWinkler.cpp | 8 +++++++- test/distance/tests-LCSseq.cpp | 8 +++++++- test/distance/tests-Levenshtein.cpp | 8 +++++++- test/distance/tests-OSA.cpp | 8 +++++++- test/tests-common.cpp | 8 +++++++- test/tests-fuzz.cpp | 7 ++++++- test/tests-main.cpp | 2 +- 15 files changed, 99 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a76179..ba306e77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +## [3.3.1] - 2025-01-22 +### Fixed +- fixed tests not building with catch2 versions >= 3.0 + ## [3.3.0] - 2025-01-18 ### Changed - add C++11 and C++14 support diff --git a/CMakeLists.txt b/CMakeLists.txt index 71f0ffca..35aaf3cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt") endif() -project(rapidfuzz LANGUAGES CXX VERSION 3.3.0) +project(rapidfuzz LANGUAGES CXX VERSION 3.3.1) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") include(GNUInstallDirs) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c91c3d71..b0f7eca1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Catch2 2 QUIET) +find_package(Catch2 QUIET) if (Catch2_FOUND) message("Using system supplied version of Catch2") else() @@ -10,6 +10,7 @@ else() GIT_TAG v2.13.10 ) FetchContent_MakeAvailable(Catch2) + set(Catch2_VERSION "2.13.10") endif() if (RAPIDFUZZ_ENABLE_LINTERS) @@ -50,11 +51,19 @@ if (RAPIDFUZZ_ENABLE_LINTERS) endif() function(rapidfuzz_add_test test) - add_executable(test_${test} tests-main.cpp tests-${test}.cpp) - target_link_libraries(test_${test} ${PROJECT_NAME}) - target_link_libraries(test_${test} Catch2::Catch2) + if(Catch2_VERSION VERSION_LESS "3.0") + add_executable(test_${test} tests-main.cpp tests-${test}.cpp) + target_link_libraries(test_${test} PRIVATE Catch2::Catch2) + target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=2) + else() + add_executable(test_${test} tests-${test}.cpp) + target_link_libraries(test_${test} PRIVATE Catch2::Catch2WithMain) + target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=3) + endif() + + target_link_libraries(test_${test} PRIVATE ${PROJECT_NAME}) if (RAPIDFUZZ_ENABLE_LINTERS) - target_link_libraries(test_${test} project_warnings) + target_link_libraries(test_${test} PRIVATE project_warnings) endif() add_test(NAME ${test} COMMAND test_${test}) endfunction() diff --git a/test/distance/CMakeLists.txt b/test/distance/CMakeLists.txt index 93870c86..412d3daa 100644 --- a/test/distance/CMakeLists.txt +++ b/test/distance/CMakeLists.txt @@ -1,7 +1,15 @@ function(rapidfuzz_add_test test) - add_executable(test_${test} ../tests-main.cpp tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp) + if(Catch2_VERSION VERSION_LESS "3.0") + add_executable(test_${test} ../tests-main.cpp tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp) + target_link_libraries(test_${test} PRIVATE Catch2::Catch2) + target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=2) + else() + add_executable(test_${test} tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp) + target_link_libraries(test_${test} PRIVATE Catch2::Catch2WithMain) + target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=3) + endif() + target_link_libraries(test_${test} PRIVATE ${PROJECT_NAME}) - target_link_libraries(test_${test} PRIVATE Catch2::Catch2) if (RAPIDFUZZ_ENABLE_LINTERS) target_link_libraries(test_${test} PRIVATE project_warnings) endif() diff --git a/test/distance/tests-DamerauLevenshtein.cpp b/test/distance/tests-DamerauLevenshtein.cpp index 98e61036..37b78466 100644 --- a/test/distance/tests-DamerauLevenshtein.cpp +++ b/test/distance/tests-DamerauLevenshtein.cpp @@ -1,4 +1,10 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include #include #include diff --git a/test/distance/tests-Hamming.cpp b/test/distance/tests-Hamming.cpp index cb3b7195..5bf94e0f 100644 --- a/test/distance/tests-Hamming.cpp +++ b/test/distance/tests-Hamming.cpp @@ -1,4 +1,10 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include #include #include diff --git a/test/distance/tests-Indel.cpp b/test/distance/tests-Indel.cpp index d4204657..c8e49d14 100644 --- a/test/distance/tests-Indel.cpp +++ b/test/distance/tests-Indel.cpp @@ -1,4 +1,10 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include #include diff --git a/test/distance/tests-Jaro.cpp b/test/distance/tests-Jaro.cpp index 1bfb7341..cc077ece 100644 --- a/test/distance/tests-Jaro.cpp +++ b/test/distance/tests-Jaro.cpp @@ -1,5 +1,11 @@ +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include "../../rapidfuzz_reference/Jaro.hpp" -#include #include #include "../common.hpp" diff --git a/test/distance/tests-JaroWinkler.cpp b/test/distance/tests-JaroWinkler.cpp index f7f5fcdd..277053df 100644 --- a/test/distance/tests-JaroWinkler.cpp +++ b/test/distance/tests-JaroWinkler.cpp @@ -1,5 +1,11 @@ +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include "../../rapidfuzz_reference/JaroWinkler.hpp" -#include #include #include "../common.hpp" diff --git a/test/distance/tests-LCSseq.cpp b/test/distance/tests-LCSseq.cpp index 9510bd4b..369a58f2 100644 --- a/test/distance/tests-LCSseq.cpp +++ b/test/distance/tests-LCSseq.cpp @@ -1,4 +1,10 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include #include diff --git a/test/distance/tests-Levenshtein.cpp b/test/distance/tests-Levenshtein.cpp index d5037787..ae938786 100644 --- a/test/distance/tests-Levenshtein.cpp +++ b/test/distance/tests-Levenshtein.cpp @@ -1,4 +1,10 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include #include #include diff --git a/test/distance/tests-OSA.cpp b/test/distance/tests-OSA.cpp index 22c48a3c..e9328cde 100644 --- a/test/distance/tests-OSA.cpp +++ b/test/distance/tests-OSA.cpp @@ -1,4 +1,10 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif + #include #include #include diff --git a/test/tests-common.cpp b/test/tests-common.cpp index 9882bc98..ab7dc762 100644 --- a/test/tests-common.cpp +++ b/test/tests-common.cpp @@ -1,5 +1,11 @@ #include "rapidfuzz/details/Range.hpp" -#include + +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif #include diff --git a/test/tests-fuzz.cpp b/test/tests-fuzz.cpp index 5a2f111c..797ba039 100644 --- a/test/tests-fuzz.cpp +++ b/test/tests-fuzz.cpp @@ -1,4 +1,9 @@ -#include +#if CATCH2_VERSION == 2 +# include +#else +# include +# include +#endif #include diff --git a/test/tests-main.cpp b/test/tests-main.cpp index a45c7d61..e06520b3 100644 --- a/test/tests-main.cpp +++ b/test/tests-main.cpp @@ -1,3 +1,3 @@ // test main file so catch2 does not has to be recompiled #define CATCH_CONFIG_MAIN -#include "catch2/catch.hpp" \ No newline at end of file +#include \ No newline at end of file