mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-30 19:54:26 +01:00
Merge pull request #149 from jsalling/refactor/fixture-cleanup
Refactor Fixture, no EOL with ignored tests, add a Makefile for Fixture tests
This commit is contained in:
@@ -179,11 +179,11 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown)
|
|||||||
typedef struct GuardBytes
|
typedef struct GuardBytes
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
char guard[sizeof(size_t)];
|
char guard_space[4];
|
||||||
} Guard;
|
} Guard;
|
||||||
|
|
||||||
|
|
||||||
static const char * end = "END";
|
static const char end[] = "END";
|
||||||
|
|
||||||
void * unity_malloc(size_t size)
|
void * unity_malloc(size_t size)
|
||||||
{
|
{
|
||||||
@@ -199,10 +199,10 @@ void * unity_malloc(size_t size)
|
|||||||
|
|
||||||
malloc_count++;
|
malloc_count++;
|
||||||
|
|
||||||
guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4);
|
guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + sizeof(end));
|
||||||
guard->size = size;
|
guard->size = size;
|
||||||
mem = (char*)&(guard[1]);
|
mem = (char*)&(guard[1]);
|
||||||
memcpy(&mem[size], end, strlen(end) + 1);
|
memcpy(&mem[size], end, sizeof(end));
|
||||||
|
|
||||||
return (void*)mem;
|
return (void*)mem;
|
||||||
}
|
}
|
||||||
@@ -398,10 +398,10 @@ void UnityConcludeFixtureTest(void)
|
|||||||
{
|
{
|
||||||
if (Unity.CurrentTestIgnored)
|
if (Unity.CurrentTestIgnored)
|
||||||
{
|
{
|
||||||
//if (UnityFixture.Verbose)
|
if (UnityFixture.Verbose)
|
||||||
//{
|
{
|
||||||
UNITY_PRINT_EOL();
|
UNITY_PRINT_EOL();
|
||||||
//}
|
}
|
||||||
Unity.TestIgnores++;
|
Unity.TestIgnores++;
|
||||||
}
|
}
|
||||||
else if (!Unity.CurrentTestFailed)
|
else if (!Unity.CurrentTestFailed)
|
||||||
|
|||||||
@@ -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
|
//This goes at the bottom of each test file or in a separate c file
|
||||||
#define TEST_GROUP_RUNNER(group)\
|
#define TEST_GROUP_RUNNER(group)\
|
||||||
void TEST_##group##_GROUP_RUNNER_runAll(void);\
|
|
||||||
void TEST_##group##_GROUP_RUNNER(void);\
|
void TEST_##group##_GROUP_RUNNER(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)
|
|
||||||
|
|
||||||
//Call this from main
|
//Call this from main
|
||||||
#define RUN_TEST_GROUP(group)\
|
#define RUN_TEST_GROUP(group)\
|
||||||
|
|||||||
15
extras/fixture/test/Makefile
Normal file
15
extras/fixture/test/Makefile
Normal file
@@ -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)
|
||||||
@@ -277,6 +277,10 @@ TEST(UnityCommandOptions, UnknownCommandIsIgnored)
|
|||||||
TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount);
|
TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored)
|
||||||
|
{
|
||||||
|
TEST_FAIL_MESSAGE("This test should not run!");
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
|
|
||||||
@@ -312,9 +316,9 @@ TEST(LeakDetection, DetectsLeak)
|
|||||||
UnityMalloc_EndTest();
|
UnityMalloc_EndTest();
|
||||||
EXPECT_ABORT_END
|
EXPECT_ABORT_END
|
||||||
UnityOutputCharSpy_Enable(0);
|
UnityOutputCharSpy_Enable(0);
|
||||||
|
Unity.CurrentTestFailed = 0;
|
||||||
CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!"));
|
CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!"));
|
||||||
free(m);
|
free(m);
|
||||||
Unity.CurrentTestFailed = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LeakDetection, BufferOverrunFoundDuringFree)
|
TEST(LeakDetection, BufferOverrunFoundDuringFree)
|
||||||
@@ -327,8 +331,8 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree)
|
|||||||
free(m);
|
free(m);
|
||||||
EXPECT_ABORT_END
|
EXPECT_ABORT_END
|
||||||
UnityOutputCharSpy_Enable(0);
|
UnityOutputCharSpy_Enable(0);
|
||||||
CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
|
|
||||||
Unity.CurrentTestFailed = 0;
|
Unity.CurrentTestFailed = 0;
|
||||||
|
CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LeakDetection, BufferOverrunFoundDuringRealloc)
|
TEST(LeakDetection, BufferOverrunFoundDuringRealloc)
|
||||||
@@ -341,6 +345,6 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc)
|
|||||||
m = realloc(m, 100);
|
m = realloc(m, 100);
|
||||||
EXPECT_ABORT_END
|
EXPECT_ABORT_END
|
||||||
UnityOutputCharSpy_Enable(0);
|
UnityOutputCharSpy_Enable(0);
|
||||||
CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()"));
|
|
||||||
Unity.CurrentTestFailed = 0;
|
Unity.CurrentTestFailed = 0;
|
||||||
|
CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ TEST_GROUP_RUNNER(UnityCommandOptions)
|
|||||||
RUN_TEST_CASE(UnityCommandOptions, MultipleOptions);
|
RUN_TEST_CASE(UnityCommandOptions, MultipleOptions);
|
||||||
RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified);
|
RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified);
|
||||||
RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored);
|
RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored);
|
||||||
|
RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP_RUNNER(LeakDetection)
|
TEST_GROUP_RUNNER(LeakDetection)
|
||||||
|
|||||||
Reference in New Issue
Block a user