From 83148364a541b1fc75caed56a301cd03489f65bb Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 09:00:45 +0000 Subject: [PATCH 01/20] Fix For Issue #10 - TEST_ASSERT_EQUAL_FLOAT doesn't fail if actual value is a NaN. --- src/unity.c | 3 ++- test/testunity.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 0219b37..3787591 100644 --- a/src/unity.c +++ b/src/unity.c @@ -578,7 +578,8 @@ void UnityAssertFloatsWithin(const _UF delta, pos_delta = 0.0f - pos_delta; } - if (pos_delta < diff) + // NOTE: This comparrison is deliberately this way round so that NaNs fail. + if ( ! (pos_delta >= diff) ) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE diff --git a/test/testunity.c b/test/testunity.c index e98ca8f..ddd80c5 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2226,6 +2226,17 @@ void testFloatsNotEqualNegative2(void) #endif } +void testFloatsNotEqualActualNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(85.963f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualFloatArrays(void) { #ifdef UNITY_EXCLUDE_FLOAT From 5027763534c6dc294e4f6ed4381976f1aac1b8f7 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 09:29:54 +0000 Subject: [PATCH 02/20] Fixed typo in comment. --- src/unity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 3787591..8188345 100644 --- a/src/unity.c +++ b/src/unity.c @@ -578,7 +578,7 @@ void UnityAssertFloatsWithin(const _UF delta, pos_delta = 0.0f - pos_delta; } - // NOTE: This comparrison is deliberately this way round so that NaNs fail. + // NOTE: This comparison is deliberately this way round so that NaNs fail. if ( ! (pos_delta >= diff) ) { UnityTestResultsFailBegin(lineNumber); From ae18c560bdf5ad75ce0839b7fc3181c5c5ecb2e7 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 15:22:28 +0000 Subject: [PATCH 03/20] Added more tests for TEST_ASSERT_EQUAL_FLOAT with NaNs. --- test/testunity.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/testunity.c b/test/testunity.c index ddd80c5..2437f3f 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2237,6 +2237,50 @@ void testFloatsNotEqualActualNaN(void) #endif } +void testFloatsNotEqualExpectedNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 85.963f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualBothNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualInfNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualNaNInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualFloatArrays(void) { #ifdef UNITY_EXCLUDE_FLOAT From 899f2f2fabb0e3f1a18c9223ab1fdc8d02986220 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 15:24:10 +0000 Subject: [PATCH 04/20] UnityAssertFloatsWithin now fails any test where either a NaN or Infinite value is passed as expected or actual. --- src/unity.c | 4 ++-- test/testunity.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/unity.c b/src/unity.c index 8188345..1a5acc9 100644 --- a/src/unity.c +++ b/src/unity.c @@ -578,8 +578,8 @@ void UnityAssertFloatsWithin(const _UF delta, pos_delta = 0.0f - pos_delta; } - // NOTE: This comparison is deliberately this way round so that NaNs fail. - if ( ! (pos_delta >= diff) ) + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE diff --git a/test/testunity.c b/test/testunity.c index 2437f3f..5daf2ae 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2281,6 +2281,50 @@ void testFloatsNotEqualNaNInf(void) #endif } +void testFloatsNotEqualActualInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(321.642f, 1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualExpectedInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 321.642f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualBothInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatsNotEqualPlusMinusInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, -1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualFloatArrays(void) { #ifdef UNITY_EXCLUDE_FLOAT From b14819bc79d4081a49aea2f59eb2659480ba1d55 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 16:12:50 +0000 Subject: [PATCH 05/20] Expanded NaN and Infinity handling to doubles. --- src/unity.c | 3 +- test/testunity.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 1a5acc9..739243b 100644 --- a/src/unity.c +++ b/src/unity.c @@ -673,7 +673,8 @@ void UnityAssertDoublesWithin(const _UD delta, pos_delta = 0.0f - pos_delta; } - if (pos_delta < diff) + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE diff --git a/test/testunity.c b/test/testunity.c index 5daf2ae..1e3e688 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2526,6 +2526,105 @@ void testDoublesNotEqualNegative2(void) #endif } +void testDoublesNotEqualActualNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(85.963f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualExpectedNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 85.963f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualBothNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualInfNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualNaNInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualActualInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(321.642f, 1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualExpectedInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 321.642f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualBothInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoublesNotEqualPlusMinusInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, -1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualDoubleArrays(void) { #ifdef UNITY_EXCLUDE_DOUBLE From b9b18bf547c248b63c8c59836e7dceeaf4868b39 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Tue, 30 Oct 2012 17:08:43 +0000 Subject: [PATCH 06/20] Added new asserts to check for plus/minus infinity and NaN. --- src/unity.c | 141 ++++++++++++++++++++++++++++++++++++++++ src/unity.h | 7 +- src/unity_internals.h | 36 ++++++++++ test/testunity.c | 148 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 331 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 739243b..317609c 100644 --- a/src/unity.c +++ b/src/unity.c @@ -28,6 +28,9 @@ const char* UnityStrDelta = " Values Not Within Delta "; const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless."; const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL"; const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; +const char* UnityStrInf = "Infinity"; +const char* UnityStrNegInf = "Negative Infinity"; +const char* UnityStrNaN = "NaN"; // compiler-generic print formatting masks const _U_UINT UnitySizeMask[] = @@ -595,6 +598,75 @@ void UnityAssertFloatsWithin(const _UF delta, } } +//----------------------------------------------- +void UnityAssertFloatIsInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if ((1.0f / 0.0f) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_FLOAT_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrInf); + UnityPrint(UnityStrWas); + UnityPrintFloat(actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertFloatIsNegInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if ((-1.0f / 0.0f) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_FLOAT_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNegInf); + UnityPrint(UnityStrWas); + UnityPrintFloat(actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertFloatIsNaN(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if (actual == actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_FLOAT_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNaN); + UnityPrint(UnityStrWas); + UnityPrintFloat(actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + #endif //not UNITY_EXCLUDE_FLOAT //----------------------------------------------- @@ -690,6 +762,75 @@ void UnityAssertDoublesWithin(const _UD delta, } } +//----------------------------------------------- +void UnityAssertDoubleIsInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if ((1.0 / 0.0) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_DOUBLE_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrInf); + UnityPrint(UnityStrWas); + UnityPrintFloat((float)actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertDoubleIsNegInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if ((-1.0 / 0.0) != actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_DOUBLE_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNegInf); + UnityPrint(UnityStrWas); + UnityPrintFloat((float)actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + +//----------------------------------------------- +void UnityAssertDoubleIsNaN(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber) +{ + UNITY_SKIP_EXECUTION; + + if (actual == actual) + { + UnityTestResultsFailBegin(lineNumber); +#ifdef UNITY_DOUBLE_VERBOSE + UnityPrint(UnityStrExpected); + UnityPrint(UnityStrNaN); + UnityPrint(UnityStrWas); + UnityPrintFloat((float)actual); +#else + UnityPrint(UnityStrDelta); +#endif + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; + } +} + #endif // not UNITY_EXCLUDE_DOUBLE //----------------------------------------------- diff --git a/src/unity.h b/src/unity.h index 6c635bd..915329e 100644 --- a/src/unity.h +++ b/src/unity.h @@ -142,12 +142,17 @@ #define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL) +#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL) //Double (If Enabled) #define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, NULL) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, NULL) - +#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL) +#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL) //------------------------------------------------------- // Test Asserts (with additional messages) diff --git a/src/unity_internals.h b/src/unity_internals.h index 253c5b9..2e7c8f9 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -410,6 +410,18 @@ void UnityAssertEqualFloatArray(const _UF* expected, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); + +void UnityAssertFloatIsInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertFloatIsNegInf(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertFloatIsNaN(const _UF actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); #endif #ifndef UNITY_EXCLUDE_DOUBLE @@ -424,6 +436,18 @@ void UnityAssertEqualDoubleArray(const _UD* expected, const _UU32 num_elements, const char* msg, const UNITY_LINE_TYPE lineNumber); + +void UnityAssertDoubleIsInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertDoubleIsNegInf(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertDoubleIsNaN(const _UD actual, + const char* msg, + const UNITY_LINE_TYPE lineNumber); #endif //------------------------------------------------------- @@ -493,20 +517,32 @@ void UnityAssertEqualDoubleArray(const _UD* expected, #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") +#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") +#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") +#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") #else #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #endif #ifdef UNITY_EXCLUDE_DOUBLE #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") +#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") +#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") +#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") #else #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message) #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) +#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) #endif #endif diff --git a/test/testunity.c b/test/testunity.c index 1e3e688..dedd9ef 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2325,6 +2325,80 @@ void testFloatsNotEqualPlusMinusInf(void) #endif } +void testFloatIsInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + TEST_ASSERT_FLOAT_IS_INF(2.0f / 0.0f); + TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / 0.0f); +#endif +} + +void testFloatIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_INF(2.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatIsNotNegInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_NEG_INF(-999.876f); + VERIFY_FAILS_END +#endif +} + +void testFloatIsNan(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + TEST_ASSERT_FLOAT_IS_NAN(0.0f / 0.0f); +#endif +} + +void testFloatIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_NAN(234.9f); + VERIFY_FAILS_END +#endif +} + +void testFloatInfIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_NAN(1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testFloatNanIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_FLOAT_IS_INF(0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualFloatArrays(void) { #ifdef UNITY_EXCLUDE_FLOAT @@ -2625,6 +2699,80 @@ void testDoublesNotEqualPlusMinusInf(void) #endif } +void testDoubleIsInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + TEST_ASSERT_DOUBLE_IS_INF(2.0f / 0.0f); + TEST_ASSERT_DOUBLE_IS_NEG_INF(-3.0f / 0.0f); +#endif +} + +void testDoubleIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_INF(2.0f); + VERIFY_FAILS_END +#endif +} + +void testDoubleIsNotNegInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_NEG_INF(-999.876f); + VERIFY_FAILS_END +#endif +} + +void testDoubleIsNan(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + TEST_ASSERT_DOUBLE_IS_NAN(0.0f / 0.0f); +#endif +} + +void testDoubleIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_NAN(234.9f); + VERIFY_FAILS_END +#endif +} + +void testDoubleInfIsNotNan(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_NAN(1.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + +void testDoubleNanIsNotInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + EXPECT_ABORT_BEGIN + TEST_ASSERT_DOUBLE_IS_INF(0.0f / 0.0f); + VERIFY_FAILS_END +#endif +} + void testEqualDoubleArrays(void) { #ifdef UNITY_EXCLUDE_DOUBLE From 5853e24e1a38f47648e2e43bbc37c93009a0b0c9 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Wed, 31 Oct 2012 08:17:10 +0000 Subject: [PATCH 07/20] Added _MESSAGE versions of asserts for floating point specials. --- src/unity.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/unity.h b/src/unity.h index 915329e..a046f71 100644 --- a/src/unity.h +++ b/src/unity.h @@ -228,10 +228,15 @@ #define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message) +#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message) +#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message) +#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message) //Double (If Enabled) #define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, __LINE__, message) #define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, __LINE__, message) - +#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message) +#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message) +#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message) #endif From 2ab2fef60a2ad8fbc21b2d7c1415ea6a5f9974b4 Mon Sep 17 00:00:00 2001 From: Ross Ryles Date: Wed, 31 Oct 2012 12:34:30 +0000 Subject: [PATCH 08/20] Array comparisons of floating point types fail if any values are NaN or infinite. --- src/unity.c | 8 +++++-- test/testunity.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/unity.c b/src/unity.c index 317609c..8273b46 100644 --- a/src/unity.c +++ b/src/unity.c @@ -539,7 +539,9 @@ void UnityAssertEqualFloatArray(const _UF* expected, tol = UNITY_FLOAT_PRECISION * *ptr_expected; if (tol < 0.0) tol = 0.0 - tol; - if (diff > tol) + + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0f != 0.0f) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -703,7 +705,9 @@ void UnityAssertEqualDoubleArray(const _UD* expected, tol = UNITY_DOUBLE_PRECISION * *ptr_expected; if (tol < 0.0) tol = 0.0 - tol; - if (diff > tol) + + //This first part of this condition will catch any NaN or Infinite values + if ((diff * 0.0f != 0.0f) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); diff --git a/test/testunity.c b/test/testunity.c index dedd9ef..3345959 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -2529,6 +2529,34 @@ void testNotEqualFloatArraysNegative3(void) #endif } +void testNotEqualFloatArraysNaN(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + float p0[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; + float p1[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} + +void testNotEqualFloatArraysInf(void) +{ +#ifdef UNITY_EXCLUDE_FLOAT + TEST_IGNORE(); +#else + float p0[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; + float p1[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} + // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ================== void testDoublesWithinDelta(void) @@ -2903,3 +2931,30 @@ void testNotEqualDoubleArraysNegative3(void) #endif } +void testNotEqualDoubleArraysNaN(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + double p0[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; + double p1[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} + +void testNotEqualDoubleArraysInf(void) +{ +#ifdef UNITY_EXCLUDE_DOUBLE + TEST_IGNORE(); +#else + double p0[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; + double p1[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4); + VERIFY_FAILS_END +#endif +} \ No newline at end of file From 56de50cf7f32558ad42560850a57c02f0a1c70ca Mon Sep 17 00:00:00 2001 From: Vivek Ayer Date: Sun, 18 Nov 2012 18:08:08 -0800 Subject: [PATCH 09/20] root: fix makefile to run testunity.out testunity.out is being created in the root directory and was being called from the 'all' target incorrectly. This is now fixed. --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 58ead54..753bbae 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ all: clean default default: ruby auto/generate_test_runner.rb test/testunity.c build/testunity_Runner.c $(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) $(OUT_FILE) - $(TARGET) + ./$(TARGET) clean: $(CLEANUP) From c2737fc71c5698afe64677695ccf7abe2dda0dc5 Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Tue, 20 Nov 2012 14:45:04 -0600 Subject: [PATCH 10/20] Fix: For floats, make sure all constants are single-precision floating point values. For doubles, make sure all constants are double-precision. --- src/unity.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/unity.c b/src/unity.c index 8273b46..8dd6d39 100644 --- a/src/unity.c +++ b/src/unity.c @@ -534,11 +534,11 @@ void UnityAssertEqualFloatArray(const _UF* expected, while (elements--) { diff = *ptr_expected - *ptr_actual; - if (diff < 0.0) - diff = 0.0 - diff; + if (diff < 0.0f) + diff = 0.0f - diff; tol = UNITY_FLOAT_PRECISION * *ptr_expected; - if (tol < 0.0) - tol = 0.0 - tol; + if (tol < 0.0f) + tol = 0.0f - tol; //This first part of this condition will catch any NaN or Infinite values if ((diff * 0.0f != 0.0f) || (diff > tol)) @@ -574,11 +574,11 @@ void UnityAssertFloatsWithin(const _UF delta, UNITY_SKIP_EXECUTION; - if (diff < 0) + if (diff < 0.0f) { diff = 0.0f - diff; } - if (pos_delta < 0) + if (pos_delta < 0.0f) { pos_delta = 0.0f - pos_delta; } @@ -707,7 +707,7 @@ void UnityAssertEqualDoubleArray(const _UD* expected, tol = 0.0 - tol; //This first part of this condition will catch any NaN or Infinite values - if ((diff * 0.0f != 0.0f) || (diff > tol)) + if ((diff * 0.0 != 0.0) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -740,17 +740,17 @@ void UnityAssertDoublesWithin(const _UD delta, UNITY_SKIP_EXECUTION; - if (diff < 0) + if (diff < 0.0) { - diff = 0.0f - diff; + diff = 0.0 - diff; } - if (pos_delta < 0) + if (pos_delta < 0.0) { - pos_delta = 0.0f - pos_delta; + pos_delta = 0.0 - pos_delta; } //This first part of this condition will catch any NaN or Infinite values - if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) + if ((diff * 0.0 != 0.0) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE From 97000e01041909f744d5d5c3ff26f239a475ea3a Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Sun, 25 Nov 2012 15:52:27 -0500 Subject: [PATCH 11/20] - make test runner handle spaces and dashes in file names --- auto/generate_test_runner.rb | 9 ++++++--- examples/rakefile.rb | 2 +- extras/fixture/rakefile.rb | 2 +- extras/fixture/src/unity_fixture.c | 8 ++------ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index a3158cb..b7d37ac 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -176,21 +176,24 @@ class UnityTestRunnerGenerator output.puts(" GlobalOrderError = NULL;") end mocks.each do |mock| - output.puts(" #{mock}_Init();") + mock_clean = mock.gsub(/(?:-|\s+)/, "_") + output.puts(" #{mock_clean}_Init();") end output.puts("}\n") output.puts("static void CMock_Verify(void)") output.puts("{") mocks.each do |mock| - output.puts(" #{mock}_Verify();") + mock_clean = mock.gsub(/(?:-|\s+)/, "_") + output.puts(" #{mock_clean}_Verify();") end output.puts("}\n") output.puts("static void CMock_Destroy(void)") output.puts("{") mocks.each do |mock| - output.puts(" #{mock}_Destroy();") + mock_clean = mock.gsub(/(?:-|\s+)/, "_") + output.puts(" #{mock_clean}_Destroy();") end output.puts("}\n") end diff --git a/examples/rakefile.rb b/examples/rakefile.rb index 198fe91..0a64118 100644 --- a/examples/rakefile.rb +++ b/examples/rakefile.rb @@ -8,7 +8,7 @@ require HERE+'rakefile_helper' include RakefileHelpers # Load default configuration, for now -DEFAULT_CONFIG_FILE = 'gcc.yml' +DEFAULT_CONFIG_FILE = 'gcc_32.yml' configure_toolchain(DEFAULT_CONFIG_FILE) task :unit do diff --git a/extras/fixture/rakefile.rb b/extras/fixture/rakefile.rb index fbff3bd..5d81e72 100644 --- a/extras/fixture/rakefile.rb +++ b/extras/fixture/rakefile.rb @@ -14,7 +14,7 @@ require HERE + 'rakefile_helper' include RakefileHelpers # Load default configuration, for now -DEFAULT_CONFIG_FILE = 'gcc.yml' +DEFAULT_CONFIG_FILE = 'gcc_32.yml' configure_toolchain(DEFAULT_CONFIG_FILE) task :unit do diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index ec0b4c5..fa2a298 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -107,12 +107,8 @@ void UnityTestRunner(unityfunction* setup, UnityPointer_UndoAllSets(); if (!Unity.CurrentTestFailed) UnityMalloc_EndTest(); - UnityConcludeFixtureTest(); - } - else - { - //aborting - jwg - di i need these for the other TEST_PROTECTS? } + UnityConcludeFixtureTest(); } } @@ -254,7 +250,7 @@ void* unity_realloc(void * oldMem, size_t size) return oldMem; newMem = unity_malloc(size); - memcpy(newMem, oldMem, size); + memcpy(newMem, oldMem, guard->size); unity_free(oldMem); return newMem; } From f73c5fa6069982e917e5632299bb5a815b002de3 Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Mon, 26 Nov 2012 11:29:47 -0600 Subject: [PATCH 12/20] Fix: - Modify tests to compile under MSVC++ EE 2008 - Change type of floating-point constants to single/double precision as appropriate. --- src/unity.c | 23 +++++++-- test/testunity.c | 121 +++++++++++++++++++++++++---------------------- 2 files changed, 83 insertions(+), 61 deletions(-) diff --git a/src/unity.c b/src/unity.c index 8dd6d39..bd9aa14 100644 --- a/src/unity.c +++ b/src/unity.c @@ -32,6 +32,13 @@ const char* UnityStrInf = "Infinity"; const char* UnityStrNegInf = "Negative Infinity"; const char* UnityStrNaN = "NaN"; +// Dividing by these constants produces +/- infinity. +// The rationale is given in UnityAssertFloatIsInf's body. +static const _UF f_zero = 0.0f; +#ifndef UNITY_EXCLUDE_DOUBLE +static const _UD d_zero = 0.0; +#endif + // compiler-generic print formatting masks const _U_UINT UnitySizeMask[] = { @@ -607,7 +614,12 @@ void UnityAssertFloatIsInf(const _UF actual, { UNITY_SKIP_EXECUTION; - if ((1.0f / 0.0f) != actual) + // In Microsoft Visual C++ Express Edition 2008, + // if ((1.0f / f_zero) != actual) + // produces + // error C2124: divide or mod by zero + // As a workaround, place 0 into a variable. + if ((1.0f / f_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE @@ -630,7 +642,8 @@ void UnityAssertFloatIsNegInf(const _UF actual, { UNITY_SKIP_EXECUTION; - if ((-1.0f / 0.0f) != actual) + // The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body. + if ((-1.0f / f_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE @@ -773,7 +786,8 @@ void UnityAssertDoubleIsInf(const _UD actual, { UNITY_SKIP_EXECUTION; - if ((1.0 / 0.0) != actual) + // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body. + if ((1.0 / d_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE @@ -796,7 +810,8 @@ void UnityAssertDoubleIsNegInf(const _UD actual, { UNITY_SKIP_EXECUTION; - if ((-1.0 / 0.0) != actual) + // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body. + if ((-1.0 / d_zero) != actual) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE diff --git a/test/testunity.c b/test/testunity.c index 3345959..2a10894 100755 --- a/test/testunity.c +++ b/test/testunity.c @@ -7,6 +7,13 @@ #include #include "unity.h" +// Dividing by these constants produces +/- infinity. +// The rationale is given in UnityAssertFloatIsInf's body. +static const _UF f_zero = 0.0f; +#ifndef UNITY_EXCLUDE_DOUBLE +static const _UD d_zero = 0.0; +#endif + #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ { @@ -2232,7 +2239,7 @@ void testFloatsNotEqualActualNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(85.963f, 0.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(85.963f, 0.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2243,7 +2250,7 @@ void testFloatsNotEqualExpectedNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 85.963f); + TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 85.963f); VERIFY_FAILS_END #endif } @@ -2254,7 +2261,7 @@ void testFloatsNotEqualBothNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 0.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 0.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2265,7 +2272,7 @@ void testFloatsNotEqualInfNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 0.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 0.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2276,7 +2283,7 @@ void testFloatsNotEqualNaNInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(0.0f / 0.0f, 1.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(0.0f / f_zero, 1.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2287,7 +2294,7 @@ void testFloatsNotEqualActualInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(321.642f, 1.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(321.642f, 1.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2298,7 +2305,7 @@ void testFloatsNotEqualExpectedInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 321.642f); + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 321.642f); VERIFY_FAILS_END #endif } @@ -2309,7 +2316,7 @@ void testFloatsNotEqualBothInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, 1.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, 1.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2320,7 +2327,7 @@ void testFloatsNotEqualPlusMinusInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_FLOAT(1.0f / 0.0f, -1.0f / 0.0f); + TEST_ASSERT_EQUAL_FLOAT(1.0f / f_zero, -1.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2330,8 +2337,8 @@ void testFloatIsInf(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - TEST_ASSERT_FLOAT_IS_INF(2.0f / 0.0f); - TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / 0.0f); + TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero); + TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero); #endif } @@ -2362,7 +2369,7 @@ void testFloatIsNan(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - TEST_ASSERT_FLOAT_IS_NAN(0.0f / 0.0f); + TEST_ASSERT_FLOAT_IS_NAN(0.0f / f_zero); #endif } @@ -2383,7 +2390,7 @@ void testFloatInfIsNotNan(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_FLOAT_IS_NAN(1.0f / 0.0f); + TEST_ASSERT_FLOAT_IS_NAN(1.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2394,7 +2401,7 @@ void testFloatNanIsNotInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_FLOAT_IS_INF(0.0f / 0.0f); + TEST_ASSERT_FLOAT_IS_INF(0.0f / f_zero); VERIFY_FAILS_END #endif } @@ -2404,10 +2411,10 @@ void testEqualFloatArrays(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, -8.0, 25.4, -0.123}; - float p1[] = {1.0, -8.0, 25.4, -0.123}; - float p2[] = {1.0, -8.0, 25.4, -0.2}; - float p3[] = {1.0, -23.0, 25.0, -0.26}; + float p0[] = {1.0f, -8.0f, 25.4f, -0.123f}; + float p1[] = {1.0f, -8.0f, 25.4f, -0.123f}; + float p2[] = {1.0f, -8.0f, 25.4f, -0.2f}; + float p3[] = {1.0f, -23.0f, 25.0f, -0.26f}; TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p0, 1); TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p0, 4); @@ -2423,7 +2430,7 @@ void testNotEqualFloatArraysExpectedNull(void) TEST_IGNORE(); #else float* p0 = NULL; - float p1[] = {1.0, 8.0, 25.4, 0.252}; + float p1[] = {1.0f, 8.0f, 25.4f, 0.252f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2436,7 +2443,7 @@ void testNotEqualFloatArraysActualNull(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; float* p1 = NULL; EXPECT_ABORT_BEGIN @@ -2450,8 +2457,8 @@ void testNotEqualFloatArrays1(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; - float p1[] = {1.0, 8.0, 25.4, 0.252}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; + float p1[] = {1.0f, 8.0f, 25.4f, 0.252f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2464,8 +2471,8 @@ void testNotEqualFloatArrays2(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; - float p1[] = {2.0, 8.0, 25.4, 0.253}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; + float p1[] = {2.0f, 8.0f, 25.4f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2478,8 +2485,8 @@ void testNotEqualFloatArrays3(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 8.0, 25.4, 0.253}; - float p1[] = {1.0, 8.0, 25.5, 0.253}; + float p0[] = {1.0f, 8.0f, 25.4f, 0.253f}; + float p1[] = {1.0f, 8.0f, 25.5f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2492,8 +2499,8 @@ void testNotEqualFloatArraysNegative1(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {-1.0, -8.0, -25.4, -0.253}; - float p1[] = {-1.0, -8.0, -25.4, -0.252}; + float p0[] = {-1.0f, -8.0f, -25.4f, -0.253f}; + float p1[] = {-1.0f, -8.0f, -25.4f, -0.252f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2506,8 +2513,8 @@ void testNotEqualFloatArraysNegative2(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {-1.0, -8.0, -25.4, -0.253}; - float p1[] = {-2.0, -8.0, -25.4, -0.253}; + float p0[] = {-1.0f, -8.0f, -25.4f, -0.253f}; + float p1[] = {-2.0f, -8.0f, -25.4f, -0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2520,8 +2527,8 @@ void testNotEqualFloatArraysNegative3(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {-1.0, -8.0, -25.4, -0.253}; - float p1[] = {-1.0, -8.0, -25.5, -0.253}; + float p0[] = {-1.0f, -8.0f, -25.4f, -0.253f}; + float p1[] = {-1.0f, -8.0f, -25.5f, -0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2534,8 +2541,8 @@ void testNotEqualFloatArraysNaN(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; - float p1[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; + float p0[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f}; + float p1[] = {1.0f, 0.0f / f_zero, 25.4f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2548,8 +2555,8 @@ void testNotEqualFloatArraysInf(void) #ifdef UNITY_EXCLUDE_FLOAT TEST_IGNORE(); #else - float p0[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; - float p1[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; + float p0[] = {1.0f, 1.0f / f_zero, 25.4f, 0.253f}; + float p1[] = {1.0f, 1.0f / f_zero, 25.4f, 0.253f}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_FLOAT_ARRAY(p0, p1, 4); @@ -2634,7 +2641,7 @@ void testDoublesNotEqualActualNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(85.963f, 0.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(85.963, 0.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2645,7 +2652,7 @@ void testDoublesNotEqualExpectedNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 85.963f); + TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 85.963); VERIFY_FAILS_END #endif } @@ -2656,7 +2663,7 @@ void testDoublesNotEqualBothNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 0.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 0.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2667,7 +2674,7 @@ void testDoublesNotEqualInfNaN(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 0.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 0.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2678,7 +2685,7 @@ void testDoublesNotEqualNaNInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(0.0f / 0.0f, 1.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 1.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2689,7 +2696,7 @@ void testDoublesNotEqualActualInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(321.642f, 1.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(321.642, 1.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2700,7 +2707,7 @@ void testDoublesNotEqualExpectedInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 321.642f); + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 321.642); VERIFY_FAILS_END #endif } @@ -2711,7 +2718,7 @@ void testDoublesNotEqualBothInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, 1.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 1.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2722,7 +2729,7 @@ void testDoublesNotEqualPlusMinusInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_DOUBLE(1.0f / 0.0f, -1.0f / 0.0f); + TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, -1.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2732,8 +2739,8 @@ void testDoubleIsInf(void) #ifdef UNITY_EXCLUDE_DOUBLE TEST_IGNORE(); #else - TEST_ASSERT_DOUBLE_IS_INF(2.0f / 0.0f); - TEST_ASSERT_DOUBLE_IS_NEG_INF(-3.0f / 0.0f); + TEST_ASSERT_DOUBLE_IS_INF(2.0 / d_zero); + TEST_ASSERT_DOUBLE_IS_NEG_INF(-3.0 / d_zero); #endif } @@ -2743,7 +2750,7 @@ void testDoubleIsNotInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_DOUBLE_IS_INF(2.0f); + TEST_ASSERT_DOUBLE_IS_INF(2.0); VERIFY_FAILS_END #endif } @@ -2754,7 +2761,7 @@ void testDoubleIsNotNegInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_DOUBLE_IS_NEG_INF(-999.876f); + TEST_ASSERT_DOUBLE_IS_NEG_INF(-999.876); VERIFY_FAILS_END #endif } @@ -2764,7 +2771,7 @@ void testDoubleIsNan(void) #ifdef UNITY_EXCLUDE_DOUBLE TEST_IGNORE(); #else - TEST_ASSERT_DOUBLE_IS_NAN(0.0f / 0.0f); + TEST_ASSERT_DOUBLE_IS_NAN(0.0 / d_zero); #endif } @@ -2774,7 +2781,7 @@ void testDoubleIsNotNan(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_DOUBLE_IS_NAN(234.9f); + TEST_ASSERT_DOUBLE_IS_NAN(234.9); VERIFY_FAILS_END #endif } @@ -2785,7 +2792,7 @@ void testDoubleInfIsNotNan(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_DOUBLE_IS_NAN(1.0f / 0.0f); + TEST_ASSERT_DOUBLE_IS_NAN(1.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2796,7 +2803,7 @@ void testDoubleNanIsNotInf(void) TEST_IGNORE(); #else EXPECT_ABORT_BEGIN - TEST_ASSERT_DOUBLE_IS_INF(0.0f / 0.0f); + TEST_ASSERT_DOUBLE_IS_INF(0.0 / d_zero); VERIFY_FAILS_END #endif } @@ -2936,8 +2943,8 @@ void testNotEqualDoubleArraysNaN(void) #ifdef UNITY_EXCLUDE_DOUBLE TEST_IGNORE(); #else - double p0[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; - double p1[] = {1.0, 0.0 / 0.0, 25.4, 0.253}; + double p0[] = {1.0, 0.0 / d_zero, 25.4, 0.253}; + double p1[] = {1.0, 0.0 / d_zero, 25.4, 0.253}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4); @@ -2950,8 +2957,8 @@ void testNotEqualDoubleArraysInf(void) #ifdef UNITY_EXCLUDE_DOUBLE TEST_IGNORE(); #else - double p0[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; - double p1[] = {1.0, 1.0 / 0.0, 25.4, 0.253}; + double p0[] = {1.0, 1.0 / d_zero, 25.4, 0.253}; + double p1[] = {1.0, 1.0 / d_zero, 25.4, 0.253}; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4); From 5b1e9818e2e3d2ce40e3f3db1b04c33582b6ae08 Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Thu, 29 Nov 2012 15:34:09 -0600 Subject: [PATCH 13/20] Fix: Clean up UINTY_xxx_WIDTH detection. Document failing approach (sizeof). --- src/unity_internals.h | 44 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 2e7c8f9..7020756 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -10,11 +10,14 @@ #include #include -//stdint.h is often automatically included. -//Unity uses it to guess at the sizes of integer types, etc. +// Unity attempts to determine sizeof(various types) +// based on UINT_MAX, ULONG_MAX, etc. These are typically +// defined in limits.h. #ifdef UNITY_USE_LIMITS_H #include #endif +// As a fallback, hope that including stdint.h will +// provide this information. #ifndef UNITY_EXCLUDE_STDINT_H #include #endif @@ -23,9 +26,10 @@ // Guess Widths If Not Specified //------------------------------------------------------- -// If the INT Width hasn't been specified, -// We first try to guess based on UINT_MAX (if it exists) -// Otherwise we fall back on assuming 32-bit +// Determine the size of an int, if not already specificied. +// We cannot use sizeof(int), because it is not yet defined +// at this stage in the trnslation of the C program. +// Therefore, infer it from UINT_MAX if possible. #ifndef UNITY_INT_WIDTH #ifdef UINT_MAX #if (UINT_MAX == 0xFFFF) @@ -37,17 +41,16 @@ #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif - #else - #define UNITY_INT_WIDTH (32) #endif - #else - #define UNITY_INT_WIDTH (32) #endif #endif +#ifndef UNITY_INT_WIDTH + #define UNITY_INT_WIDTH (32) +#endif -// If the Long Width hasn't been specified, -// We first try to guess based on ULONG_MAX (if it exists) -// Otherwise we fall back on assuming 32-bit +// Determine the size of a long, if not already specified, +// by following the process used above to define +// UNITY_INT_WIDTH. #ifndef UNITY_LONG_WIDTH #ifdef ULONG_MAX #if (ULONG_MAX == 0xFFFF) @@ -56,20 +59,19 @@ #define UNITY_LONG_WIDTH (32) #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) #define UNITY_LONG_WIDTH (64) - #else - #define UNITY_LONG_WIDTH (32) #ifndef UNITY_SUPPORT_64 #define UNITY_SUPPORT_64 #endif #endif - #else - #define UNITY_LONG_WIDTH (32) #endif #endif +#ifndef UNITY_LONG_WIDTH + #define UNITY_LONG_WIDTH (32) +#endif -// If the Pointer Width hasn't been specified, -// We first try to guess based on INTPTR_MAX (if it exists) -// Otherwise we fall back on assuming 32-bit +// Determine the size of a pointer, if not already specified, +// by following the process used above to define +// UNITY_INT_WIDTH. #ifndef UNITY_POINTER_WIDTH #ifdef UINTPTR_MAX #if (UINTPTR_MAX <= 0xFFFF) @@ -155,10 +157,6 @@ typedef _US64 _U_SINT; // Pointer Support //------------------------------------------------------- -#ifndef UNITY_POINTER_WIDTH -#define UNITY_POINTER_WIDTH (32) -#endif /* UNITY_POINTER_WIDTH */ - #if (UNITY_POINTER_WIDTH == 32) typedef _UU32 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 From bc251726b61c0e2b87f7a687f4e11ce5e01c987c Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Mon, 3 Dec 2012 11:36:45 -0600 Subject: [PATCH 14/20] Add: Additional documentation for Unity configuration options. --- src/unity.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/unity.h b/src/unity.h index a046f71..f0c6abe 100644 --- a/src/unity.h +++ b/src/unity.h @@ -14,10 +14,13 @@ //------------------------------------------------------- // Configuration Options //------------------------------------------------------- +// All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above. -// Integers -// - Unity assumes 32 bit integers by default -// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH +// Integers/longs/pointers +// - Unity assumes 32 bit integers, longs, and pointers by default +// - If your compiler treats ints of a different size, options are: +// - define UNITY_USE_LIMITS_H to use limits.h to determine sizes +// - define UNITY_INT_WIDTH, UNITY_LONG_WIDTH, nand UNITY_POINTER_WIDTH // Floats // - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons From 9d8491276125ac53b8b9d4530bf70e8cc128ab07 Mon Sep 17 00:00:00 2001 From: Dennis Lambe Jr Date: Fri, 21 Dec 2012 15:07:09 -0500 Subject: [PATCH 15/20] Ensured unity_fixture tests pass --- extras/fixture/rakefile_helper.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extras/fixture/rakefile_helper.rb b/extras/fixture/rakefile_helper.rb index 01a5d66..09730ef 100644 --- a/extras/fixture/rakefile_helper.rb +++ b/extras/fixture/rakefile_helper.rb @@ -87,7 +87,7 @@ module RakefileHelpers return {:command => command, :options => options, :includes => includes} end - def link(exe_name, obj_list) + def link_it(exe_name, obj_list) linker = build_linker_fields cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + (obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join + @@ -148,7 +148,8 @@ module RakefileHelpers # Get a list of all source files needed src_files = Dir[HERE+'src/*.c'] src_files += Dir[HERE+'test/*.c'] - src_files << '../../src/Unity.c' + src_files += Dir[HERE+'test/main/*.c'] + src_files << '../../src/unity.c' # Build object files src_files.each { |f| compile(f, test_defines) } @@ -156,7 +157,7 @@ module RakefileHelpers # Link the test executable test_base = "framework_test" - link(test_base, obj_list) + link_it(test_base, obj_list) # Execute unit test and generate results file simulator = build_simulator_fields From 601459a5c222e62a78acb18969d077242258b544 Mon Sep 17 00:00:00 2001 From: Dennis Lambe Jr Date: Fri, 21 Dec 2012 15:32:29 -0500 Subject: [PATCH 16/20] Fixed compilation warning in unity_fixture.c with optimization on. More details here: http://forums.pragprog.com/forums/123/topics/10901 --- extras/fixture/src/unity_fixture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index fa2a298..4db2b0a 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -5,9 +5,9 @@ [Released under MIT License. Please refer to license.txt for details] ========================================== */ +#include #include "unity_fixture.h" #include "unity_internals.h" -#include UNITY_FIXTURE_T UnityFixture; From e21881c53f4ad463dd51a0cd02de32585e4cb3df Mon Sep 17 00:00:00 2001 From: Dennis Lambe Jr Date: Fri, 21 Dec 2012 16:00:11 -0500 Subject: [PATCH 17/20] Fixed a unity_fixture bug that prevented IGNORE_TEST from properly counting ignored tests. More details here: http://forums.pragprog.com/forums/123/topics/10126 --- extras/fixture/src/unity_fixture.c | 1 + 1 file changed, 1 insertion(+) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 4db2b0a..ec91e60 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -117,6 +117,7 @@ void UnityIgnoreTest() Unity.NumberOfTests++; Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('!'); + UnityConcludeFixtureTest(); } From 47bf32edd6785926168b4d17c582d8a0c03d1408 Mon Sep 17 00:00:00 2001 From: Dennis Lambe Jr Date: Fri, 21 Dec 2012 16:07:49 -0500 Subject: [PATCH 18/20] Made unity_fixture IGNORE_TEST() respect the -v verbose flag. More details here: http://forums.pragprog.com/forums/123/topics/10126 --- extras/fixture/src/unity_fixture.c | 12 +++++++++--- extras/fixture/src/unity_fixture.h | 2 +- extras/fixture/src/unity_fixture_internals.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index ec91e60..1e0aa37 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -112,11 +112,14 @@ void UnityTestRunner(unityfunction* setup, } } -void UnityIgnoreTest() +void UnityIgnoreTest(const char * printableName) { Unity.NumberOfTests++; Unity.CurrentTestIgnored = 1; - UNITY_OUTPUT_CHAR('!'); + if (!UnityFixture.Verbose) + UNITY_OUTPUT_CHAR('!'); + else + UnityPrint(printableName); UnityConcludeFixtureTest(); } @@ -357,6 +360,10 @@ void UnityConcludeFixtureTest() { if (Unity.CurrentTestIgnored) { + if (UnityFixture.Verbose) + { + UNITY_OUTPUT_CHAR('\n'); + } Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) @@ -375,4 +382,3 @@ void UnityConcludeFixtureTest() Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; } - diff --git a/extras/fixture/src/unity_fixture.h b/extras/fixture/src/unity_fixture.h index da1f871..43c9f7c 100644 --- a/extras/fixture/src/unity_fixture.h +++ b/extras/fixture/src/unity_fixture.h @@ -41,7 +41,7 @@ int UnityMain(int argc, char* argv[], void (*runAllTests)()); void TEST_##group##_##name##_();\ void TEST_##group##_##name##_run()\ {\ - UnityIgnoreTest();\ + UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")");\ }\ void TEST_##group##_##name##_() diff --git a/extras/fixture/src/unity_fixture_internals.h b/extras/fixture/src/unity_fixture_internals.h index db23f67..46cbbcb 100644 --- a/extras/fixture/src/unity_fixture_internals.h +++ b/extras/fixture/src/unity_fixture_internals.h @@ -25,7 +25,7 @@ void UnityTestRunner(unityfunction * setup, const char * name, const char * file, int line); -void UnityIgnoreTest(); +void UnityIgnoreTest(const char * printableName); void UnityMalloc_StartTest(); void UnityMalloc_EndTest(); int UnityFailureCount(); From 146dfa3b2d98742a944c9d3f89233fd4bc0eedb9 Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Wed, 9 Jan 2013 09:54:29 -0600 Subject: [PATCH 19/20] Fix: Corrected type of size in GuardBytes to be size_t, not int. --- extras/fixture/src/unity_fixture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 1e0aa37..5dc099c 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -164,8 +164,8 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown) typedef struct GuardBytes { - int size; - char guard[sizeof(int)]; + size_t size; + char guard[sizeof(size_t)]; } Guard; From 4817d78de3443b5108642adbb273cdec21d94954 Mon Sep 17 00:00:00 2001 From: "Bryan A. Jones" Date: Fri, 11 Jan 2013 12:56:15 -0600 Subject: [PATCH 20/20] Fix: Declare all variables before statements in a function. Likewise, place all function prototypes before statements. These changes support Microsoft Visual Studio 2008 Express Edition, which follows C89-style rules. --- extras/fixture/src/unity_fixture.h | 8 ++++---- extras/fixture/test/unity_fixture_Test.c | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/extras/fixture/src/unity_fixture.h b/extras/fixture/src/unity_fixture.h index 43c9f7c..9d5cd12 100644 --- a/extras/fixture/src/unity_fixture.h +++ b/extras/fixture/src/unity_fixture.h @@ -49,8 +49,8 @@ int UnityMain(int argc, char* argv[], void (*runAllTests)()); void TEST_##group##_##name##_run() #define RUN_TEST_CASE(group, name) \ - DECLARE_TEST_CASE(group, name);\ - TEST_##group##_##name##_run(); + { DECLARE_TEST_CASE(group, name);\ + TEST_##group##_##name##_run(); } //This goes at the bottom of each test file or in a separate c file #define TEST_GROUP_RUNNER(group)\ @@ -63,8 +63,8 @@ int UnityMain(int argc, char* argv[], void (*runAllTests)()); //Call this from main #define RUN_TEST_GROUP(group)\ - void TEST_##group##_GROUP_RUNNER();\ - TEST_##group##_GROUP_RUNNER(); + { void TEST_##group##_GROUP_RUNNER();\ + TEST_##group##_GROUP_RUNNER(); } //CppUTest Compatibility Macros #define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue) diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index b8b4524..f5803b8 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -49,10 +49,12 @@ TEST(UnityFixture, PointerSetting) TEST(UnityFixture, ForceMallocFail) { + void* m; + void* mfails; UnityMalloc_MakeMallocFailAfterCount(1); - void* m = malloc(10); + m = malloc(10); CHECK(m); - void* mfails = malloc(10); + mfails = malloc(10); TEST_ASSERT_POINTERS_EQUAL(0, mfails); free(m); } @@ -76,8 +78,9 @@ TEST(UnityFixture, ReallocSameIsUnchanged) TEST(UnityFixture, ReallocLargerNeeded) { void* m1 = malloc(10); + void* m2; strcpy((char*)m1, "123456789"); - void* m2 = realloc(m1, 15); + m2 = realloc(m1, 15); CHECK(m1 != m2); STRCMP_EQUAL("123456789", m2); free(m2);