mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-18 23:11:11 +08:00
Add TEST_MESSAGE for outputting messages without aborting a test and _MESSAGE variant to TEST_PASS collection.
This commit is contained in:
@@ -178,10 +178,12 @@ documentation for specifics.
|
|||||||
|
|
||||||
## The Assertions in All Their Blessed Glory
|
## The Assertions in All Their Blessed Glory
|
||||||
|
|
||||||
### Basic Fail and Ignore
|
### Basic Fail, Pass and Ignore
|
||||||
|
|
||||||
##### `TEST_FAIL()`
|
##### `TEST_FAIL()`
|
||||||
|
|
||||||
|
##### `TEST_FAIL_MESSAGE("message")`
|
||||||
|
|
||||||
This fella is most often used in special conditions where your test code is
|
This fella is most often used in special conditions where your test code is
|
||||||
performing logic beyond a simple assertion. That is, in practice, `TEST_FAIL()`
|
performing logic beyond a simple assertion. That is, in practice, `TEST_FAIL()`
|
||||||
will always be found inside a conditional code block.
|
will always be found inside a conditional code block.
|
||||||
@@ -192,13 +194,30 @@ code then verifies as a final step.
|
|||||||
- Triggering an exception and verifying it (as in Try / Catch / Throw - see the
|
- Triggering an exception and verifying it (as in Try / Catch / Throw - see the
|
||||||
[CException](https://github.com/ThrowTheSwitch/CException) project).
|
[CException](https://github.com/ThrowTheSwitch/CException) project).
|
||||||
|
|
||||||
|
##### `TEST_PASS()`
|
||||||
|
|
||||||
|
##### `TEST_PASS_MESSAGE("message")`
|
||||||
|
|
||||||
|
This will abort the remainder of the test, but count the test as a pass. Under
|
||||||
|
normal circumstances, it is not necessary to include this macro in your tests...
|
||||||
|
a lack of failure will automatically be counted as a `PASS`. It is occasionally
|
||||||
|
useful for tests with `#ifdef`s and such.
|
||||||
|
|
||||||
##### `TEST_IGNORE()`
|
##### `TEST_IGNORE()`
|
||||||
|
|
||||||
|
##### `TEST_IGNORE_MESSAGE("message")`
|
||||||
|
|
||||||
Marks a test case (i.e. function meant to contain test assertions) as ignored.
|
Marks a test case (i.e. function meant to contain test assertions) as ignored.
|
||||||
Usually this is employed as a breadcrumb to come back and implement a test case.
|
Usually this is employed as a breadcrumb to come back and implement a test case.
|
||||||
An ignored test case has effects if other assertions are in the enclosing test
|
An ignored test case has effects if other assertions are in the enclosing test
|
||||||
case (see Unity documentation for more).
|
case (see Unity documentation for more).
|
||||||
|
|
||||||
|
##### `TEST_MESSAGE(message)`
|
||||||
|
|
||||||
|
This can be useful for outputting `INFO` messages into the Unity output stream
|
||||||
|
without actually ending the test. Like pass and fail messages, it will be output
|
||||||
|
with the filename and line number.
|
||||||
|
|
||||||
### Boolean
|
### Boolean
|
||||||
|
|
||||||
##### `TEST_ASSERT (condition)`
|
##### `TEST_ASSERT (condition)`
|
||||||
|
|||||||
14
src/unity.c
14
src/unity.c
@@ -1715,6 +1715,20 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
|
|||||||
UNITY_IGNORE_AND_BAIL;
|
UNITY_IGNORE_AND_BAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
void UnityMessage(const char* msg, const UNITY_LINE_TYPE line)
|
||||||
|
{
|
||||||
|
UnityTestResultsBegin(Unity.TestFile, line);
|
||||||
|
UnityPrint("INFO");
|
||||||
|
if (msg != NULL)
|
||||||
|
{
|
||||||
|
UNITY_OUTPUT_CHAR(':');
|
||||||
|
UNITY_OUTPUT_CHAR(' ');
|
||||||
|
UnityPrint(msg);
|
||||||
|
}
|
||||||
|
UNITY_PRINT_EOL();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------*/
|
/*-----------------------------------------------*/
|
||||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
|
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -102,11 +102,13 @@ int suiteTearDown(int num_failures);
|
|||||||
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
|
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
|
||||||
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, (message))
|
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, (message))
|
||||||
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
|
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
|
||||||
|
#define TEST_MESSAGE(message) UnityMessage((message), __LINE__)
|
||||||
#define TEST_ONLY()
|
#define TEST_ONLY()
|
||||||
|
|
||||||
/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails.
|
/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails.
|
||||||
* This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */
|
* This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */
|
||||||
#define TEST_PASS() TEST_ABORT()
|
#define TEST_PASS() TEST_ABORT()
|
||||||
|
#define TEST_PASS_MESSAGE(message) do { UnityMessage((message), __LINE__); TEST_ABORT(); } while(0)
|
||||||
|
|
||||||
/* This macro does nothing, but it is useful for build tools (like Ceedling) to make use of this to figure out
|
/* This macro does nothing, but it is useful for build tools (like Ceedling) to make use of this to figure out
|
||||||
* which files should be linked to in order to perform a test. Use it like TEST_FILE("sandwiches.c") */
|
* which files should be linked to in order to perform a test. Use it like TEST_FILE("sandwiches.c") */
|
||||||
|
|||||||
@@ -614,8 +614,8 @@ void UnityAssertNumbersArrayWithin(const UNITY_UINT delta,
|
|||||||
const UNITY_FLAGS_T flags);
|
const UNITY_FLAGS_T flags);
|
||||||
|
|
||||||
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
|
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
|
||||||
|
|
||||||
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
|
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
|
||||||
|
void UnityMessage(const char* message, const UNITY_LINE_TYPE line);
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
void UnityAssertFloatsWithin(const UNITY_FLOAT delta,
|
void UnityAssertFloatsWithin(const UNITY_FLOAT delta,
|
||||||
|
|||||||
@@ -147,6 +147,28 @@ void testPassShouldEndImmediatelyWithPass(void)
|
|||||||
TEST_FAIL_MESSAGE("We should have passed already and finished this test");
|
TEST_FAIL_MESSAGE("We should have passed already and finished this test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testPassShouldEndImmediatelyWithPassAndMessage(void)
|
||||||
|
{
|
||||||
|
TEST_PASS_MESSAGE("Woohoo! This Automatically Passes!");
|
||||||
|
TEST_FAIL_MESSAGE("We should have passed already and finished this test");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testMessageShouldDisplayMessageWithoutEndingAndGoOnToPass(void)
|
||||||
|
{
|
||||||
|
TEST_MESSAGE("This is just a message");
|
||||||
|
TEST_MESSAGE("This is another message");
|
||||||
|
TEST_PASS();
|
||||||
|
}
|
||||||
|
|
||||||
|
void testMessageShouldDisplayMessageWithoutEndingAndGoOnToFail(void)
|
||||||
|
{
|
||||||
|
TEST_MESSAGE("This is yet another message");
|
||||||
|
|
||||||
|
EXPECT_ABORT_BEGIN
|
||||||
|
TEST_FAIL();
|
||||||
|
VERIFY_FAILS_END
|
||||||
|
}
|
||||||
|
|
||||||
void testTrue(void)
|
void testTrue(void)
|
||||||
{
|
{
|
||||||
TEST_ASSERT(1);
|
TEST_ASSERT(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user