vendor/unity/src/unity.c in ceedling-0.28.2 vs vendor/unity/src/unity.c in ceedling-0.28.3
- old
+ new
@@ -2,35 +2,44 @@
Unity Project - A Test Framework for C
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
============================================================================ */
+#define UNITY_INCLUDE_SETUP_STUBS
#include "unity.h"
#include <stddef.h>
/* If omitted from header, declare overrideable prototypes here so they're ready for use */
#ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
void UNITY_OUTPUT_CHAR(int);
#endif
/* Helpful macros for us to use here in Assert functions */
-#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; TEST_ABORT(); }
-#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; TEST_ABORT(); }
+#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); }
+#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); }
#define RETURN_IF_FAIL_OR_IGNORE if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) return
struct UNITY_STORAGE_T Unity;
+#ifdef UNITY_OUTPUT_COLOR
+static const char UnityStrOk[] = "\033[42mOK\033[00m";
+static const char UnityStrPass[] = "\033[42mPASS\033[00m";
+static const char UnityStrFail[] = "\033[41mFAIL\033[00m";
+static const char UnityStrIgnore[] = "\033[43mIGNORE\033[00m";
+#else
static const char UnityStrOk[] = "OK";
static const char UnityStrPass[] = "PASS";
static const char UnityStrFail[] = "FAIL";
static const char UnityStrIgnore[] = "IGNORE";
+#endif
static const char UnityStrNull[] = "NULL";
static const char UnityStrSpacer[] = ". ";
static const char UnityStrExpected[] = " Expected ";
static const char UnityStrWas[] = " Was ";
static const char UnityStrGt[] = " to be greater than ";
static const char UnityStrLt[] = " to be less than ";
+static const char UnityStrOrEqual[] = "or equal to ";
static const char UnityStrElement[] = " Element ";
static const char UnityStrByte[] = " Byte ";
static const char UnityStrMemory[] = " Memory Mismatch.";
static const char UnityStrDelta[] = " Values Not Within Delta ";
static const char UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless.";
@@ -81,10 +90,22 @@
else if (*pch == 10)
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('n');
}
+#ifdef UNITY_OUTPUT_COLOR
+ /* print ANSI escape code */
+ else if (*pch == 27 && *(pch + 1) == '[')
+ {
+ while (*pch && *pch != 'm')
+ {
+ UNITY_OUTPUT_CHAR(*pch);
+ pch++;
+ }
+ UNITY_OUTPUT_CHAR('m');
+ }
+#endif
/* unprintable characters are shown as codes */
else
{
UNITY_OUTPUT_CHAR('\\');
UNITY_OUTPUT_CHAR('x');
@@ -368,10 +389,11 @@
Unity.TestFailures++;
}
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
+ UNITY_EXEC_TIME_RESET();
UNITY_PRINT_EOL();
UNITY_FLUSH_CALL();
}
/*-----------------------------------------------*/
@@ -529,53 +551,48 @@
UNITY_FAIL_AND_BAIL;
}
}
/*-----------------------------------------------*/
-void UnityAssertGreaterNumber(const UNITY_INT threshold,
- const UNITY_INT actual,
- const char *msg,
- const UNITY_LINE_TYPE lineNumber,
- const UNITY_DISPLAY_STYLE_T style)
+void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold,
+ const UNITY_INT actual,
+ const UNITY_COMPARISON_T compare,
+ const char *msg,
+ const UNITY_LINE_TYPE lineNumber,
+ const UNITY_DISPLAY_STYLE_T style)
{
+ int failed = 0;
RETURN_IF_FAIL_OR_IGNORE;
- if (!(actual > threshold))
+ if (threshold == actual && compare & UNITY_EQUAL_TO) return;
+ if (threshold == actual) failed = 1;
+
+ if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
- UnityTestResultsFailBegin(lineNumber);
- UnityPrint(UnityStrExpected);
- UnityPrintNumberByStyle(actual, style);
- UnityPrint(UnityStrGt);
- UnityPrintNumberByStyle(threshold, style);
- UnityAddMsgIfSpecified(msg);
- UNITY_FAIL_AND_BAIL;
+ if (actual > threshold && compare & UNITY_SMALLER_THAN) failed = 1;
+ if (actual < threshold && compare & UNITY_GREATER_THAN) failed = 1;
}
-}
+ else /* UINT or HEX */
+ {
+ if ((UNITY_UINT)actual > (UNITY_UINT)threshold && compare & UNITY_SMALLER_THAN) failed = 1;
+ if ((UNITY_UINT)actual < (UNITY_UINT)threshold && compare & UNITY_GREATER_THAN) failed = 1;
+ }
-/*-----------------------------------------------*/
-void UnityAssertSmallerNumber(const UNITY_INT threshold,
- const UNITY_INT actual,
- const char *msg,
- const UNITY_LINE_TYPE lineNumber,
- const UNITY_DISPLAY_STYLE_T style)
-{
- RETURN_IF_FAIL_OR_IGNORE;
-
- if (!(actual < threshold))
+ if (failed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(actual, style);
- UnityPrint(UnityStrLt);
+ if (compare & UNITY_GREATER_THAN) UnityPrint(UnityStrGt);
+ if (compare & UNITY_SMALLER_THAN) UnityPrint(UnityStrLt);
+ if (compare & UNITY_EQUAL_TO) UnityPrint(UnityStrOrEqual);
UnityPrintNumberByStyle(threshold, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
-
-
#define UnityPrintPointlessAndBail() \
{ \
UnityTestResultsFailBegin(lineNumber); \
UnityPrint(UnityStrPointless); \
UnityAddMsgIfSpecified(msg); \
@@ -602,11 +619,11 @@
if (expected == actual) return; /* Both are NULL or same pointer */
if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
UNITY_FAIL_AND_BAIL;
- while (elements--)
+ while ((elements > 0) && elements--)
{
UNITY_INT expect_val;
UNITY_INT actual_val;
switch (length)
{
@@ -659,17 +676,17 @@
}
/*-----------------------------------------------*/
#ifndef UNITY_EXCLUDE_FLOAT
/* Wrap this define in a function with variable types as float or double */
-#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
- if (isinf(expected) && isinf(actual) && ((expected < 0) == (actual < 0))) return 1; \
- if (UNITY_NAN_CHECK) return 1; \
- diff = actual - expected; \
- if (diff < 0) diff = -diff; \
- if (delta < 0) delta = -delta; \
- return !(isnan(diff) || isinf(diff) || (diff > delta))
+#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
+ if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \
+ if (UNITY_NAN_CHECK) return 1; \
+ (diff) = (actual) - (expected); \
+ if ((diff) < 0) (diff) = -(diff); \
+ if ((delta) < 0) (delta) = -(delta); \
+ return !(isnan(diff) || isinf(diff) || ((diff) > (delta)))
/* This first part of this condition will catch any NaN or Infinite values */
#ifndef UNITY_NAN_NOT_EQUAL_NAN
#define UNITY_NAN_CHECK isnan(expected) && isnan(actual)
#else
#define UNITY_NAN_CHECK 0
@@ -956,11 +973,11 @@
RETURN_IF_FAIL_OR_IGNORE;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
if (actual > expected)
- Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
+ Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
else
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta);
}
else
{
@@ -1071,11 +1088,11 @@
const UNITY_LINE_TYPE lineNumber,
const UNITY_FLAGS_T flags)
{
UNITY_UINT32 i = 0;
UNITY_UINT32 j = 0;
- const char* exp = NULL;
+ const char* expd = NULL;
const char* act = NULL;
RETURN_IF_FAIL_OR_IGNORE;
/* if no elements, it's an error */
@@ -1094,36 +1111,36 @@
UNITY_FAIL_AND_BAIL;
}
if (flags != UNITY_ARRAY_TO_ARRAY)
{
- exp = (const char*)expected;
+ expd = (const char*)expected;
}
do
{
act = actual[j];
if (flags == UNITY_ARRAY_TO_ARRAY)
{
- exp = ((const char* const*)expected)[j];
+ expd = ((const char* const*)expected)[j];
}
/* if both pointers not null compare the strings */
- if (exp && act)
+ if (expd && act)
{
- for (i = 0; exp[i] || act[i]; i++)
+ for (i = 0; expd[i] || act[i]; i++)
{
- if (exp[i] != act[i])
+ if (expd[i] != act[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
else
{ /* handle case of one pointers being null (if both null, test should pass) */
- if (exp != act)
+ if (expd != act)
{
Unity.CurrentTestFailed = 1;
}
}
@@ -1133,11 +1150,11 @@
if (num_elements > 1)
{
UnityPrint(UnityStrElement);
UnityPrintNumberUnsigned(j);
}
- UnityPrintExpectedAndActualStrings(exp, act);
+ UnityPrintExpectedAndActualStrings(expd, act);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
} while (++j < num_elements);
}
@@ -1309,21 +1326,10 @@
}
UNITY_IGNORE_AND_BAIL;
}
/*-----------------------------------------------*/
-#if defined(UNITY_WEAK_ATTRIBUTE)
- UNITY_WEAK_ATTRIBUTE void setUp(void) { }
- UNITY_WEAK_ATTRIBUTE void tearDown(void) { }
-#elif defined(UNITY_WEAK_PRAGMA)
- #pragma weak setUp
- void setUp(void) { }
- #pragma weak tearDown
- void tearDown(void) { }
-#endif
-
-/*-----------------------------------------------*/
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
Unity.NumberOfTests++;
@@ -1349,9 +1355,10 @@
Unity.NumberOfTests = 0;
Unity.TestFailures = 0;
Unity.TestIgnores = 0;
Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0;
+ UNITY_EXEC_TIME_RESET();
UNITY_CLR_DETAILS();
UNITY_OUTPUT_START();
}