diff --git a/.travis.yml b/.travis.yml index d97d210..251e5c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ - cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION ../test - make - ./utest_test + - ./utest_test_wpo diff --git a/.travis.yml b/.travis.yml index d97d210..251e5c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ - cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION ../test - make - ./utest_test + - ./utest_test_wpo diff --git a/appveyor.yml b/appveyor.yml index 86fc235..269f39e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,8 @@ - VSVERSION: Visual Studio 14 2015 - VSVERSION: Visual Studio 15 2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + - VSVERSION: Visual Studio 16 2019 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 platform: - Win32 @@ -32,10 +34,13 @@ build_script: - md build - cd build - - if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test - - if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if "%VSVERSION%"=="Visual Studio 16 2019" cmake -G "%VSVERSION%" -A "%PLATFORM%" ../test - msbuild /m /p:Configuration="%CONFIGURATION%" /p:Platform="%PLATFORM%" utest.sln - copy %CONFIGURATION%\utest_test.exe utest_test.exe + - copy %CONFIGURATION%\utest_test_wpo.exe utest_test_wpo.exe test_script: - utest_test.exe + - utest_test_wpo.exe diff --git a/.travis.yml b/.travis.yml index d97d210..251e5c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ - cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION ../test - make - ./utest_test + - ./utest_test_wpo diff --git a/appveyor.yml b/appveyor.yml index 86fc235..269f39e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,8 @@ - VSVERSION: Visual Studio 14 2015 - VSVERSION: Visual Studio 15 2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + - VSVERSION: Visual Studio 16 2019 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 platform: - Win32 @@ -32,10 +34,13 @@ build_script: - md build - cd build - - if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test - - if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if "%VSVERSION%"=="Visual Studio 16 2019" cmake -G "%VSVERSION%" -A "%PLATFORM%" ../test - msbuild /m /p:Configuration="%CONFIGURATION%" /p:Platform="%PLATFORM%" utest.sln - copy %CONFIGURATION%\utest_test.exe utest_test.exe + - copy %CONFIGURATION%\utest_test_wpo.exe utest_test_wpo.exe test_script: - utest_test.exe + - utest_test_wpo.exe diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e137a37..94ef9b2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,17 +28,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) -add_executable(utest_test - ../utest.h - main.c - test.c - test.cpp - test11.cpp - stdint_include.c - type_printers.c - type_printers.cpp -) - if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX) if (${IDX} GREATER -1) @@ -91,3 +80,31 @@ else() message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!") endif() + +add_executable(utest_test + ../utest.h + main.c + test.c + test.cpp + test11.cpp + stdint_include.c + type_printers.c + type_printers.cpp +) + +add_executable(utest_test_wpo + ../utest.h + main.c + test.c + test.cpp + test11.cpp + stdint_include.c + type_printers.c + type_printers.cpp +) + + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_options(utest_test_wpo PRIVATE "$<$:/GL>") + target_link_options(utest_test_wpo PRIVATE "$<$:/LTCG>") +endif() diff --git a/.travis.yml b/.travis.yml index d97d210..251e5c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ - cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION ../test - make - ./utest_test + - ./utest_test_wpo diff --git a/appveyor.yml b/appveyor.yml index 86fc235..269f39e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,8 @@ - VSVERSION: Visual Studio 14 2015 - VSVERSION: Visual Studio 15 2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + - VSVERSION: Visual Studio 16 2019 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 platform: - Win32 @@ -32,10 +34,13 @@ build_script: - md build - cd build - - if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test - - if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if "%VSVERSION%"=="Visual Studio 16 2019" cmake -G "%VSVERSION%" -A "%PLATFORM%" ../test - msbuild /m /p:Configuration="%CONFIGURATION%" /p:Platform="%PLATFORM%" utest.sln - copy %CONFIGURATION%\utest_test.exe utest_test.exe + - copy %CONFIGURATION%\utest_test_wpo.exe utest_test_wpo.exe test_script: - utest_test.exe + - utest_test_wpo.exe diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e137a37..94ef9b2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,17 +28,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) -add_executable(utest_test - ../utest.h - main.c - test.c - test.cpp - test11.cpp - stdint_include.c - type_printers.c - type_printers.cpp -) - if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX) if (${IDX} GREATER -1) @@ -91,3 +80,31 @@ else() message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!") endif() + +add_executable(utest_test + ../utest.h + main.c + test.c + test.cpp + test11.cpp + stdint_include.c + type_printers.c + type_printers.cpp +) + +add_executable(utest_test_wpo + ../utest.h + main.c + test.c + test.cpp + test11.cpp + stdint_include.c + type_printers.c + type_printers.cpp +) + + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_options(utest_test_wpo PRIVATE "$<$:/GL>") + target_link_options(utest_test_wpo PRIVATE "$<$:/LTCG>") +endif() diff --git a/test/main.c b/test/main.c index 4b5bbcd..0f4329c 100644 --- a/test/main.c +++ b/test/main.c @@ -31,12 +31,16 @@ const char *command[3] = {"utest_test", "--list-tests", 0}; int return_code; FILE *stdout_file; - size_t index; + size_t index, kndex; + char *hits; // 64k should be enough for anyone #define MAX_CHARS (64 * 1024) char buffer[MAX_CHARS] = {0}; + hits = (char *)malloc(utest_state.tests_length); + memset(hits, 0, utest_state.tests_length); + ASSERT_EQ(0, process_create(command, process_option_combined_stdout_stderr, &process)); @@ -54,8 +58,22 @@ #endif #endif - ASSERT_EQ(0, strncmp(buffer, utest_state.tests[index].name, - strlen(utest_state.tests[index].name))); + // First wipe out the newlines from the fgets. + for (kndex = 0;; kndex++) { + if ((buffer[kndex] == '\r') || (buffer[kndex] == '\n')) { + buffer[kndex] = '\0'; + break; + } + } + + // Record the hit for listed test. + for (kndex = 0; kndex < utest_state.tests_length; kndex++) { + if (0 == strcmp(buffer, utest_state.tests[kndex].name)) { + ASSERT_EQ(hits[kndex], 0); + hits[kndex] = 1; + break; + } + } #if defined(__clang__) #if __has_warning("-Wdisabled-macro-expansion") @@ -68,6 +86,13 @@ ASSERT_EQ(0, return_code); ASSERT_EQ(0, process_destroy(&process)); + + // Run through all the hits and make sure we got exactly one for each. + for (kndex = 0; kndex < utest_state.tests_length; kndex++) { + ASSERT_EQ(hits[kndex], 1); + } + + free(hits); } UTEST_MAIN() diff --git a/.travis.yml b/.travis.yml index d97d210..251e5c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ - cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION ../test - make - ./utest_test + - ./utest_test_wpo diff --git a/appveyor.yml b/appveyor.yml index 86fc235..269f39e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,8 @@ - VSVERSION: Visual Studio 14 2015 - VSVERSION: Visual Studio 15 2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + - VSVERSION: Visual Studio 16 2019 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 platform: - Win32 @@ -32,10 +34,13 @@ build_script: - md build - cd build - - if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test - - if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="x64" cmake -G "%VSVERSION% Win64" ../test + - if NOT "%VSVERSION%"=="Visual Studio 16 2019" if "%PLATFORM%"=="Win32" cmake -G "%VSVERSION%" ../test + - if "%VSVERSION%"=="Visual Studio 16 2019" cmake -G "%VSVERSION%" -A "%PLATFORM%" ../test - msbuild /m /p:Configuration="%CONFIGURATION%" /p:Platform="%PLATFORM%" utest.sln - copy %CONFIGURATION%\utest_test.exe utest_test.exe + - copy %CONFIGURATION%\utest_test_wpo.exe utest_test_wpo.exe test_script: - utest_test.exe + - utest_test_wpo.exe diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e137a37..94ef9b2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,17 +28,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) -add_executable(utest_test - ../utest.h - main.c - test.c - test.cpp - test11.cpp - stdint_include.c - type_printers.c - type_printers.cpp -) - if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 IDX) if (${IDX} GREATER -1) @@ -91,3 +80,31 @@ else() message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!") endif() + +add_executable(utest_test + ../utest.h + main.c + test.c + test.cpp + test11.cpp + stdint_include.c + type_printers.c + type_printers.cpp +) + +add_executable(utest_test_wpo + ../utest.h + main.c + test.c + test.cpp + test11.cpp + stdint_include.c + type_printers.c + type_printers.cpp +) + + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_options(utest_test_wpo PRIVATE "$<$:/GL>") + target_link_options(utest_test_wpo PRIVATE "$<$:/LTCG>") +endif() diff --git a/test/main.c b/test/main.c index 4b5bbcd..0f4329c 100644 --- a/test/main.c +++ b/test/main.c @@ -31,12 +31,16 @@ const char *command[3] = {"utest_test", "--list-tests", 0}; int return_code; FILE *stdout_file; - size_t index; + size_t index, kndex; + char *hits; // 64k should be enough for anyone #define MAX_CHARS (64 * 1024) char buffer[MAX_CHARS] = {0}; + hits = (char *)malloc(utest_state.tests_length); + memset(hits, 0, utest_state.tests_length); + ASSERT_EQ(0, process_create(command, process_option_combined_stdout_stderr, &process)); @@ -54,8 +58,22 @@ #endif #endif - ASSERT_EQ(0, strncmp(buffer, utest_state.tests[index].name, - strlen(utest_state.tests[index].name))); + // First wipe out the newlines from the fgets. + for (kndex = 0;; kndex++) { + if ((buffer[kndex] == '\r') || (buffer[kndex] == '\n')) { + buffer[kndex] = '\0'; + break; + } + } + + // Record the hit for listed test. + for (kndex = 0; kndex < utest_state.tests_length; kndex++) { + if (0 == strcmp(buffer, utest_state.tests[kndex].name)) { + ASSERT_EQ(hits[kndex], 0); + hits[kndex] = 1; + break; + } + } #if defined(__clang__) #if __has_warning("-Wdisabled-macro-expansion") @@ -68,6 +86,13 @@ ASSERT_EQ(0, return_code); ASSERT_EQ(0, process_destroy(&process)); + + // Run through all the hits and make sure we got exactly one for each. + for (kndex = 0; kndex < utest_state.tests_length; kndex++) { + ASSERT_EQ(hits[kndex], 1); + } + + free(hits); } UTEST_MAIN() diff --git a/utest.h b/utest.h index 7e7f04f..5c77310 100644 --- a/utest.h +++ b/utest.h @@ -112,10 +112,24 @@ #define UTEST_PRIu64 "I64u" #define UTEST_INLINE __forceinline +#if defined(__cplusplus) +#define UTEST_C_FUNC extern "C" +#else +#define UTEST_C_FUNC +#endif + +#if defined(_WIN64) +#define UTEST_SYMBOL_PREFIX +#else +#define UTEST_SYMBOL_PREFIX "_" +#endif + #pragma section(".CRT$XCU", read) #define UTEST_INITIALIZER(f) \ static void __cdecl f(void); \ - __declspec(allocate(".CRT$XCU")) void(__cdecl * f##_)(void) = f; \ + __pragma(comment(linker, "/include:" UTEST_SYMBOL_PREFIX #f "_")); \ + UTEST_C_FUNC __declspec(allocate(".CRT$XCU")) void(__cdecl * f##_)(void) = \ + f; \ static void __cdecl f(void) #else #if defined(__linux__)