Skip to content

Commit f65c3d1

Browse files
committed
fixed tests not building with catch2 versions >= 3.0
1 parent 6f34131 commit f65c3d1

15 files changed

+99
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
## [3.3.1] - 2025-01-22
4+
### Fixed
5+
- fixed tests not building with catch2 versions >= 3.0
6+
37
## [3.3.0] - 2025-01-18
48
### Changed
59
- add C++11 and C++14 support

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3232
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
3333
endif()
3434

35-
project(rapidfuzz LANGUAGES CXX VERSION 3.3.0)
35+
project(rapidfuzz LANGUAGES CXX VERSION 3.3.1)
3636

3737
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
3838
include(GNUInstallDirs)

test/CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
find_package(Catch2 2 QUIET)
1+
find_package(Catch2 QUIET)
22
if (Catch2_FOUND)
33
message("Using system supplied version of Catch2")
44
else()
@@ -10,6 +10,7 @@ else()
1010
GIT_TAG v2.13.10
1111
)
1212
FetchContent_MakeAvailable(Catch2)
13+
set(Catch2_VERSION "2.13.10")
1314
endif()
1415

1516
if (RAPIDFUZZ_ENABLE_LINTERS)
@@ -50,11 +51,19 @@ if (RAPIDFUZZ_ENABLE_LINTERS)
5051
endif()
5152

5253
function(rapidfuzz_add_test test)
53-
add_executable(test_${test} tests-main.cpp tests-${test}.cpp)
54-
target_link_libraries(test_${test} ${PROJECT_NAME})
55-
target_link_libraries(test_${test} Catch2::Catch2)
54+
if(Catch2_VERSION VERSION_LESS "3.0")
55+
add_executable(test_${test} tests-main.cpp tests-${test}.cpp)
56+
target_link_libraries(test_${test} PRIVATE Catch2::Catch2)
57+
target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=2)
58+
else()
59+
add_executable(test_${test} tests-${test}.cpp)
60+
target_link_libraries(test_${test} PRIVATE Catch2::Catch2WithMain)
61+
target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=3)
62+
endif()
63+
64+
target_link_libraries(test_${test} PRIVATE ${PROJECT_NAME})
5665
if (RAPIDFUZZ_ENABLE_LINTERS)
57-
target_link_libraries(test_${test} project_warnings)
66+
target_link_libraries(test_${test} PRIVATE project_warnings)
5867
endif()
5968
add_test(NAME ${test} COMMAND test_${test})
6069
endfunction()

test/distance/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
function(rapidfuzz_add_test test)
2-
add_executable(test_${test} ../tests-main.cpp tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
2+
if(Catch2_VERSION VERSION_LESS "3.0")
3+
add_executable(test_${test} ../tests-main.cpp tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
4+
target_link_libraries(test_${test} PRIVATE Catch2::Catch2)
5+
target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=2)
6+
else()
7+
add_executable(test_${test} tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
8+
target_link_libraries(test_${test} PRIVATE Catch2::Catch2WithMain)
9+
target_compile_definitions(test_${test} PRIVATE CATCH2_VERSION=3)
10+
endif()
11+
312
target_link_libraries(test_${test} PRIVATE ${PROJECT_NAME})
4-
target_link_libraries(test_${test} PRIVATE Catch2::Catch2)
513
if (RAPIDFUZZ_ENABLE_LINTERS)
614
target_link_libraries(test_${test} PRIVATE project_warnings)
715
endif()

test/distance/tests-DamerauLevenshtein.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
28
#include <rapidfuzz/details/Range.hpp>
39
#include <rapidfuzz/details/types.hpp>
410
#include <string>

test/distance/tests-Hamming.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
28
#include <rapidfuzz/distance.hpp>
39
#include <rapidfuzz/distance/Hamming.hpp>
410
#include <string>

test/distance/tests-Indel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
28
#include <string>
39

410
#include <rapidfuzz/distance.hpp>

test/distance/tests-Jaro.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
18
#include "../../rapidfuzz_reference/Jaro.hpp"
2-
#include <catch2/catch.hpp>
39
#include <rapidfuzz/distance/Jaro.hpp>
410

511
#include "../common.hpp"

test/distance/tests-JaroWinkler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
18
#include "../../rapidfuzz_reference/JaroWinkler.hpp"
2-
#include <catch2/catch.hpp>
39
#include <rapidfuzz/distance/JaroWinkler.hpp>
410

511
#include "../common.hpp"

test/distance/tests-LCSseq.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
28
#include <rapidfuzz/distance/LCSseq.hpp>
39
#include <string>
410

test/distance/tests-Levenshtein.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
28
#include <rapidfuzz/details/Range.hpp>
39
#include <rapidfuzz/details/types.hpp>
410
#include <rapidfuzz/distance/Levenshtein.hpp>

test/distance/tests-OSA.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
7+
28
#include <rapidfuzz/details/types.hpp>
39
#include <rapidfuzz/distance/OSA.hpp>
410
#include <string>

test/tests-common.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include "rapidfuzz/details/Range.hpp"
2-
#include <catch2/catch.hpp>
2+
3+
#if CATCH2_VERSION == 2
4+
# include <catch2/catch.hpp>
5+
#else
6+
# include <catch2/catch_approx.hpp>
7+
# include <catch2/catch_test_macros.hpp>
8+
#endif
39

410
#include <rapidfuzz/details/common.hpp>
511

test/tests-fuzz.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#include <catch2/catch.hpp>
1+
#if CATCH2_VERSION == 2
2+
# include <catch2/catch.hpp>
3+
#else
4+
# include <catch2/catch_test_macros.hpp>
5+
# include <catch2/matchers/catch_matchers_floating_point.hpp>
6+
#endif
27

38
#include <rapidfuzz/fuzz.hpp>
49

test/tests-main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// test main file so catch2 does not has to be recompiled
22
#define CATCH_CONFIG_MAIN
3-
#include "catch2/catch.hpp"
3+
#include <catch2/catch.hpp>

0 commit comments

Comments
 (0)