From b449884c71c44fa636a94fbee4c2e6676cca709f Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 29 Dec 2022 22:20:40 +0100 Subject: [PATCH] add covering rule --- atoi.c | 4 ++-- calc.c | 4 +++- makefile | 24 ++++++++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/atoi.c b/atoi.c index 5547020..50ec270 100644 --- a/atoi.c +++ b/atoi.c @@ -7,7 +7,7 @@ int atoi (char *str) if (*str == '-') { s = 0; - str++; + str++; } while (*str != 0) { @@ -20,4 +20,4 @@ int atoi (char *str) return (s) ? i : -i; } -/* vim: set ts=4 sw=4 et */ +/* vim: set ts=4 sw=4 et: */ diff --git a/calc.c b/calc.c index a26d775..e8c8e5a 100644 --- a/calc.c +++ b/calc.c @@ -129,6 +129,7 @@ int main (int argc, char *argv[]) // test: calc.exe -h // test: calc.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }' +// test: echo 1 | calc.exe -v3 | grep -q value // test: calc.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }' // test: calc.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }' // test: echo "1 + 2" | calc.exe | grep -q '=> 3' @@ -161,6 +162,7 @@ int main (int argc, char *argv[]) // test: echo "2 ^ 3 * 4 + 5" | calc.exe | grep -q '=> 3.7e1' // test: echo "2 + 3 * 4 ^ 5" | calc.exe | grep -q '=> 3.074e3' // test: echo "2 ^ 3 * 4 + cos(5/6)" | calc.exe | grep -q '=> 3.267241e1' -// test: echo "95-6.3*15" | calc.exe | grep -q '=> 4.999971e-1' +// test: echo "95-6.3*15-1" | calc.exe | grep -q '=> -5.000028e-1' +// test: echo "95-6.3+15" | calc.exe | grep -q '=> 1.037e2' /* vim: set ts=4 sw=4 et: */ diff --git a/makefile b/makefile index 674c73f..0f6cb9b 100644 --- a/makefile +++ b/makefile @@ -11,7 +11,7 @@ OFLAGS = -O4 -Os #OFLAGS += -malign-double CFLAGS += -W -Wall -Wextra -g CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 -CFLAGS += $(OFLAGS) $(INCLUDES) +CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOVER) LDFLAGS += -g # Targets @@ -43,8 +43,6 @@ VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, F all: depends $(MAKE) $(ALLEXE:%=%.exe) -depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) - count: wc $(wildcard *.c *.h) $(MAKEFILE_LIST) @@ -54,20 +52,34 @@ clean: rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_*) $(call PASS, SUCCESS) +depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) + +gcovs: + $(MAKE) $(addprefix gcov_,$(ALLEXE)) + purge: clean $(call TITLE, "Purging") touch purge - rm -f purge $(ALLEXE) $(shell [ -f .targets ] && { cat .targets | sort | uniq; echo .targets; }) + rm -f purge $(ALLEXE:%=%.exe) $(shell [ -f .targets ] && { cat .targets | sort | uniq; echo .targets; }) $(call PASS, SUCCESS) tests: all - $(MAKE) $(addprefix test_,$(ALLEXE:%.exe=%)) + $(MAKE) $(addprefix test_,$(ALLEXE)) ## Main rules include $(wildcard *.d) include $(wildcard *.ld) +gcov_%: + make purge + CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs -ftest-coverage" make + make test_$(@:gcov_%=%) + gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)` + touch gcov + rm -f gcov $(wildcard *.gcda *.gcno) + make purge + %.test: %.c $(call TITLE, "Building $@") # awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@ @@ -114,7 +126,7 @@ valgrind_%: % ## Phony -.PHONY: clean count purge +.PHONY: all clean count depends gcovs purge tests ## Precious -- 2.30.2