1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-30 11:44:27 +01:00

- standardized output format for test results

- added color coding to output

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@58 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
mvandervoord
2010-03-10 03:10:41 +00:00
parent e966e563c2
commit 5e75c90c89
5 changed files with 219 additions and 61 deletions

View File

@@ -133,9 +133,9 @@ void UnityPrintMask(const unsigned long mask, const unsigned long number)
}
}
void UnityTestResultsBegin(const long line)
void UnityTestResultsBegin(const char* file, const long line)
{
UnityPrint(Unity.TestFile);
UnityPrint(file);
UNITY_OUTPUT_CHAR(':');
UnityPrintNumber(line);
UNITY_OUTPUT_CHAR(':');
@@ -143,6 +143,12 @@ void UnityTestResultsBegin(const long line)
UNITY_OUTPUT_CHAR(':');
}
void UnityTestResultsFailBegin(const long line)
{
UnityTestResultsBegin(Unity.AssertContainerFile, line);
UnityPrint("FAIL:");
}
void UnityConcludeTest()
{
if (Unity.CurrentTestIgnored)
@@ -151,8 +157,8 @@ void UnityConcludeTest()
}
else if (!Unity.CurrentTestFailed)
{
UnityPrint(Unity.CurrentTestName);
UnityPrint("::: PASS\n");
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
UnityPrint("PASS\n");
}
else
{
@@ -173,7 +179,7 @@ void UnityAssertBits(const long mask,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Expected ");
UnityPrintMask(mask, expected);
UnityPrint(" was ");
@@ -198,7 +204,7 @@ void UnityAssertEqualNumber(const long expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Expected ");
UnityPrintNumberByStyle(expected, style);
UnityPrint(" was ");
@@ -223,7 +229,7 @@ void UnityAssertEqualNumberUnsigned(const unsigned long expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Expected ");
UnityPrintNumberByStyle(expected, style);
UnityPrint(" was ");
@@ -253,7 +259,7 @@ void UnityAssertEqualIntArray(const int* expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("You asked me to compare 0 elements of an array, which was pointless.");
if (msg)
{
@@ -270,7 +276,7 @@ void UnityAssertEqualIntArray(const int* expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Element ");
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(" Expected ");
@@ -304,7 +310,7 @@ void UnityAssertEqualUnsignedIntArray(const unsigned int* expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("You asked me to compare nothing, which was pointless.");
if (msg)
{
@@ -321,7 +327,7 @@ void UnityAssertEqualUnsignedIntArray(const unsigned int* expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Element ");
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(" Expected ");
@@ -362,7 +368,7 @@ void UnityAssertFloatsWithin(const _UF delta,
if (pos_delta < diff)
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Floats not within delta.");
if (msg)
{
@@ -390,7 +396,7 @@ void UnityAssertNumbersWithin(const long delta,
if (delta < diff)
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Values not within delta.");
if (msg)
{
@@ -412,7 +418,7 @@ void UnityAssertNumbersUnsignedWithin(const unsigned long delta,
if (delta < diff)
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Values not within delta.");
if (msg)
{
@@ -451,7 +457,7 @@ void UnityAssertEqualString(const char* expected,
if (Unity.CurrentTestFailed)
{
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Expected '");
UnityPrint(expected);
UnityPrint("' was '");
@@ -478,7 +484,7 @@ void UnityAssertEqualMemory(const void* expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("You asked me to compare nothing, which was pointless.");
if (msg)
{
@@ -507,7 +513,7 @@ void UnityAssertEqualMemory(const void* expected,
if (Unity.CurrentTestFailed)
{
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Memory Mismatch.");
if (msg)
{
@@ -532,7 +538,7 @@ void UnityAssertEqualMemoryArray(const void* expected,
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("You asked me to compare nothing, which was pointless.");
if (msg)
{
@@ -567,7 +573,7 @@ void UnityAssertEqualMemoryArray(const void* expected,
if (Unity.CurrentTestFailed)
{
UnityTestResultsBegin(lineNumber);
UnityTestResultsFailBegin(lineNumber);
UnityPrint("Element ");
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
UnityPrint(" Memory Mismatch.");
@@ -583,17 +589,27 @@ void UnityAssertEqualMemoryArray(const void* expected,
void UnityFail(const char* message, const long line)
{
Unity.CurrentTestFailed = 1;
UnityTestResultsBegin(line);
UnityPrint(message);
UnityTestResultsBegin(Unity.AssertContainerFile, line);
UnityPrint("FAIL");
if (message != NULL)
{
UNITY_OUTPUT_CHAR(':');
UnityPrint(message);
}
UNITY_OUTPUT_CHAR('\n');
}
void UnityIgnore(const char* message, const long line)
{
Unity.CurrentTestIgnored = 1;
UnityTestResultsBegin(line);
UnityPrint(message);
UnityPrint(" IGNORED\n");
UnityTestResultsBegin(Unity.AssertContainerFile, line);
UnityPrint("IGNORE");
if (message != NULL)
{
UNITY_OUTPUT_CHAR(':');
UnityPrint(message);
}
UNITY_OUTPUT_CHAR('\n');
}
void UnityBegin()

View File

@@ -76,7 +76,9 @@ typedef enum
struct _Unity
{
const char* TestFile;
const char* AssertContainerFile;
const char* CurrentTestName;
unsigned long CurrentTestLineNumber;
unsigned char NumberOfTests;
unsigned char TestFailures;
unsigned char TestIgnores;
@@ -199,8 +201,9 @@ void UnityAssertFloatsWithin(const _UF delta,
#define ABORT_IF_NECESSARY() \
if( Unity.CurrentTestFailed || Unity.CurrentTestIgnored ) {TEST_ABORT();}
#define RUN_TEST(func) \
#define RUN_TEST(func, line_num) \
Unity.CurrentTestName = #func; \
Unity.CurrentTestLineNumber = line_num; \
Unity.NumberOfTests ++; \
runTest(func); \
UnityConcludeTest();
@@ -228,13 +231,13 @@ void UnityAssertFloatsWithin(const _UF delta,
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) TEST_ASSERT_MESSAGE(pointer != NULL, message)
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_INT(expected, actual) TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualIntArray((const int*)(expected), (const int*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
@@ -246,43 +249,43 @@ void UnityAssertFloatsWithin(const _UF delta,
#define TEST_ASSERT_NOT_EQUAL(expected, actual) TEST_ASSERT_FALSE((expected) == (actual))
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertNumbersWithin((long)(delta), (long)(expected), (long)(actual), NULL, (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, NULL)
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualNumberUnsigned((unsigned long)(expected), (unsigned long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_UINT(expected, actual) TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualUnsignedIntArray((const unsigned int*)(expected), (const unsigned int*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualNumberUnsigned((unsigned long)(expected), (unsigned long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX8); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualNumberUnsigned((unsigned long)(expected), (unsigned long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX16); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualIntArray((const int*)(expected), (const int*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
@@ -291,62 +294,63 @@ void UnityAssertFloatsWithin(const _UF delta,
#define TEST_ASSERT_EQUAL_HEX(expected, actual) TEST_ASSERT_EQUAL_HEX32(expected, actual)
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualIntArray((const int*)(expected), (const int*)(actual), (unsigned long)(num_elements), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, NULL)
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertBits((mask), (expected), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_BITS(mask, expected, actual) TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, NULL)
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertBits((mask), (-1), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_BITS_HIGH(mask, actual) TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, NULL)
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertBits((mask), (0), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_BITS_LOW(mask, actual) TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, NULL)
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertBits(((_UU32)1 << bit), (-1), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_BIT_HIGH(bit, actual) TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, NULL)
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertBits(((_UU32)1 << bit), (0), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_BIT_LOW(bit, actual) TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, NULL)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualString((expected), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_STRING(expected, actual) TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualMemory((expected), (actual), (len), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, NULL)
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertEqualMemoryArray((expected), (actual), (len), (num_elements), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, NULL)
#define TEST_FAIL(message) { Unity.TestFile=__FILE__; UnityFail((message), (unsigned short)__LINE__); TEST_ABORT(); }
#define TEST_IGNORE_MESSAGE(message) { Unity.TestFile=__FILE__; UnityIgnore((message), (unsigned short)__LINE__); TEST_ABORT(); }
#define TEST_FAIL(message) { Unity.AssertContainerFile=__FILE__; UnityFail((message), (unsigned short)__LINE__); TEST_ABORT(); }
#define TEST_IGNORE_MESSAGE(message) { Unity.AssertContainerFile=__FILE__; UnityIgnore((message), (unsigned short)__LINE__); TEST_ABORT(); }
#define TEST_IGNORE() TEST_IGNORE_MESSAGE(NULL)
#define TEST_ONLY()
#ifdef UNITY_EXCLUDE_FLOAT
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) TEST_FAIL("Unity Floating Point Disabled");
@@ -355,7 +359,7 @@ void UnityAssertFloatsWithin(const _UF delta,
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) TEST_FAIL("Unity Floating Point Disabled");
#else
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) \
Unity.TestFile=__FILE__; \
Unity.AssertContainerFile=__FILE__; \
UnityAssertFloatsWithin((delta), (expected), (actual), (message), (unsigned short)__LINE__); \
ABORT_IF_NECESSARY();
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, NULL)