mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-10-19 13:23:36 +08:00
- Added ability to tack on details to a Unity failure message.
This commit is contained in:
14
src/unity.c
14
src/unity.c
@ -365,6 +365,18 @@ static void UnityAddMsgIfSpecified(const char* msg)
|
||||
if (msg)
|
||||
{
|
||||
UnityPrint(UnityStrSpacer);
|
||||
#ifndef UNITY_EXCLUDE_DETAILS
|
||||
if (Unity.CurrentDetail1)
|
||||
{
|
||||
UnityPrint(Unity.CurrentDetail1);
|
||||
UnityPrint(UnityStrSpacer);
|
||||
if (Unity.CurrentDetail2)
|
||||
{
|
||||
UnityPrint(Unity.CurrentDetail2);
|
||||
UnityPrint(UnityStrSpacer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
UnityPrint(msg);
|
||||
}
|
||||
}
|
||||
@ -1242,6 +1254,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
|
||||
Unity.CurrentTestName = FuncName;
|
||||
Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
|
||||
Unity.NumberOfTests++;
|
||||
UNITY_CLR_DETAILS();
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
setUp();
|
||||
@ -1266,6 +1279,7 @@ void UnityBegin(const char* filename)
|
||||
Unity.CurrentTestFailed = 0;
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
|
||||
UNITY_CLR_DETAILS();
|
||||
UNITY_OUTPUT_START();
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,10 @@ struct _Unity
|
||||
{
|
||||
const char* TestFile;
|
||||
const char* CurrentTestName;
|
||||
#ifndef UNITY_EXCLUDE_DETAILS
|
||||
const char* CurrentDetail1;
|
||||
const char* CurrentDetail2;
|
||||
#endif
|
||||
UNITY_LINE_TYPE CurrentTestLineNumber;
|
||||
UNITY_COUNTER_TYPE NumberOfTests;
|
||||
UNITY_COUNTER_TYPE TestFailures;
|
||||
@ -419,6 +423,16 @@ int UnityEnd(void);
|
||||
void UnityConcludeTest(void);
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
|
||||
|
||||
#ifndef UNITY_EXCLUDE_DETAILS
|
||||
#define UNITY_CLR_DETAILS() { Unity.CurrentDetail1 = 0; Unity.CurrentDetail2 = 0; }
|
||||
#define UNITY_SET_DETAIL(d1) { Unity.CurrentDetail1 = d1; Unity.CurrentDetail2 = 0; }
|
||||
#define UNITY_SET_DETAILS(d1,d2) { Unity.CurrentDetail1 = d1; Unity.CurrentDetail2 = d2; }
|
||||
#else
|
||||
#define UNITY_CLR_DETAILS()
|
||||
#define UNITY_SET_DETAIL(d1)
|
||||
#define UNITY_SET_DETAILS(d1,d2)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Output
|
||||
//-------------------------------------------------------
|
||||
|
@ -71,6 +71,7 @@ void testUnitySizeInitializationReminder(void)
|
||||
"still correct.";
|
||||
|
||||
/* Define a structure with all the same fields as `struct _Unity`. */
|
||||
#ifdef UNITY_EXCLUDE_DETAILS
|
||||
struct {
|
||||
const char* TestFile;
|
||||
const char* CurrentTestName;
|
||||
@ -82,6 +83,21 @@ void testUnitySizeInitializationReminder(void)
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
jmp_buf AbortFrame;
|
||||
} _Expected_Unity;
|
||||
#else
|
||||
struct {
|
||||
const char* TestFile;
|
||||
const char* CurrentTestName;
|
||||
const char* CurrentDetails1;
|
||||
const char* CurrentDetails2;
|
||||
UNITY_LINE_TYPE CurrentTestLineNumber;
|
||||
UNITY_COUNTER_TYPE NumberOfTests;
|
||||
UNITY_COUNTER_TYPE TestFailures;
|
||||
UNITY_COUNTER_TYPE TestIgnores;
|
||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
jmp_buf AbortFrame;
|
||||
} _Expected_Unity;
|
||||
#endif
|
||||
|
||||
/* Compare our fake structure's size to the actual structure's size. They
|
||||
* should be the same.
|
||||
@ -3484,3 +3500,43 @@ void testNotEqualDoubleArraysInf(void)
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testThatDetailsCanBeHandleOneDetail(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_DETAILS
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
UNITY_SET_DETAIL("Detail1");
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(5, 6, "Should Fail And Say Detail1");
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testThatDetailsCanBeHandleTwoDetails(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_DETAILS
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
UNITY_SET_DETAILS("Detail1","Detail2");
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_HEX8_MESSAGE(7, 8, "Should Fail And Say Detail1 and Detail2");
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testThatDetailsCanBeHandleSingleDetailClearingTwoDetails(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_DETAILS
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
UNITY_SET_DETAILS("Detail1","Detail2");
|
||||
UNITY_SET_DETAIL("DetailNew");
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("MEH", "GUH", "Should Fail And Say DetailNew");
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user