mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-25 10:13:12 +08:00
Merge pull request #178 from jsalling/feature/coverage-fixture
100% code coverage for Unity Fixture
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
CC = gcc
|
||||
ifeq ($(shell uname -s), Darwin)
|
||||
CC = clang
|
||||
endif
|
||||
#DEBUG = -O0 -g
|
||||
CFLAGS += -std=c99
|
||||
CFLAGS += -pedantic
|
||||
@ -15,21 +18,22 @@ SRC = ../src/unity_fixture.c \
|
||||
main/AllTests.c
|
||||
|
||||
INC_DIR = -I../src -I../../../src/
|
||||
BUILD_DIR = ../build
|
||||
TARGET = ../build/fixture_tests.exe
|
||||
|
||||
all: default noStdlibMalloc 32bits
|
||||
|
||||
default: ../build/
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET)
|
||||
default: $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_SUPPORT_64
|
||||
@ echo "default build"
|
||||
./$(TARGET)
|
||||
|
||||
32bits: ../build/
|
||||
32bits: $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32
|
||||
@ echo "32bits build"
|
||||
./$(TARGET)
|
||||
|
||||
noStdlibMalloc: ../build/
|
||||
noStdlibMalloc: $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC
|
||||
@ echo "build with noStdlibMalloc"
|
||||
./$(TARGET)
|
||||
@ -40,13 +44,22 @@ clang89: ../build/
|
||||
-D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89 -Wno-comment ; ./$(TARGET)
|
||||
|
||||
clangEverything:
|
||||
clang $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m64 -Weverything
|
||||
clang $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -Weverything
|
||||
|
||||
../build :
|
||||
mkdir -p ../build
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
rm -f $(TARGET) $(BUILD_DIR)/*.gc*
|
||||
|
||||
coverage: $(BUILD_DIR)
|
||||
cd $(BUILD_DIR) && \
|
||||
$(CC) $(DEFINES) $(foreach i, $(SRC), ../test/$(i)) $(INC_DIR) -o $(TARGET) -fprofile-arcs -ftest-coverage
|
||||
rm -f $(BUILD_DIR)/*.gcda
|
||||
./$(TARGET) > /dev/null ; ./$(TARGET) -v > /dev/null
|
||||
cd $(BUILD_DIR) && \
|
||||
gcov unity_fixture.c | head -3
|
||||
grep '###' $(BUILD_DIR)/unity_fixture.c.gcov -C2 || true # Show uncovered lines
|
||||
|
||||
# These extended flags DO get included before any target build runs
|
||||
CFLAGS += -Wbad-function-cast
|
||||
@ -62,5 +75,6 @@ CFLAGS += -Wstrict-prototypes
|
||||
CFLAGS += -Wswitch-default
|
||||
CFLAGS += -Wundef
|
||||
CFLAGS += -Wno-error=undef # Warning only, this should not stop the build
|
||||
CFLAGS += -Wunreachable-code
|
||||
CFLAGS += -Wunused
|
||||
CFLAGS += -fstrict-aliasing
|
||||
|
@ -136,6 +136,22 @@ TEST(UnityFixture, FreeNULLSafety)
|
||||
free(NULL);
|
||||
}
|
||||
|
||||
TEST(UnityFixture, ConcludeTestIncrementsFailCount)
|
||||
{
|
||||
_U_UINT savedFails = Unity.TestFailures;
|
||||
_U_UINT savedIgnores = Unity.TestIgnores;
|
||||
UnityOutputCharSpy_Enable(1);
|
||||
Unity.CurrentTestFailed = 1;
|
||||
UnityConcludeFixtureTest(); // Resets TestFailed for this test to pass
|
||||
Unity.CurrentTestIgnored = 1;
|
||||
UnityConcludeFixtureTest(); // Resets TestIgnored
|
||||
UnityOutputCharSpy_Enable(0);
|
||||
TEST_ASSERT_EQUAL(savedFails + 1, Unity.TestFailures);
|
||||
TEST_ASSERT_EQUAL(savedIgnores + 1, Unity.TestIgnores);
|
||||
Unity.TestFailures = savedFails;
|
||||
Unity.TestIgnores = savedIgnores;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
TEST_GROUP(UnityCommandOptions);
|
||||
@ -276,6 +292,21 @@ TEST(UnityCommandOptions, UnknownCommandIsIgnored)
|
||||
TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount);
|
||||
}
|
||||
|
||||
TEST(UnityCommandOptions, GroupOrNameFilterWithoutStringFails)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(3, unknownCommand));
|
||||
TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(5, unknownCommand));
|
||||
TEST_ASSERT_EQUAL(1, UnityMain(3, unknownCommand, NULL));
|
||||
}
|
||||
|
||||
TEST(UnityCommandOptions, GroupFilterReallyFilters)
|
||||
{
|
||||
_U_UINT saved = Unity.NumberOfTests;
|
||||
TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(4, unknownCommand));
|
||||
UnityIgnoreTest(NULL, "non-matching", NULL);
|
||||
TEST_ASSERT_EQUAL(saved, Unity.NumberOfTests);
|
||||
}
|
||||
|
||||
IGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored)
|
||||
{
|
||||
TEST_FAIL_MESSAGE("This test should not run!");
|
||||
|
@ -19,6 +19,7 @@ TEST_GROUP_RUNNER(UnityFixture)
|
||||
RUN_TEST_CASE(UnityFixture, CallocFillsWithZero);
|
||||
RUN_TEST_CASE(UnityFixture, PointerSet);
|
||||
RUN_TEST_CASE(UnityFixture, FreeNULLSafety);
|
||||
RUN_TEST_CASE(UnityFixture, ConcludeTestIncrementsFailCount);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(UnityCommandOptions)
|
||||
@ -32,6 +33,8 @@ TEST_GROUP_RUNNER(UnityCommandOptions)
|
||||
RUN_TEST_CASE(UnityCommandOptions, MultipleOptions);
|
||||
RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified);
|
||||
RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored);
|
||||
RUN_TEST_CASE(UnityCommandOptions, GroupOrNameFilterWithoutStringFails);
|
||||
RUN_TEST_CASE(UnityCommandOptions, GroupFilterReallyFilters);
|
||||
RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ static int spy_enable;
|
||||
|
||||
void UnityOutputCharSpy_Create(int s)
|
||||
{
|
||||
size = s;
|
||||
size = (s > 0) ? s : 0;
|
||||
count = 0;
|
||||
spy_enable = 0;
|
||||
buffer = malloc((size_t)size);
|
||||
|
Reference in New Issue
Block a user