Skip to content

Commit fa3520a

Browse files
committed
allow testeval to use a non-flag filename argument and cleaned up tests
1 parent 0b49071 commit fa3520a

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
CMakeFiles/
3+
Testing/
34
**/build/
45
.cache/
56
CMakeCache.txt

cpp/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ if(JSONLOGIC_ENABLE_BENCH)
6262
endif()
6363
if(JSONLOGIC_ENABLE_TESTS)
6464
message(STATUS "Building tests: ${JSONLOGIC_ENABLE_TESTS}")
65-
enable_testing()
65+
include(CTest)
66+
67+
# Enable parallel testing by default
68+
include(ProcessorCount)
69+
ProcessorCount(N)
70+
if(NOT N EQUAL 0)
71+
set(CTEST_BUILD_FLAGS -j${N})
72+
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
73+
endif()
74+
6675
add_subdirectory(tests)
6776
endif()

cpp/tests/CMakeLists.txt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,28 @@ add_executable(testeval src/testeval.cpp)
22
target_link_libraries(testeval PRIVATE jsonlogic Boost::json Boost::lexical_cast Boost::range)
33
target_include_directories(testeval PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
44

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-
125
# Get all JSON test files
136
file(GLOB_RECURSE JSON_TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/json/*.json")
147

158
# Add individual tests for each JSON file (normal mode)
169
foreach(json_file ${JSON_TEST_FILES})
1710
get_filename_component(test_name ${json_file} NAME_WE)
1811
add_test(NAME "jsonlogic_${test_name}"
19-
COMMAND bash -c "cat '${json_file}' | $<TARGET_FILE:testeval>"
12+
COMMAND testeval "${json_file}"
2013
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
2114
set_tests_properties("jsonlogic_${test_name}" PROPERTIES
2215
LABELS "jsonlogic;normal"
2316
TIMEOUT 5
24-
FIXTURES_REQUIRED testeval_fixture)
17+
)
2518
endforeach()
2619

2720
# Add individual tests for each JSON file (strict mode)
2821
foreach(json_file ${JSON_TEST_FILES})
2922
get_filename_component(test_name ${json_file} NAME_WE)
3023
add_test(NAME "jsonlogic_${test_name}_strict"
31-
COMMAND bash -c "cat '${json_file}' | $<TARGET_FILE:testeval> -s"
24+
COMMAND testeval -s "${json_file}"
3225
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
3326
set_tests_properties("jsonlogic_${test_name}_strict" PROPERTIES
3427
LABELS "jsonlogic;strict"
35-
TIMEOUT 5
36-
FIXTURES_REQUIRED testeval_fixture)
28+
TIMEOUT 5)
3729
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")

cpp/tests/src/testeval.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#include <boost/json/src.hpp>
33
#include <boost/lexical_cast.hpp>
44
#include <boost/range/adaptor/transformed.hpp>
5+
#include <cstdint>
56
#include <fstream>
67
#include <iostream>
7-
#include <sstream>
8-
98
#include <jsonlogic/logic.hpp>
9+
#include <sstream>
10+
#include <vector>
1011

1112
enum class ResultStatus : std::uint8_t {
1213
NoError = 0, // no error
@@ -105,9 +106,11 @@ bool matchOpt0(const std::vector<std::string> &args, N &pos,
105106
}
106107

107108
template <class N, class Fn>
108-
bool noSwitch0(const std::vector<std::string> &args, N &pos, Fn /*fn*/) {
109-
//~ if (fn(args[pos]))
110-
//~ return true;
109+
bool noSwitch0(const std::vector<std::string> &args, N &pos, Fn fn) {
110+
if (fn(args[pos])) {
111+
++pos;
112+
return true;
113+
}
111114

112115
std::cerr << "unrecognized argument: " << args[pos] << std::endl;
113116
++pos;
@@ -254,7 +257,10 @@ int main(int argc, const char **argv) {
254257
exit(1);
255258
}
256259

257-
bjsn::value all = parseStream(std::cin);
260+
bjsn::value all = config.filename.empty() ? parseStream(std::cin)
261+
: parseFile(config.filename);
262+
263+
// parseStream(config.filename.empty() ? std::cin : config.filename);
258264
bjsn::object &allobj = all.as_object();
259265

260266
bjsn::value rule = allobj["rule"];

0 commit comments

Comments
 (0)