gcov coverage, CI, badge
authorJames Alan Preiss <jamesalanpreiss@gmail.com>
Tue, 2 Jun 2020 00:27:42 +0000 (17:27 -0700)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 00:27:42 +0000 (17:27 -0700)
.github/workflows/test.yml
.gitignore
Makefile
README.md
math3d.h

index 43e580d..165ad85 100644 (file)
@@ -11,3 +11,8 @@ jobs:
       run: make
     - name: test
       run: make test
+    - name: coverage
+      run: |
+        make coverage
+        rm test.c.gcov
+        bash <(curl -s https://codecov.io/bash) -X gcov
index d4b2758..0ec8c16 100644 (file)
@@ -1,5 +1,6 @@
-# test binary
+# test binaries
 test_math3d
+cov_math3d
 
 # Object files
 *.o
@@ -34,3 +35,8 @@ test_math3d
 # Debug files
 *.dSYM/
 *.su
+
+# Gcov output
+*.gcov
+*.gcda
+*.gcno
index 833525a..56b222b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,16 @@
+CFLAGS = -std=c99 -Wall -Wpedantic -Wdouble-promotion
+TESTFLAGS = -DCMATH3D_ASSERTS -g
+
 test_math3d: test.c math3d.h
-       $(CC) -std=c99 -Wall -Wpedantic -Wdouble-promotion -g -o test_math3d test.c -lm
+       $(CC) $(CFLAGS) $(TESTFLAGS) -o test_math3d test.c -lm
+
+coverage:
+       $(CC) $(CFLAGS) $(TESTFLAGS) -DCMATH3D_COVERAGE -fprofile-arcs -ftest-coverage -o cov_math3d test.c -lm -lgcov
+       ./cov_math3d
+       gcov test.c math3d.h
 
 test: ./test_math3d
        ./test_math3d
 
 clean:
-       rm test_math3d
+       rm test_math3d *.gcov *.gcda *.gcno
index 2397871..108dabd 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,3 +1,6 @@
+![](https://github.com/jpreiss/cmath3d/workflows/test/badge.svg)
+![](https://img.shields.io/codecov/c/github/jpreiss/cmath3d)
+
 # cmath3d
 3d math library for C. Vectors, 3x3 matrices, quaternions. 32-bit floats.
 
index 0671d7b..795f302 100644 (file)
--- a/math3d.h
+++ b/math3d.h
@@ -28,6 +28,11 @@ SOFTWARE.
 #include <math.h>
 #include <stdbool.h>
 
+// gcov doesn't work properly if functions are inlined.
+#ifdef CMATH3D_COVERAGE
+#define inline
+#endif
+
 #ifndef M_PI_F
 #define M_PI_F   (3.14159265358979323846f)
 #define M_1_PI_F (0.31830988618379067154f)