Skip to content

Commit 0b49071

Browse files
committed
tests are now handled via cmake.
1 parent 5593e65 commit 0b49071

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

cpp/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ if(JSONLOGIC_ENABLE_BENCH)
6262
endif()
6363
if(JSONLOGIC_ENABLE_TESTS)
6464
message(STATUS "Building tests: ${JSONLOGIC_ENABLE_TESTS}")
65+
enable_testing()
6566
add_subdirectory(tests)
6667
endif()
67-
68-
add_custom_target(test
69-
COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-tests.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/json
70-
COMMENT "Running tests with run_tests.sh"
71-
)
72-
add_dependencies(test testeval)

cpp/tests/CMakeLists.txt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
11
add_executable(testeval src/testeval.cpp)
22
target_link_libraries(testeval PRIVATE jsonlogic Boost::json Boost::lexical_cast Boost::range)
3-
target_include_directories(testeval PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
3+
target_include_directories(testeval PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
4+
5+
# Create a fixture setup test that builds testeval if needed
6+
add_test(NAME "build_testeval"
7+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target testeval)
8+
set_tests_properties("build_testeval" PROPERTIES
9+
LABELS "setup"
10+
FIXTURES_SETUP testeval_fixture)
11+
12+
# Get all JSON test files
13+
file(GLOB_RECURSE JSON_TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/json/*.json")
14+
15+
# Add individual tests for each JSON file (normal mode)
16+
foreach(json_file ${JSON_TEST_FILES})
17+
get_filename_component(test_name ${json_file} NAME_WE)
18+
add_test(NAME "jsonlogic_${test_name}"
19+
COMMAND bash -c "cat '${json_file}' | $<TARGET_FILE:testeval>"
20+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
21+
set_tests_properties("jsonlogic_${test_name}" PROPERTIES
22+
LABELS "jsonlogic;normal"
23+
TIMEOUT 5
24+
FIXTURES_REQUIRED testeval_fixture)
25+
endforeach()
26+
27+
# Add individual tests for each JSON file (strict mode)
28+
foreach(json_file ${JSON_TEST_FILES})
29+
get_filename_component(test_name ${json_file} NAME_WE)
30+
add_test(NAME "jsonlogic_${test_name}_strict"
31+
COMMAND bash -c "cat '${json_file}' | $<TARGET_FILE:testeval> -s"
32+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
33+
set_tests_properties("jsonlogic_${test_name}_strict" PROPERTIES
34+
LABELS "jsonlogic;strict"
35+
TIMEOUT 5
36+
FIXTURES_REQUIRED testeval_fixture)
37+
endforeach()
38+
39+
# Custom target to run tests with clean summary (excludes setup test)
40+
add_custom_target(test_clean
41+
COMMAND ${CMAKE_CTEST_COMMAND} --exclude-regex "^_setup_"
42+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
43+
COMMENT "Running tests with clean summary (excluding setup tests)")
44+
45+
# Custom target to run only jsonlogic tests
46+
add_custom_target(test_jsonlogic
47+
COMMAND ${CMAKE_CTEST_COMMAND} -L jsonlogic --exclude-regex "^_setup_"
48+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
49+
COMMENT "Running only jsonlogic tests")

0 commit comments

Comments
 (0)