Add TEST_MESSAGE for outputting messages without aborting a test and _MESSAGE variant to TEST_PASS collection.

This commit is contained in:
Mark VanderVoord
2019-07-06 11:02:32 -04:00
parent a54d58a8fd
commit 0000f1e6d2
5 changed files with 59 additions and 2 deletions

View File

@@ -178,10 +178,12 @@ documentation for specifics.
## The Assertions in All Their Blessed Glory
### Basic Fail and Ignore
### Basic Fail, Pass and Ignore
##### `TEST_FAIL()`
##### `TEST_FAIL_MESSAGE("message")`
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()`
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
[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_MESSAGE("message")`
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.
An ignored test case has effects if other assertions are in the enclosing test
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
##### `TEST_ASSERT (condition)`

View File

@@ -1715,6 +1715,20 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
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)
{

View File

@@ -102,11 +102,13 @@ int suiteTearDown(int num_failures);
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, (message))
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
#define TEST_MESSAGE(message) UnityMessage((message), __LINE__)
#define TEST_ONLY()
/* 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. */
#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
* which files should be linked to in order to perform a test. Use it like TEST_FILE("sandwiches.c") */

View File

@@ -614,8 +614,8 @@ void UnityAssertNumbersArrayWithin(const UNITY_UINT delta,
const UNITY_FLAGS_T flags);
void UnityFail(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
void UnityAssertFloatsWithin(const UNITY_FLOAT delta,

View File

@@ -147,6 +147,28 @@ void testPassShouldEndImmediatelyWithPass(void)
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)
{
TEST_ASSERT(1);