From f75f489b6effb8a396df3cc448a7bd1ec9cc90e6 Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 14 Dec 2015 16:40:07 -0600 Subject: [PATCH 1/5] Get rid of magic numbers and strlen call for 'end' string in Fixture Using sizeof() instead of constant 4, makes code less fragile to change Change name of 'guard' in Guard struct to 'guard_space' --- extras/fixture/src/unity_fixture.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index e781256..57009dc 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -179,11 +179,11 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown) typedef struct GuardBytes { size_t size; - char guard[sizeof(size_t)]; + char guard_space[4]; } Guard; -static const char * end = "END"; +static const char end[] = "END"; void * unity_malloc(size_t size) { @@ -199,10 +199,10 @@ void * unity_malloc(size_t size) malloc_count++; - guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4); + guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + sizeof(end)); guard->size = size; mem = (char*)&(guard[1]); - memcpy(&mem[size], end, strlen(end) + 1); + memcpy(&mem[size], end, sizeof(end)); return (void*)mem; } From 1703bd1a5e83f07917d98db7b64237ff1d162e65 Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 14 Dec 2015 17:04:17 -0600 Subject: [PATCH 2/5] Reduce stack usage by removing unnecessary call from group runner in Fixture Defining a group_runner which calls group_runner_runAll() is redundant --- extras/fixture/src/unity_fixture.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/extras/fixture/src/unity_fixture.h b/extras/fixture/src/unity_fixture.h index cbbdbae..57c8868 100644 --- a/extras/fixture/src/unity_fixture.h +++ b/extras/fixture/src/unity_fixture.h @@ -55,13 +55,8 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); //This goes at the bottom of each test file or in a separate c file #define TEST_GROUP_RUNNER(group)\ - void TEST_##group##_GROUP_RUNNER_runAll(void);\ void TEST_##group##_GROUP_RUNNER(void);\ - void TEST_##group##_GROUP_RUNNER(void)\ - {\ - TEST_##group##_GROUP_RUNNER_runAll();\ - }\ - void TEST_##group##_GROUP_RUNNER_runAll(void) + void TEST_##group##_GROUP_RUNNER(void) //Call this from main #define RUN_TEST_GROUP(group)\ From 81cf5eb6268d60566d610e19daee205d84875578 Mon Sep 17 00:00:00 2001 From: jsalling Date: Tue, 15 Dec 2015 17:32:55 -0600 Subject: [PATCH 3/5] Do not add EOL after every ignored test using Unity Fixture Revert part of commit 77af37ad, code looked like a temporary change The behavior is back to the original, printing "....!..." in quiet mode Added an ignored test to Fixture for visual inspection --- extras/fixture/src/unity_fixture.c | 6 +++--- extras/fixture/test/unity_fixture_Test.c | 4 ++++ extras/fixture/test/unity_fixture_TestRunner.c | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 57009dc..240661f 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -398,10 +398,10 @@ void UnityConcludeFixtureTest(void) { if (Unity.CurrentTestIgnored) { - //if (UnityFixture.Verbose) - //{ + if (UnityFixture.Verbose) + { UNITY_PRINT_EOL(); - //} + } Unity.TestIgnores++; } else if (!Unity.CurrentTestFailed) diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index 27652f6..af70934 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -277,6 +277,10 @@ TEST(UnityCommandOptions, UnknownCommandIsIgnored) TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); } +IGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored) +{ + TEST_FAIL_MESSAGE("This test should not run!"); +} //------------------------------------------------------------ diff --git a/extras/fixture/test/unity_fixture_TestRunner.c b/extras/fixture/test/unity_fixture_TestRunner.c index 28d8e56..6c1a90c 100644 --- a/extras/fixture/test/unity_fixture_TestRunner.c +++ b/extras/fixture/test/unity_fixture_TestRunner.c @@ -32,6 +32,7 @@ TEST_GROUP_RUNNER(UnityCommandOptions) RUN_TEST_CASE(UnityCommandOptions, MultipleOptions); RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified); RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored); + RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored); } TEST_GROUP_RUNNER(LeakDetection) From c629e120e104623d7a3648f4f00f1702e55657df Mon Sep 17 00:00:00 2001 From: jsalling Date: Wed, 16 Dec 2015 17:21:09 -0600 Subject: [PATCH 4/5] Fix Leak Detection always passing, but printing a fail message Don't set CurrentTestFailed = 0 at end, move before last check These tests now fail if the output_Spy is not used instead of putchar() --- extras/fixture/test/unity_fixture_Test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index af70934..238be5f 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -316,9 +316,9 @@ TEST(LeakDetection, DetectsLeak) UnityMalloc_EndTest(); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); + Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!")); free(m); - Unity.CurrentTestFailed = 0; } TEST(LeakDetection, BufferOverrunFoundDuringFree) @@ -331,8 +331,8 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree) free(m); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); - CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()")); Unity.CurrentTestFailed = 0; + CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()")); } TEST(LeakDetection, BufferOverrunFoundDuringRealloc) @@ -345,6 +345,6 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc) m = realloc(m, 100); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); - CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); Unity.CurrentTestFailed = 0; + CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); } From caa3f6663d50f7f67a66b6a2fae7628674d3677f Mon Sep 17 00:00:00 2001 From: jsalling Date: Fri, 18 Dec 2015 17:48:35 -0600 Subject: [PATCH 5/5] Add Makefile to fixture/test to make building tests easier No rake and ruby required to build existing tests --- extras/fixture/test/Makefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 extras/fixture/test/Makefile diff --git a/extras/fixture/test/Makefile b/extras/fixture/test/Makefile new file mode 100644 index 0000000..fe1d530 --- /dev/null +++ b/extras/fixture/test/Makefile @@ -0,0 +1,15 @@ +CC = gcc +DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar +SRC = ../src/unity_fixture.c \ + ../../../src/unity.c \ + unity_fixture_Test.c \ + unity_fixture_TestRunner.c \ + unity_output_Spy.c \ + main/AllTests.c + +INC_DIR = -I../src -I../../../src/ +TARGET = fixture_tests.exe + +all: + @ $(CC) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) + @ ./$(TARGET)