2017-01-16 13:52:01 +00:00
|
|
|
if(ENABLE_CJSON_TEST)
|
2018-09-04 19:25:15 +00:00
|
|
|
add_library(unity STATIC unity/src/unity.c)
|
2017-02-28 19:48:04 +00:00
|
|
|
|
2017-03-01 07:56:17 +00:00
|
|
|
# Disable -Werror for Unity
|
2017-03-15 23:22:53 +00:00
|
|
|
if (FLAG_SUPPORTED_Werror)
|
2017-03-16 00:09:26 +00:00
|
|
|
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
|
|
|
|
else()
|
|
|
|
target_compile_options(unity PRIVATE "-Wno-error")
|
|
|
|
endif()
|
2017-03-01 07:56:17 +00:00
|
|
|
endif()
|
2017-03-01 22:16:47 +00:00
|
|
|
# Disable -fvisibility=hidden for Unity
|
2017-03-15 23:22:53 +00:00
|
|
|
if (FLAG_SUPPORTED_fvisibilityhidden)
|
2017-03-16 00:09:26 +00:00
|
|
|
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
|
|
|
|
else()
|
|
|
|
target_compile_options(unity PRIVATE "-fvisibility=default")
|
|
|
|
endif()
|
2017-03-01 22:16:47 +00:00
|
|
|
endif()
|
2017-03-21 18:02:55 +00:00
|
|
|
# Disable -fsanitize=float-divide-by-zero for Unity (GCC bug on x86 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80097)
|
|
|
|
if (FLAG_SUPPORTED_fsanitizefloatdividebyzero AND (CMAKE_C_COMPILER_ID STREQUAL "GNU"))
|
|
|
|
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero")
|
|
|
|
else()
|
|
|
|
target_compile_options(unity PRIVATE "-fno-sanitize=float-divide-by-zero")
|
|
|
|
endif()
|
|
|
|
endif()
|
2017-05-09 23:21:13 +00:00
|
|
|
# Disable -Wswitch-enum for Unity
|
|
|
|
if (FLAG_SUPPORTED_Wswitchenum)
|
|
|
|
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum")
|
|
|
|
else()
|
|
|
|
target_compile_options(unity PRIVATE "-Wno-switch-enum")
|
|
|
|
endif()
|
|
|
|
endif()
|
2017-03-01 07:56:17 +00:00
|
|
|
|
2017-01-16 13:52:01 +00: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 00:53:55 +00:00
|
|
|
parse_number
|
2017-01-17 18:44:38 +00:00
|
|
|
parse_hex4
|
2017-02-04 01:12:10 +00:00
|
|
|
parse_string
|
2017-02-06 15:27:59 +00:00
|
|
|
parse_array
|
2017-02-07 19:24:59 +00:00
|
|
|
parse_object
|
2017-02-07 19:39:45 +00:00
|
|
|
parse_value
|
2017-02-19 16:25:22 +00:00
|
|
|
print_string
|
2017-02-20 00:25:19 +00:00
|
|
|
print_number
|
2017-02-20 01:12:13 +00:00
|
|
|
print_array
|
2017-02-20 01:30:37 +00:00
|
|
|
print_object
|
2017-02-20 01:43:18 +00:00
|
|
|
print_value
|
2017-02-21 08:17:49 +00:00
|
|
|
misc_tests
|
2017-03-21 22:40:50 +00:00
|
|
|
parse_with_opts
|
2017-04-06 11:02:38 +00:00
|
|
|
compare_tests
|
2017-12-28 21:56:57 +00:00
|
|
|
cjson_add
|
2017-12-30 01:24:06 +00:00
|
|
|
readme_examples
|
2019-04-14 21:13:41 +00:00
|
|
|
minify_tests
|
2017-01-16 13:52:01 +00:00
|
|
|
)
|
|
|
|
|
2017-01-18 15:18:35 +00: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()
|
2017-09-08 11:19:41 +00:00
|
|
|
set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/../valgrind.supp)
|
2017-01-18 15:18:35 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-01-16 13:52:01 +00:00
|
|
|
foreach(unity_test ${unity_tests})
|
|
|
|
add_executable("${unity_test}" "${unity_test}.c")
|
2018-09-04 19:25:15 +00:00
|
|
|
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
|
|
|
target_sources(${unity_test} PRIVATE unity_setup.c)
|
|
|
|
endif()
|
2017-11-28 15:44:24 +00:00
|
|
|
target_link_libraries("${unity_test}" "${CJSON_LIB}" unity)
|
2017-01-18 15:18:35 +00:00
|
|
|
if(MEMORYCHECK_COMMAND)
|
|
|
|
add_test(NAME "${unity_test}"
|
2017-03-14 23:23:48 +00:00
|
|
|
COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${unity_test}")
|
2017-01-18 15:18:35 +00:00
|
|
|
else()
|
|
|
|
add_test(NAME "${unity_test}"
|
|
|
|
COMMAND "./${unity_test}")
|
|
|
|
endif()
|
2017-01-16 13:52:01 +00:00
|
|
|
endforeach()
|
2017-03-15 23:22:53 +00:00
|
|
|
|
|
|
|
add_dependencies(check ${unity_tests})
|
2017-04-12 17:15:53 +00:00
|
|
|
|
|
|
|
if (ENABLE_CJSON_UTILS)
|
|
|
|
#copy test files
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests")
|
|
|
|
file(GLOB test_files "json-patch-tests/*")
|
|
|
|
file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests/")
|
|
|
|
|
|
|
|
set (cjson_utils_tests
|
2017-04-18 12:11:14 +00:00
|
|
|
json_patch_tests
|
2017-06-28 14:01:20 +00:00
|
|
|
old_utils_tests
|
|
|
|
misc_utils_tests)
|
2017-04-12 17:15:53 +00:00
|
|
|
|
|
|
|
foreach (cjson_utils_test ${cjson_utils_tests})
|
|
|
|
add_executable("${cjson_utils_test}" "${cjson_utils_test}.c")
|
2017-11-28 15:44:24 +00:00
|
|
|
target_link_libraries("${cjson_utils_test}" "${CJSON_LIB}" "${CJSON_UTILS_LIB}" unity)
|
2019-05-10 23:37:33 +00:00
|
|
|
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
|
|
|
target_sources(${cjson_utils_test} PRIVATE unity_setup.c)
|
|
|
|
endif()
|
2017-04-12 17:15:53 +00:00
|
|
|
if(MEMORYCHECK_COMMAND)
|
|
|
|
add_test(NAME "${cjson_utils_test}"
|
|
|
|
COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${cjson_utils_test}")
|
|
|
|
else()
|
|
|
|
add_test(NAME "${cjson_utils_test}"
|
|
|
|
COMMAND "./${cjson_utils_test}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_dependencies(check ${cjson_utils_tests})
|
|
|
|
endif()
|
2017-01-16 13:52:01 +00:00
|
|
|
endif()
|