1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-24 17:01:35 +01:00

- rework to not bother with any of the ever-changing test frameworks in Ruby (sigh) for self-testing

- started working on cleaner floating point support. more coming.
This commit is contained in:
Mark VanderVoord
2014-07-21 14:00:53 -04:00
parent 39cc60ce56
commit 96155881ed
7 changed files with 248 additions and 132 deletions

View File

@@ -28,6 +28,7 @@ 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* UnityStrNot = "Not ";
const char* UnityStrInf = "Infinity";
const char* UnityStrNegInf = "Negative Infinity";
const char* UnityStrNaN = "NaN";
@@ -614,6 +615,7 @@ void UnityAssertFloatsWithin(const _UF delta,
//-----------------------------------------------
void UnityAssertFloatIsInf(const _UF actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
@@ -624,16 +626,21 @@ void UnityAssertFloatIsInf(const _UF actual,
// produces
// error C2124: divide or mod by zero
// As a workaround, place 0 into a variable.
if ((1.0f / f_zero) != actual)
_U_SINT is_inf = ((1.0f / f_zero) == actual) ? 1 : 0;
if (is_inf != should_be)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
if (!should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrInf);
UnityPrint(UnityStrWas);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
if (should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrInf);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
@@ -642,22 +649,28 @@ void UnityAssertFloatIsInf(const _UF actual,
//-----------------------------------------------
void UnityAssertFloatIsNegInf(const _UF actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
// The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body.
if ((-1.0f / f_zero) != actual)
_U_SINT is_inf = ((-1.0f / f_zero) == actual) ? 1 : 0;
if (is_inf != should_be)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
if (!should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNegInf);
UnityPrint(UnityStrWas);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
if (should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNegInf);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
@@ -666,21 +679,30 @@ void UnityAssertFloatIsNegInf(const _UF actual,
//-----------------------------------------------
void UnityAssertFloatIsNaN(const _UF actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
UNITY_SKIP_EXECUTION;
if (actual == actual)
//NaN is the only floating point value that does NOT
//equal itself. Therefore if Actual == Actual, then it
//is NOT NaN.
_U_SINT is_nan = (actual == actual) ? 0 : 1;
if (is_nan != should_be)
{
UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrint(UnityStrExpected);
if (!should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNaN);
UnityPrint(UnityStrWas);
#ifdef UNITY_FLOAT_VERBOSE
UnityPrintFloat(actual);
#else
UnityPrint(UnityStrDelta);
if (should_be)
UnityPrint(UnityStrNot);
UnityPrint(UnityStrNaN);
#endif
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
@@ -786,6 +808,7 @@ void UnityAssertDoublesWithin(const _UD delta,
//-----------------------------------------------
void UnityAssertDoubleIsInf(const _UD actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
@@ -810,6 +833,7 @@ void UnityAssertDoubleIsInf(const _UD actual,
//-----------------------------------------------
void UnityAssertDoubleIsNegInf(const _UD actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
@@ -834,6 +858,7 @@ void UnityAssertDoubleIsNegInf(const _UD actual,
//-----------------------------------------------
void UnityAssertDoubleIsNaN(const _UD actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
{
@@ -1093,8 +1118,8 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
//-----------------------------------------------
#ifdef UNITY_SUPPORT_WEAK
void setUp(void) { }
void tearDown(void) { }
UNITY_WEAK void setUp(void) { }
UNITY_WEAK void tearDown(void) { }
#else
void setUp(void);
void tearDown(void);

View File

@@ -174,6 +174,9 @@
#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)
#define TEST_ASSERT_FLOAT_IS_NOT_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_FLOAT_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_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)
@@ -182,6 +185,9 @@
#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)
#define TEST_ASSERT_DOUBLE_IS_NOT_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, __LINE__, NULL)
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, __LINE__, NULL)
//-------------------------------------------------------
// Test Asserts (with additional messages)
@@ -260,6 +266,9 @@
#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)
#define TEST_ASSERT_FLOAT_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_FLOAT_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_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)
@@ -268,4 +277,7 @@
#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)
#define TEST_ASSERT_DOUBLE_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, __LINE__, message)
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, __LINE__, message)
#endif

View File

@@ -274,7 +274,7 @@ extern int UNITY_OUTPUT_CHAR(int);
#ifndef UNITY_WEAK
#ifdef UNITY_SUPPORT_WEAK
#define UNITY_WEAK __attribute__((weak))
#define UNITY_WEAK UNITY_SUPPORT_WEAK
#else
#define UNITY_WEAK
#endif
@@ -438,14 +438,17 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsInf(const _UF actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsNegInf(const _UF actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertFloatIsNaN(const _UF actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
@@ -464,14 +467,17 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsInf(const _UD actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsNegInf(const _UD actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertDoubleIsNaN(const _UD actual,
const _U_SINT should_be,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#endif
@@ -550,9 +556,12 @@ void UnityAssertDoubleIsNaN(const _UD actual,
#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)
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#endif
#ifdef UNITY_EXCLUDE_DOUBLE
@@ -566,9 +575,12 @@ void UnityAssertDoubleIsNaN(const _UD actual,
#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((_UD)(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) UnityAssertDoubleIsInf((_UD)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
#endif
#endif