increase test coverage
authorLaurent Mazet <mazet@softndesign.org>
Sun, 15 Jan 2023 21:09:47 +0000 (22:09 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 15 Jan 2023 21:09:47 +0000 (22:09 +0100)
ascii.c
atoi.c
makefile

diff --git a/ascii.c b/ascii.c
index c61554b9da2599f62a0b9274b380f1bccd9b5606..dd54596f948c06f00d32bf003b20b149d5ec0db6 100644 (file)
--- a/ascii.c
+++ b/ascii.c
@@ -134,13 +134,16 @@ int main (int argc, char *argv[])
 
 // test: ascii.exe -h
 // test: ascii.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
-// test: ascii.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
+// test: ascii.exe -_ 2>/dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
+// test: ascii.exe error 2>&1 | grep -q 'invalid option'
 // test: ascii.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
 
 // test: ascii.exe | awk '/ 64\[40\] @/ { rc=1 } END { exit (1-rc) }'
 // test: ascii.exe | awk '/127\[7f\] DEL/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe -v | grep -q version
 // test: ascii.exe -c 4 | tail -1 | awk '/63/ { rc=1 } END { exit (1-rc) }'
 // test: ascii.exe -c 5 | tail -1 | awk '/51/ { rc=1 } END { exit (1-rc) }'
 // test: ascii.exe -c 6 | tail -1 | awk '/42/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe -c 2>&1 | grep -q 'missing number of columns'
 
 /* vim: set ts=4 sw=4 et: */
diff --git a/atoi.c b/atoi.c
index 554702086f1139d9787efeb680de4bd182998871..50ec270e617189ed81e267c5814297ff95cfd247 100644 (file)
--- 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: */
index c1855b2b985738dc04413f45a20e6c9b031e1e52..0f8ca5f8f65d9e86bb4d28defccfa5bfd31b6b77 100644 (file)
--- a/makefile
+++ b/makefile
@@ -11,19 +11,20 @@ OFLAGS  = -O4 -Os
 #OFLAGS += -malign-double
 CFLAGS += -W -Wall -Wextra -g
 CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
-CFLAGS += $(OFLAGS) $(INCLUDES)
-LDFLAGS += -g
+CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOV)
+LDFLAGS += -g $(GCOV)
 
 # Targets
 
 ALLEXE  =
 ALLEXE += ascii
-ALLEXE += skel
+#ALLEXE += skel
 
 SHELL = bash
 
-MAKE = mingw32-make
+#MAKE = mingw32-make
 MAKEFLAGS += -s
+include $(wildcard .makefile)
 
 # Functions
 
@@ -43,11 +44,6 @@ VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, F
 all: depends
        $(MAKE) $(ALLEXE:%=%.exe)
 
-alltests: all
-       $(MAKE) $(addprefix test_,$(ALLEXE:%.exe=%))
-
-depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
-
 count:
        wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
 
@@ -57,17 +53,43 @@ 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)
        $(call PASS, SUCCESS)
 
+valgrinds:
+       $(MAKE) $(addprefix valgrind_,$(ALLEXE))
+
+wipe: purge
+       $(call TITLE, "Wiping")
+       touch wipe
+       rm -f wipe $(wildcard *.gcda *.gcno *.gcov)
+       $(call PASS, SUCCESS)
+
+tests: all
+       $(MAKE) $(addprefix test_,$(ALLEXE))
+
 ## Main rules
 
 include $(wildcard *.d)
 include $(wildcard *.ld)
 
+gcov_%:
+       $(MAKE) purge
+       GCOV="-fprofile-arcs -ftest-coverage -O0" $(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 }' $< > $@
@@ -82,12 +104,12 @@ test_%: %.test %.exe
          [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
                        || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
        done; \
-       test "$$RC" -ne 1 
+       test "$$RC" -ne 1
 
-valgrind_%: %
+valgrind_%: %.exe
        VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \
        export VALGRIND; \
-       $(MAKE) test_$<
+       $(MAKE) $(@:valgrind_%=test_%)
 
 %.d: %.c
        $(call TITLE, "Building $@")
@@ -114,7 +136,7 @@ valgrind_%: %
 
 ## Phony
 
-.PHONY: clean count purge
+.PHONY: all clean count depends gcovs purge tests
 
 ## Precious