Skip to content

Commit 23934ca

Browse files
committed
Enable Catch2 test framework
Signed-off-by: Cristian Le <[email protected]>
1 parent 833a836 commit 23934ca

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ if (NOT TARGET nlohmann_json_schema_validator::validator)
6161
endif ()
6262
endif ()
6363
endif ()
64+
# Fetch/Find Catch2
65+
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
66+
FetchContent_Declare(Catch2
67+
GIT_REPOSITORY https://github.com/catchorg/Catch2
68+
GIT_TAG v3.4.0
69+
FIND_PACKAGE_ARGS CONFIG
70+
)
71+
list(APPEND fetch_packages Catch2)
72+
else ()
73+
# Try to get system installed version
74+
find_package(Catch2 QUIET)
75+
if (NOT Catch2_FOUND)
76+
# If failed fetch the desired version
77+
FetchContent_Declare(Catch2
78+
GIT_REPOSITORY https://github.com/catchorg/Catch2
79+
GIT_TAG v3.4.0
80+
)
81+
list(APPEND fetch_packages Catch2)
82+
endif ()
83+
endif ()
6484

6585
# Get all dependencies
6686
FetchContent_MakeAvailable(${fetch_packages})
@@ -70,6 +90,14 @@ FetchContent_MakeAvailable(${fetch_packages})
7090
]==============================================================================================]
7191

7292
enable_testing()
93+
include(Catch)
94+
95+
add_executable(json-schema-test-suite)
96+
set_target_properties(json-schema-test-suite PROPERTIES
97+
OUTPUT_NAME test-suite
98+
)
99+
target_link_libraries(json-schema-test-suite PRIVATE Catch2::Catch2WithMain nlohmann_json_schema_validator::validator)
100+
catch_discover_tests(json-schema-test-suite)
73101

74102
set(PIPE_IN_TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/test-pipe-in.sh)
75103

0 commit comments

Comments
 (0)