提交 6e2de5e5 编写于 作者: G greg-williams

* Converted Unity to use setjmp/jongjmp for aborting upon test failures

* Eliminated TEST_WRAP and TEST_WRAP_NO_RETURN, since new abort mechanism eliminates the need to use these
- Updated documentation
- Changed default target to GCC in both Unity test and example project

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@7 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 8f6a7ad7
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
==============
Unity Test API
==============
......@@ -31,13 +32,13 @@ Ignore this test and return immediately. Output a message stating why the test
Aborting Tests
--------------
There are times when a test will contain an infinite loop on error conditions, or there may be reason to escape from the test early without executing the rest of the test. A pair of macros support this functionality in Unity. The first (TEST_PROTECT) sets up the feature, and handles emergency abort cases. TEST_THROW can then be used at any time within the tests to return to the last TEST_PROTECT call.
There are times when a test will contain an infinite loop on error conditions, or there may be reason to escape from the test early without executing the rest of the test. A pair of macros support this functionality in Unity. The first (TEST_PROTECT) sets up the feature, and handles emergency abort cases. TEST_ABORT can then be used at any time within the tests to return to the last TEST_PROTECT call.
TEST_PROTECT()
Setup and Catch macro
TEST_THROW (message)
TEST_ABORT()
Abort Test macro
......@@ -51,8 +52,12 @@ main()
}
}
If MyTest calls TEST_THROW, a failure with the message provided will be inserted, and program control will immediately return to TEST_PROTECT with a non-zero return value.
If MyTest calls TEST_ABORT, program control will immediately return to TEST_PROTECT with a non-zero return value.
=======================
Unity Assertion Summary
=======================
--------------------
Basic Validity Tests
......
......@@ -8,10 +8,10 @@ require '../auto/unity_test_summary'
require '../auto/generate_test_runner'
#USE THIS ONE IF YOU WANT TO TRY THIS WITH GCC
#require 'rakefile_helper_GCC'
require 'rakefile_helper_GCC'
#USE THIS ONE IF YOU WANT TO TRY THIS WITH IAR
require 'rakefile_helper_IAR'
#require 'rakefile_helper_IAR'
include RakefileHelpers
......
......@@ -5,8 +5,8 @@ void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned
void AssertEqualArrayInt(int* expected, int* actual, unsigned int length);
void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, unsigned int length);
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, length) {TEST_WRAP(AssertEqualArrayUint(expected, actual, length));}
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {TEST_WRAP(AssertEqualArrayInt(expected, actual, length));}
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {TEST_WRAP(AssertEqualArrayFloatWithin(tolerance, expected, actual, length));}
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, length) {AssertEqualArrayUint(expected, actual, length);}
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualArrayInt(expected, actual, length);}
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {AssertEqualArrayFloatWithin(tolerance, expected, actual, length);}
#endif // _TESTHELPER_H
......@@ -4,6 +4,7 @@
#define UNITY
#include <stdio.h>
#include <setjmp.h>
typedef void (*UnityTestFunction)(void);
......@@ -26,6 +27,8 @@ struct _Unity
unsigned char CurrentTestIgnored;
const char *TestFile;
float DefaultDelta;
jmp_buf* volatile pAbortFrame;
jmp_buf AbortFrame;
};
extern struct _Unity Unity;
......@@ -64,38 +67,20 @@ void UnityFail(const char *message, int line);
void UnityIgnore(const char *message, int line);
#define EXIT_WRAPPED_TEST(exprString) \
if( Unity.CurrentTestFailed ) {\
UnityPrint(__FILE__); \
UnityPrint(":"); \
UnityPrintNumber(__LINE__); \
UnityPrint(":REDIRECTED:"); \
UnityPrint(exprString); \
UnityPrintChar('\n'); \
}
#define RETURN_IF_NECESSARY() \
if( Unity.CurrentTestFailed || Unity.CurrentTestIgnored ) {return;}
#define TEST_WRAP_NO_RETURN(function) \
{\
function; \
EXIT_WRAPPED_TEST(#function); \
}
#define TEST_PROTECT() (setjmp(*Unity.pAbortFrame) == 0)
#define TEST_ABORT() {longjmp(*Unity.pAbortFrame, 1);}
#define ABORT_IF_NECESSARY() \
if( Unity.CurrentTestFailed || Unity.CurrentTestIgnored ) {TEST_ABORT();}
#define RUN_TEST(func) \
Unity.CurrentTestName = #func; \
Unity.pAbortFrame = &Unity.AbortFrame; \
Unity.NumberOfTests ++; \
runTest(func); \
UnityConcludeTest();
#define TEST_WRAP(function) \
{\
TEST_WRAP_NO_RETURN(function); \
Unity.TestFile=__FILE__; \
RETURN_IF_NECESSARY(); \
}
#define TEST_ASSERT_MESSAGE(condition, message) if (condition) {} else {TEST_FAIL(message);}
#define TEST_ASSERT(condition) TEST_ASSERT_MESSAGE(condition, NULL)
......@@ -115,7 +100,7 @@ if( Unity.CurrentTestFailed ) {\
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_INT); \
RETURN_IF_NECESSARY();
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_INT(expected, actual) TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) TEST_ASSERT_EQUAL_INT_MESSAGE((expected), (actual), (message))
......@@ -124,31 +109,31 @@ if( Unity.CurrentTestFailed ) {\
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertIntsWithin((delta), (expected), (actual), NULL, (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_UINT); \
RETURN_IF_NECESSARY();
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_UINT(expected, actual) TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX8); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX16); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertEqualInt((int)(expected), (int)(actual), (message), (unsigned short)__LINE__, UNITY_DISPLAY_STYLE_HEX32); \
RETURN_IF_NECESSARY();
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, NULL)
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message)
......@@ -157,51 +142,48 @@ if( Unity.CurrentTestFailed ) {\
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertBits((mask), (expected), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertBits((mask), (-1), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertBits((mask), (0), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertBits((1 << bit), (-1), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
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__; \
UnityAssertBits((1 << bit), (0), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
ABORT_IF_NECESSARY();
#define TEST_ASSERT_BIT_LOW(bit, actual) TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, NULL)
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertFloatsWithin((delta), (expected), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
ABORT_IF_NECESSARY();
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, NULL)
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) \
Unity.TestFile=__FILE__; \
UnityAssertEqualString((expected), (actual), (message), (unsigned short)__LINE__); \
RETURN_IF_NECESSARY();
ABORT_IF_NECESSARY();
#define TEST_ASSERT_EQUAL_STRING(expected, actual) TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, NULL)
#define TEST_FAIL(message) { Unity.TestFile=__FILE__; UnityFail((message), (unsigned short)__LINE__); return; }
#define TEST_IGNORE_MESSAGE(message) { Unity.TestFile=__FILE__; UnityIgnore((message), (unsigned short)__LINE__); return; }
#define TEST_IGNORE() TEST_IGNORE_MESSAGE("")
#define TEST_PROTECT() (setjmp(AbortFrame) == 0)
#define TEST_THROW(message) { Unity.TestFile=__FILE__; UnityFail((message), (unsigned short)__LINE__); longjmp(AbortFrame, 1); }
#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_IGNORE() TEST_IGNORE_MESSAGE(NULL)
#endif
......@@ -3,6 +3,18 @@
#include <setjmp.h>
#include "unity.h"
#define EXPECT_ABORT_BEGIN \
{ \
jmp_buf NewFrame, *PrevFrame = Unity.pAbortFrame; \
Unity.pAbortFrame = &NewFrame; \
if (TEST_PROTECT()) \
{
#define EXPECT_ABORT_END \
} \
Unity.pAbortFrame = PrevFrame; \
}
void setUp(void)
{
}
......@@ -30,16 +42,14 @@ void testPreviousPass(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void vanilla_asserter(int val)
{
TEST_ASSERT(val);
}
void testNotVanilla(void)
{
int failed;
vanilla_asserter(0);
EXPECT_ABORT_BEGIN
TEST_ASSERT(0);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -47,15 +57,13 @@ void testNotVanilla(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void true_asserter(int val)
{
TEST_ASSERT_TRUE(val);
}
void testNotTrue(void)
{
int failed;
true_asserter(0);
EXPECT_ABORT_BEGIN
TEST_ASSERT_TRUE(0);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -64,15 +72,13 @@ void testNotTrue(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void false_asserter(int val)
{
TEST_ASSERT_FALSE(val);
}
void testNotFalse(void)
{
int failed;
false_asserter(1);
EXPECT_ABORT_BEGIN
TEST_ASSERT_FALSE(1);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -81,15 +87,13 @@ void testNotFalse(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void unless_asserter(int val)
{
TEST_ASSERT_UNLESS(val);
}
void testNotUnless(void)
{
int failed;
unless_asserter(1);
EXPECT_ABORT_BEGIN
TEST_ASSERT_UNLESS(1);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -98,15 +102,13 @@ void testNotUnless(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void failer(void)
{
TEST_FAIL("Expected for testing");
}
void testFail(void)
{
int failed;
failer();
EXPECT_ABORT_BEGIN
TEST_FAIL("Expected for testing");
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -115,31 +117,14 @@ void testFail(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void ignorer(void)
{
TEST_IGNORE();
TEST_FAIL("This should not be reached");
}
void assertIgnoreInWrapper(void)
{
TEST_WRAP(ignorer());
TEST_FAIL("This should not be reached");
}
void testIgnoreInWrapper(void)
{
unsigned char ignored;
assertIgnoreInWrapper();
ignored = Unity.CurrentTestIgnored;
Unity.CurrentTestIgnored = 0;
TEST_ASSERT_EQUAL_INT(1, ignored);
}
void testIgnore(void)
{
int ignored;
ignorer();
EXPECT_ABORT_BEGIN
TEST_IGNORE();
TEST_FAIL("This should not be reached");
EXPECT_ABORT_END
ignored = Unity.CurrentTestIgnored;
Unity.CurrentTestIgnored = 0;
......@@ -147,63 +132,28 @@ void testIgnore(void)
TEST_ASSERT(ignored);
}
void ignorerWithMessage(void)
{
TEST_IGNORE_MESSAGE("This is an expected TEST_IGNORE_MESSAGE string!");
TEST_FAIL("This should not be reached");
}
void testIgnoreMessage(void)
{
int ignored;
ignorerWithMessage();
ignored = Unity.CurrentTestIgnored;
Unity.CurrentTestIgnored = 0;
TEST_ASSERT(ignored);
}
void assertIgnoreWithMessageInWrapper(void)
{
TEST_WRAP(ignorerWithMessage());
EXPECT_ABORT_BEGIN
TEST_IGNORE_MESSAGE("This is an expected TEST_IGNORE_MESSAGE string!");
TEST_FAIL("This should not be reached");
}
EXPECT_ABORT_END
void testIgnoreMessageInWrapper(void)
{
unsigned char ignored;
assertIgnoreWithMessageInWrapper();
ignored = Unity.CurrentTestIgnored;
Unity.CurrentTestIgnored = 0;
TEST_ASSERT_EQUAL_INT(1, ignored);
}
void wrapper(void)
{
TEST_WRAP(failer()); // if this doesn't force a return, then the failures will be incorrectly reset
Unity.CurrentTestFailed = 0;
}
void testWrap(void)
{
int failed;
wrapper();
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0U;
TEST_ASSERT_EQUAL_INT(1U, failed);
}
void intFailer(void)
{
TEST_ASSERT_EQUAL_INT(3982, 3983);
TEST_ASSERT(ignored);
}
void testNotEqualInts(void)
{
int failed;
intFailer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_INT(3982, 3983);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -211,15 +161,13 @@ void testNotEqualInts(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
}
void bitFailer(void)
{
TEST_ASSERT_BITS(0xFF00, 0x5555, 0x5A55);
}
void testNotEqualBits(void)
{
int failed;
bitFailer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_BITS(0xFF00, 0x5555, 0x5A55);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -227,15 +175,14 @@ void testNotEqualBits(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
}
void uintFailer(void)
{
TEST_ASSERT_EQUAL_UINT(900000, 900001);
}
void testNotEqualUInts(void)
{
int failed;
uintFailer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_UINT(900000, 900001);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -243,15 +190,13 @@ void testNotEqualUInts(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
}
void hex8Failer(void)
{
TEST_ASSERT_EQUAL_HEX8(0x23,0x22);
}
void testNotEqualHex8s(void)
{
int failed;
hex8Failer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_HEX8(0x23,0x22);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -259,15 +204,13 @@ void testNotEqualHex8s(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
}
void hex16Failer(void)
{
TEST_ASSERT_EQUAL_HEX16(0x1234, 0x1235);
}
void testNotEqualHex16s(void)
{
int failed;
hex16Failer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_HEX16(0x1234, 0x1235);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -275,35 +218,14 @@ void testNotEqualHex16s(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
}
void hex32Failer(void)
{
TEST_ASSERT_EQUAL_HEX32(900000, 900001);
}
void testNotEqualHex32s(void)
{
int failed;
hex32Failer();
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
TEST_ASSERT_MESSAGE(1U == failed, "This is expected");
}
void UnwrappedAssertion(int expected, int actual)
{
TEST_ASSERT_EQUAL(expected,actual);
}
void testMultipleUnwrappedAssertionsHandledAppropriately(void)
{
int failed;
UnwrappedAssertion(4,5);
UnwrappedAssertion(6,6);
UnwrappedAssertion(19,19);
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_HEX32(900000, 900001);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -516,15 +438,13 @@ void testFloatsWithinDelta(void)
TEST_ASSERT_FLOAT_WITHIN(0.007f, -726.93724f, -726.94424f);
}
void floatWithinFailer(void)
{
TEST_ASSERT_FLOAT_WITHIN(0.05f, 9273.2649f, 9273.2049f);
}
void testFloatsNotWithinDelta(void)
{
int failed;
floatWithinFailer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_FLOAT_WITHIN(0.05f, 9273.2649f, 9273.2049f);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -540,15 +460,13 @@ void testIntsWithinDelta(void)
TEST_ASSERT_INT_WITHIN(500, 50, -440);
}
void intWithinFailer(void)
{
TEST_ASSERT_INT_WITHIN(5, 5000, 5006);
}
void testIntsNotWithinDelta(void)
{
int failed;
intWithinFailer();
EXPECT_ABORT_BEGIN
TEST_ASSERT_INT_WITHIN(5, 5000, 5006);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -568,25 +486,13 @@ void testEqualStrings(void)
TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures);
}
void stringFailer1(void)
{
TEST_ASSERT_EQUAL_STRING("foo", "bar");
}
void stringFailer2(void)
{
TEST_ASSERT_EQUAL_STRING("foo", "");
}
void stringFailer3(void)
{
TEST_ASSERT_EQUAL_STRING("", "bar");
}
void testNotEqualString1(void)
{
int failed;
stringFailer1();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", "bar");
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -597,7 +503,10 @@ void testNotEqualString1(void)
void testNotEqualString2(void)
{
int failed;
stringFailer2();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", "");
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -608,7 +517,10 @@ void testNotEqualString2(void)
void testNotEqualString3(void)
{
int failed;
stringFailer3();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("", "bar");
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -616,15 +528,13 @@ void testNotEqualString3(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
}
void stringFailer_ExpectedStringIsNull(void)
{
TEST_ASSERT_EQUAL_STRING(NULL, "bar");
}
void testNotEqualString_ExpectedStringIsNull(void)
{
int failed;
stringFailer_ExpectedStringIsNull();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING(NULL, "bar");
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -632,15 +542,13 @@ void testNotEqualString_ExpectedStringIsNull(void)
TEST_ASSERT_MESSAGE(1U == failed, "This is also expected");
}
void stringFailer_ActualStringIsNull(void)
{
TEST_ASSERT_EQUAL_STRING("foo", NULL);
}
void testNotEqualString_ActualStringIsNull(void)
{
int failed;
stringFailer_ActualStringIsNull();
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING("foo", NULL);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
Unity.CurrentTestFailed = 0;
......@@ -651,12 +559,11 @@ void testNotEqualString_ActualStringIsNull(void)
void testProtection(void)
{
volatile int mask = 0;
jmp_buf AbortFrame;
if (TEST_PROTECT())
{
mask |= 1;
TEST_THROW("This throw was expected");
TEST_ABORT();
}
else
{
......
......@@ -14,18 +14,14 @@ void testNotTrue(void);
void testNotFalse(void);
void testNotUnless(void);
void testFail(void);
void testIgnoreInWrapper(void);
void testIgnore(void);
void testIgnoreMessage(void);
void testIgnoreMessageInWrapper(void);
void testWrap(void);
void testNotEqualInts(void);
void testNotEqualBits(void);
void testNotEqualUInts(void);
void testNotEqualHex8s(void);
void testNotEqualHex16s(void);
void testNotEqualHex32s(void);
void testMultipleUnwrappedAssertionsHandledAppropriately(void);
void testEqualInts(void);
void testEqualUints(void);
void testEqualHex8s(void);
......@@ -52,9 +48,12 @@ void testProtection(void);
static void runTest(UnityTestFunction test)
{
if (TEST_PROTECT())
{
setUp();
test();
tearDown();
}
tearDown();
}
int main(void)
......@@ -65,24 +64,20 @@ int main(void)
// RUN_TEST calls runTest
RUN_TEST(testTrue);
RUN_TEST(testFalse);
RUN_TEST(testPreviousPass);
RUN_TEST(testNotVanilla);
RUN_TEST(testNotTrue);
RUN_TEST(testNotFalse);
RUN_TEST(testNotUnless);
RUN_TEST(testPreviousPass);
RUN_TEST(testFail);
RUN_TEST(testWrap);
RUN_TEST(testIgnoreInWrapper);
RUN_TEST(testIgnore);
RUN_TEST(testIgnoreMessage);
RUN_TEST(testIgnoreMessageInWrapper);
RUN_TEST(testNotEqualBits);
RUN_TEST(testNotEqualInts);
RUN_TEST(testNotEqualUInts);
RUN_TEST(testNotEqualHex8s);
RUN_TEST(testNotEqualHex16s);
RUN_TEST(testNotEqualHex32s);
RUN_TEST(testMultipleUnwrappedAssertionsHandledAppropriately);
RUN_TEST(testEqualBits);
RUN_TEST(testEqualInts);
RUN_TEST(testEqualUints);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册