1
0
mirror of https://github.com/ThrowTheSwitch/Unity synced 2025-03-12 16:11:12 -04:00
Unity/test/Makefile
jsalling 13c99601a7 Add a value to FLOAT_TRAIT enum to enforce use of default case in switches
Revert the previous commit. Add tests for extended enum cases.
 Fix crash due to accessing 'trait_names' array out of bounds.
 Adding an extra invalid value to the end of an enum causes '-Wswitch' flag
  to warn unless there is a switch default case - also enabled by '-Wall'.
2016-03-02 14:56:09 -06:00

53 lines
1.9 KiB
Makefile

CC = gcc
ifeq ($(shell uname -s), Darwin)
CC = clang
endif
#DEBUG = -O0 -g
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
CFLAGS += $(DEBUG)
DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy -D UNITY_INCLUDE_DOUBLE
SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c
INC_DIR = -I ../src
COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src
BUILD_DIR = build
TARGET = build/testunity-cov.exe
# To generate coverage, call 'make -s', the default target runs.
# To see missing coverage, follow up with 'make uncovered'.
# For verbose output of all the tests, run 'make test'.
default: coverage
.PHONY: default coverage uncovered test clean
coverage: $(BUILD_DIR)/testunityRunner.c
cd $(BUILD_DIR) && \
$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC), ../$i) $(COV_FLAGS) -o ../$(TARGET)
rm -f $(BUILD_DIR)/*.gcda
./$(TARGET) | grep Tests -A1
cd $(BUILD_DIR) && \
gcov unity.c | head -3
uncovered:
grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
test: CFLAGS += -Wbad-function-cast -Wcast-qual -Wconversion -Wformat=2 -Wold-style-definition \
-Wpointer-arith -Wshadow -Wstrict-overflow=5 -Wstrict-prototypes -Wswitch-default -Wundef \
-Wunreachable-code -Wunused -fstrict-aliasing
test: $(BUILD_DIR)/testunityRunner.c
$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET)
./$(TARGET)
$(BUILD_DIR)/testunityRunner.c: tests/testunity.c | $(BUILD_DIR)
awk $(AWK_SCRIPT) tests/testunity.c > $@
AWK_SCRIPT='/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0 } \
END{ print "\#include \"unity.h\" //Autogenerated by awk in Makefile" ; \
for (i=0; i<d; i++) { print declarations[i] ";" } \
printf "int main()\n{\n UNITY_BEGIN();\n" ; \
for (i=0; i<t; i++) { print " RUN_TEST(" tests[i] ");" } \
printf " return UNITY_END();\n}\n" }'
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean:
rm -f $(BUILD_DIR)/$(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/testunityRunner.c