Enable build and test on Windows

This commit is contained in:
Zach Hindes 2018-09-04 14:25:15 -05:00
parent f32703a7a1
commit ad2cb5b7ea
5 changed files with 18 additions and 2 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
* text=auto
/tests/inputs/* text eol=lf

View File

@ -54,6 +54,8 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS)
/Za
/sdl
/W4
/wd4001
/D_CRT_SECURE_NO_WARNINGS
)
endif()
endif()

View File

@ -1,5 +1,5 @@
if(ENABLE_CJSON_TEST)
add_library(unity "${CJSON_LIBRARY_TYPE}" unity/src/unity.c)
add_library(unity STATIC unity/src/unity.c)
# Disable -Werror for Unity
if (FLAG_SUPPORTED_Werror)
@ -72,6 +72,9 @@ if(ENABLE_CJSON_TEST)
foreach(unity_test ${unity_tests})
add_executable("${unity_test}" "${unity_test}.c")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
target_sources(${unity_test} PRIVATE unity_setup.c)
endif()
target_link_libraries("${unity_test}" "${CJSON_LIB}" unity)
if(MEMORYCHECK_COMMAND)
add_test(NAME "${unity_test}"

View File

@ -34,9 +34,15 @@ static void *failing_malloc(size_t size)
return NULL;
}
/* work around MSVC error C2322: '...' address of dillimport '...' is not static */
static void CJSON_CDECL normal_free(void *pointer)
{
free(pointer);
}
static cJSON_Hooks failing_hooks = {
failing_malloc,
free
normal_free
};
static void cjson_add_null_should_add_null(void)

3
tests/unity_setup.c Normal file
View File

@ -0,0 +1,3 @@
// msvc doesn't support weak-linking, so we need to define these functions.
void setUp(void) { }
void tearDown(void) { }