Skip to content

Commit

Permalink
fixed tests not building with catch2 versions >= 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Jan 22, 2025
1 parent 6f34131 commit f65c3d1
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Catch2 2 QUIET)
find_package(Catch2 QUIET)
if (Catch2_FOUND)
message("Using system supplied version of Catch2")
else()
Expand All @@ -10,6 +10,7 @@ else()
GIT_TAG v2.13.10
)
FetchContent_MakeAvailable(Catch2)
set(Catch2_VERSION "2.13.10")
endif()

if (RAPIDFUZZ_ENABLE_LINTERS)
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions test/distance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-DamerauLevenshtein.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <rapidfuzz/details/Range.hpp>
#include <rapidfuzz/details/types.hpp>
#include <string>
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-Hamming.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <rapidfuzz/distance.hpp>
#include <rapidfuzz/distance/Hamming.hpp>
#include <string>
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-Indel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <string>

#include <rapidfuzz/distance.hpp>
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-Jaro.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include "../../rapidfuzz_reference/Jaro.hpp"
#include <catch2/catch.hpp>
#include <rapidfuzz/distance/Jaro.hpp>

#include "../common.hpp"
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-JaroWinkler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include "../../rapidfuzz_reference/JaroWinkler.hpp"
#include <catch2/catch.hpp>
#include <rapidfuzz/distance/JaroWinkler.hpp>

#include "../common.hpp"
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-LCSseq.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <rapidfuzz/distance/LCSseq.hpp>
#include <string>

Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-Levenshtein.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <rapidfuzz/details/Range.hpp>
#include <rapidfuzz/details/types.hpp>
#include <rapidfuzz/distance/Levenshtein.hpp>
Expand Down
8 changes: 7 additions & 1 deletion test/distance/tests-OSA.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <rapidfuzz/details/types.hpp>
#include <rapidfuzz/distance/OSA.hpp>
#include <string>
Expand Down
8 changes: 7 additions & 1 deletion test/tests-common.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "rapidfuzz/details/Range.hpp"
#include <catch2/catch.hpp>

#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_approx.hpp>
# include <catch2/catch_test_macros.hpp>
#endif

#include <rapidfuzz/details/common.hpp>

Expand Down
7 changes: 6 additions & 1 deletion test/tests-fuzz.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include <catch2/catch.hpp>
#if CATCH2_VERSION == 2
# include <catch2/catch.hpp>
#else
# include <catch2/catch_test_macros.hpp>
# include <catch2/matchers/catch_matchers_floating_point.hpp>
#endif

#include <rapidfuzz/fuzz.hpp>

Expand Down
2 changes: 1 addition & 1 deletion test/tests-main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// test main file so catch2 does not has to be recompiled
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <catch2/catch.hpp>

0 comments on commit f65c3d1

Please sign in to comment.