2017-01-16 16:52:01 +03:00
|
|
|
if(ENABLE_CJSON_TEST)
|
2017-02-28 22:48:04 +03:00
|
|
|
add_library(unity unity/src/unity.c)
|
|
|
|
|
2017-03-01 10:56:17 +03:00
|
|
|
# Disable -Werror for Unity
|
|
|
|
list(FIND custom_compiler_flags "-Werror" werror_found)
|
|
|
|
if (werror_found)
|
|
|
|
target_compile_options(unity PRIVATE "-Wno-error")
|
|
|
|
endif()
|
2017-03-02 01:16:47 +03:00
|
|
|
# Disable -fvisibility=hidden for Unity
|
|
|
|
list(FIND custom_compiler_flags "-fvisibility=hidden" visibility_found)
|
|
|
|
if (visibility_found)
|
|
|
|
target_compile_options(unity PRIVATE "-fvisibility=default")
|
|
|
|
endif()
|
2017-03-01 10:56:17 +03:00
|
|
|
|
2017-01-16 16:52:01 +03:00
|
|
|
#copy test files
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")
|
|
|
|
file(GLOB test_files "inputs/*")
|
|
|
|
file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/")
|
|
|
|
|
|
|
|
set(unity_tests
|
|
|
|
parse_examples
|
2017-01-17 03:53:55 +03:00
|
|
|
parse_number
|
2017-01-17 21:44:38 +03:00
|
|
|
parse_hex4
|
2017-02-04 04:12:10 +03:00
|
|
|
parse_string
|
2017-02-06 18:27:59 +03:00
|
|
|
parse_array
|
2017-02-07 22:24:59 +03:00
|
|
|
parse_object
|
2017-02-07 22:39:45 +03:00
|
|
|
parse_value
|
2017-02-19 19:25:22 +03:00
|
|
|
print_string
|
2017-02-20 03:25:19 +03:00
|
|
|
print_number
|
2017-02-20 04:12:13 +03:00
|
|
|
print_array
|
2017-02-20 04:30:37 +03:00
|
|
|
print_object
|
2017-02-20 04:43:18 +03:00
|
|
|
print_value
|
2017-02-21 11:17:49 +03:00
|
|
|
misc_tests
|
2017-01-16 16:52:01 +03:00
|
|
|
)
|
|
|
|
|
2017-02-15 20:41:55 +03:00
|
|
|
add_library(test-common common.c)
|
|
|
|
|
2017-01-18 18:18:35 +03:00
|
|
|
option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
|
|
|
|
if (ENABLE_VALGRIND)
|
|
|
|
find_program(MEMORYCHECK_COMMAND valgrind)
|
|
|
|
if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
|
|
|
|
message(WARNING "Valgrind couldn't be found.")
|
|
|
|
unset(MEMORYCHECK_COMMAND)
|
|
|
|
else()
|
|
|
|
set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-02-17 15:59:26 +03:00
|
|
|
#"check" target that automatically builds everything and runs the tests
|
|
|
|
add_custom_target(check
|
|
|
|
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
|
|
|
|
DEPENDS ${unity_tests})
|
|
|
|
|
2017-01-16 16:52:01 +03:00
|
|
|
foreach(unity_test ${unity_tests})
|
|
|
|
add_executable("${unity_test}" "${unity_test}.c")
|
2017-02-15 20:41:55 +03:00
|
|
|
target_link_libraries("${unity_test}" "${CJSON_LIB}" unity test-common)
|
2017-01-18 18:18:35 +03:00
|
|
|
if(MEMORYCHECK_COMMAND)
|
|
|
|
add_test(NAME "${unity_test}"
|
|
|
|
COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "./${unity_test}")
|
|
|
|
else()
|
|
|
|
add_test(NAME "${unity_test}"
|
|
|
|
COMMAND "./${unity_test}")
|
|
|
|
endif()
|
2017-01-16 16:52:01 +03:00
|
|
|
endforeach()
|
|
|
|
endif()
|