diff --git a/test/targets/clang_file.yml b/test/targets/clang_file.yml index a14205a..470a728 100644 --- a/test/targets/clang_file.yml +++ b/test/targets/clang_file.yml @@ -28,7 +28,7 @@ compiler: - '-Wstrict-overflow=5' - '-Wuninitialized' - '-Wunused' - - '-Wunreachable-code' +# - '-Wunreachable-code' - '-Wreturn-type' - '-Wshadow' - '-Wundef' @@ -57,6 +57,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_64 - UNITY_OUTPUT_RESULTS_FILE @@ -65,7 +66,7 @@ compiler: extension: '.o' destination: *build_path linker: - path: gcc + path: clang options: - -lm - '-m64' diff --git a/test/targets/clang_strict.yml b/test/targets/clang_strict.yml index 3e2bdc2..da76aed 100644 --- a/test/targets/clang_strict.yml +++ b/test/targets/clang_strict.yml @@ -28,7 +28,7 @@ compiler: - '-Wstrict-overflow=5' - '-Wuninitialized' - '-Wunused' - - '-Wunreachable-code' +# - '-Wunreachable-code' - '-Wreturn-type' - '-Wshadow' - '-Wundef' @@ -57,6 +57,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES - UNITY_SUPPORT_64 @@ -65,7 +66,7 @@ compiler: extension: '.o' destination: *build_path linker: - path: gcc + path: clang options: - -lm - '-m64' diff --git a/test/targets/gcc_32.yml b/test/targets/gcc_32.yml index dbed355..3b7ac41 100644 --- a/test/targets/gcc_32.yml +++ b/test/targets/gcc_32.yml @@ -19,6 +19,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_EXCLUDE_STDINT_H - UNITY_EXCLUDE_LIMITS_H - UNITY_EXCLUDE_SIZEOF diff --git a/test/targets/gcc_64.yml b/test/targets/gcc_64.yml index 8f60340..04a2a70 100644 --- a/test/targets/gcc_64.yml +++ b/test/targets/gcc_64.yml @@ -19,6 +19,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_EXCLUDE_STDINT_H - UNITY_EXCLUDE_LIMITS_H - UNITY_EXCLUDE_SIZEOF diff --git a/test/targets/gcc_auto_limits.yml b/test/targets/gcc_auto_limits.yml index 72ed555..feec894 100644 --- a/test/targets/gcc_auto_limits.yml +++ b/test/targets/gcc_auto_limits.yml @@ -19,6 +19,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_EXCLUDE_STDINT_H - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES diff --git a/test/targets/gcc_auto_sizeof.yml b/test/targets/gcc_auto_sizeof.yml index b7076ea..9a1f9cf 100644 --- a/test/targets/gcc_auto_sizeof.yml +++ b/test/targets/gcc_auto_sizeof.yml @@ -19,8 +19,9 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_EXCLUDE_STDINT_H - - UNITY_EXCLUDE_LIMTIS_H + - UNITY_EXCLUDE_LIMITS_H - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES - UNITY_SUPPORT_64 diff --git a/test/targets/gcc_auto_stdint.yml b/test/targets/gcc_auto_stdint.yml index 0405629..bf358f8 100644 --- a/test/targets/gcc_auto_stdint.yml +++ b/test/targets/gcc_auto_stdint.yml @@ -32,6 +32,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES - UNITY_SUPPORT_64 diff --git a/test/targets/gcc_manual_math.yml b/test/targets/gcc_manual_math.yml index 64ea3f9..b910046 100644 --- a/test/targets/gcc_manual_math.yml +++ b/test/targets/gcc_manual_math.yml @@ -19,6 +19,7 @@ compiler: defines: prefix: '-D' items: + - UNITY_OUTPUT_CHAR=putcharSpy - UNITY_EXCLUDE_MATH_H - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index e0d86e2..52ac71f 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -5,8 +5,11 @@ ========================================== */ #include +#include #include "unity.h" +int putcharSpy(int c) {return putchar(c);} // include passthrough for linking tests + #define TEST_CASE(...) #define EXPECT_ABORT_BEGIN \ diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 7f775e8..215a02a 100755 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -2158,8 +2158,122 @@ void testIgnoredAndThenFailInTearDown(void) TEST_IGNORE(); } +// Tricky series of macros to set USING_OUTPUT_SPY +#define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) +#define ASSIGN_VALUE(a) VAL_FUNC_##a +#define VAL_FUNC_putcharSpy() 0, 1 +#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway) +#define SECOND_PARAM(a, b, ...) b +#if USING_SPY_AS(UNITY_OUTPUT_CHAR()) + #define USING_OUTPUT_SPY // true only if UNITY_OUTPUT_CHAR = putchar_Spy +#endif + +#ifdef USING_OUTPUT_SPY +#include +#define SPY_BUFFER_MAX 40 +static char putcharSpyBuffer[SPY_BUFFER_MAX]; +#endif +static int indexSpyBuffer; +static int putcharSpyEnabled; + +void startPutcharSpy(void) {indexSpyBuffer = 0; putcharSpyEnabled = 1;} + +void endPutcharSpy(void) {putcharSpyEnabled = 0;} + +char* getBufferPutcharSpy(void) +{ +#ifdef USING_OUTPUT_SPY + putcharSpyBuffer[indexSpyBuffer] = '\0'; + return putcharSpyBuffer; +#else + return NULL; +#endif +} + +int putcharSpy(int c) +{ +#ifdef USING_OUTPUT_SPY + if (putcharSpyEnabled) + { + if (indexSpyBuffer < SPY_BUFFER_MAX - 1) + putcharSpyBuffer[indexSpyBuffer++] = (char)c; + } else + c = putchar(c); +#endif + return c; +} + +#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \ + startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \ + TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ + } + +#define TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS(expected, actual) { \ + startPutcharSpy(); UnityPrintNumberUnsigned((actual)); endPutcharSpy(); \ + TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ + } + +void testPrintNumbers32(void) +{ +#ifndef USING_OUTPUT_SPY + TEST_IGNORE_MESSAGE("Compile with '-D UNITY_OUTPUT_CHAR=putcharSpy' to enable print testing"); +#else + TEST_ASSERT_EQUAL_PRINT_NUMBERS("0", 0); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("1", 1); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("-1", -1); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("2000000000", 2000000000); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("-2147483648", (_US32)0x80000000); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("-1", (_US32)0xFFFFFFFF); +#endif +} + +void testPrintNumbersUnsigned32(void) +{ +#ifndef USING_OUTPUT_SPY + TEST_IGNORE(); +#else + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("0", 0); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("1", 1); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("1500000000", 1500000000); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("2147483648", (_UU32)0x80000000); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("4294967295", (_UU32)0xFFFFFFFF); +#endif +} + // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== +void testPrintNumbersInt64(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + #ifndef USING_OUTPUT_SPY + TEST_IGNORE(); + #else + TEST_ASSERT_EQUAL_PRINT_NUMBERS("0", 0); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("10000000000", 10000000000); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("-9223372036854775808", (_U_SINT)0x8000000000000000); + TEST_ASSERT_EQUAL_PRINT_NUMBERS("-1", (_U_SINT)0xFFFFFFFFFFFFFFFF); + #endif +#endif +} + +void testPrintNumbersUInt64(void) +{ +#ifndef UNITY_SUPPORT_64 + TEST_IGNORE(); +#else + #ifndef USING_OUTPUT_SPY + TEST_IGNORE(); + #else + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("0", 0); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("70000000000", 70000000000); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("9223372036854775808", (_U_UINT)0x8000000000000000); + TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS("18446744073709551615", (_U_UINT)0xFFFFFFFFFFFFFFFF); + #endif +#endif +} + void testEqualHex64s(void) { #ifndef UNITY_SUPPORT_64