From: James Alan Preiss <jamesalanpreiss@gmail.com>
Date: Tue, 2 Jun 2020 00:27:42 +0000 (-0700)
Subject: gcov coverage, CI, badge
X-Git-Url: https://git.owens.tech/projects.html/projects.html/git?a=commitdiff_plain;h=a50b4d5515c01826020cca1f2531aeb0f8b1166d;p=forks%2Fcmath3d.git

gcov coverage, CI, badge
---

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 43e580d..165ad85 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -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
diff --git a/.gitignore b/.gitignore
index d4b2758..0ec8c16 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile b/Makefile
index 833525a..56b222b 100644
--- 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
diff --git a/README.md b/README.md
index 2397871..108dabd 100644
--- 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.
 
diff --git a/math3d.h b/math3d.h
index 0671d7b..795f302 100644
--- 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)