From 65e401f3dea82b308153829e8e002ebf0011995f Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 5 Dec 2016 21:21:03 -0600 Subject: [PATCH 1/2] Always run the tearDown() even if test is ignored --- auto/generate_test_runner.rb | 2 +- src/unity.c | 2 +- test/tests/testunity.c | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 134be65..8e8e5bb 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -276,7 +276,7 @@ class UnityTestRunnerGenerator output.puts(" TestFunc(#{va_args2}); \\") output.puts(" } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\"); } \\") if cexception output.puts(" } \\") - output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED) \\") + output.puts(" if (TEST_PROTECT()) \\") output.puts(" { \\") output.puts(" #{@options[:teardown_name]}(); \\") output.puts(" CMock_Verify(); \\") unless (used_mocks.empty?) diff --git a/src/unity.c b/src/unity.c index c755ebb..1255af5 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1275,7 +1275,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int setUp(); Func(); } - if (TEST_PROTECT() && !(Unity.CurrentTestIgnored)) + if (TEST_PROTECT()) { tearDown(); } diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 08c621a..bab24dc 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -67,7 +67,11 @@ void tearDown(void) { endPutcharSpy(); /* Stop suppressing test output */ if (SetToOneToFailInTearDown == 1) + { + /* These will be skipped internally if already failed/ignored */ TEST_FAIL_MESSAGE("<= Failed in tearDown"); + TEST_IGNORE_MESSAGE("<= Ignored in tearDown"); + } if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0)) { UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]"); From 41df8feaee32474cf98dfee8f4d80b0584db537c Mon Sep 17 00:00:00 2001 From: jsalling Date: Sat, 31 Dec 2016 13:59:07 -0600 Subject: [PATCH 2/2] Fix test for counting CMock_Verify calls --- test/testdata/testRunnerGeneratorWithMocks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testdata/testRunnerGeneratorWithMocks.c b/test/testdata/testRunnerGeneratorWithMocks.c index de749c0..7eb0b67 100644 --- a/test/testdata/testRunnerGeneratorWithMocks.c +++ b/test/testdata/testRunnerGeneratorWithMocks.c @@ -183,9 +183,9 @@ void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void) void test_ShouldCallMockInitAndVerifyFunctionsForEachTest(void) { - int passes = (int)(Unity.NumberOfTests - Unity.TestFailures - Unity.TestIgnores); + int passesOrIgnores = (int)(Unity.NumberOfTests - Unity.TestFailures); TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests, mockMock_Init_Counter, "Mock Init Should Be Called Once Per Test Started"); - TEST_ASSERT_EQUAL_MESSAGE(passes, mockMock_Verify_Counter, "Mock Verify Should Be Called Once Per Test Passed"); + TEST_ASSERT_EQUAL_MESSAGE(passesOrIgnores, mockMock_Verify_Counter, "Mock Verify Should Be Called Once Per Test Passed"); TEST_ASSERT_EQUAL_MESSAGE(Unity.NumberOfTests - 1, mockMock_Destroy_Counter, "Mock Destroy Should Be Called Once Per Test Completed"); TEST_ASSERT_EQUAL_MESSAGE(0, CMockMemFreeFinalCounter, "Mock MemFreeFinal Should Not Be Called Until End"); }