increase test coverage
authorLaurent Mazet <mazet@softndesign.org>
Sun, 15 Jan 2023 22:16:25 +0000 (23:16 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 15 Jan 2023 22:16:25 +0000 (23:16 +0100)
calc.c
makefile

diff --git a/calc.c b/calc.c
index 95eef4ed89131f5e954e2f4d199cbf82177da7fe..f57f1a455dfba634e1ef23971892dd790ed55616 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -147,6 +147,9 @@ int main (int argc, char *argv[])
 // 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: calc.exe error 2>&1 | grep -q 'invalid option'
+// test: calc.exe -p 2>&1 | grep -q 'missing precision'
+// test: calc.exe -v 2>&1 | grep -q 'missing verbose'
 // test: echo "1 + 2" | calc.exe | grep -q '=> 3'
 // test: echo "1 - 2" | calc.exe | grep -q '=> -1'
 // test: echo "2 * 3" | calc.exe | grep -q '=> 6'
@@ -189,5 +192,9 @@ int main (int argc, char *argv[])
 // test: echo "sqrt 2" | calc.exe | grep -q 'error'
 // test: echo "pow (2)" | calc.exe | grep -q 'error'
 // test: echo "1.23456789" | calc.exe -p 3 | grep -q '1\.234'
+// test: echo . | calc.exe
+// test: echo -e '1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1\n1 + 1' | ./calc.exe | grep -q 6.4e1
+// test: echo -e '-cos (1)\n1 + 1\n1 - 1\n1 * 1\n1 / 1\n3%2\n2^2\nsqrt (2)\ncos (0)\nsin (0)\natan (0)\nlog (1)\nexp (1)\nhelp\nquit' | calc.exe -v 3 | grep -q bye
+// test: echo -e '1 +\n1 -\n1 * 1\n1 /\n3%\n2^\nsqrt ()\ncos ()\nsin ()\natan ()\nlog ()\nexp ()\n1 + (' | calc.exe |grep -c error |xargs test 11 =
 
 /* vim: set ts=4 sw=4 et: */
index f5e19b9bf3cf3464218cfbfba33ae02eb6d2366c..08034deb07d4070f32d79d5180237effb6f8b683 100644 (file)
--- a/makefile
+++ b/makefile
@@ -11,8 +11,8 @@ OFLAGS  = -O4 -Os
 #OFLAGS += -malign-double
 CFLAGS += -W -Wall -Wextra -g
 CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
-CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOVER)
-LDFLAGS += -g
+CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOV)
+LDFLAGS += -g $(GCOV)
 
 # Targets
 
@@ -24,6 +24,7 @@ SHELL = bash
 
 #MAKE = mingw32-make
 MAKEFLAGS += -s
+include $(wildcard .makefile)
 
 # Functions
 
@@ -69,7 +70,7 @@ valgrinds:
 wipe: purge
        $(call TITLE, "Wiping")
        touch wipe
-       rm -f wipe $(wildcard *.gcda *.gcno)
+       rm -f wipe $(wildcard *.gcda *.gcno *.gcov)
        $(call PASS, SUCCESS)
 
 tests: all
@@ -82,7 +83,7 @@ include $(wildcard *.ld)
 
 gcov_%:
        $(MAKE) purge
-       CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs -ftest-coverage" $(MAKE)
+       GCOV="-fprofile-arcs -ftest-coverage -O0" $(MAKE)
        $(MAKE) test_$(@:gcov_%=%)
        gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
        touch gcov
@@ -103,7 +104,7 @@ 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_%: %.exe
        VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \