summaryrefslogtreecommitdiffhomepage
path: root/tests/Makefile
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-05 10:37:41 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-05 10:37:41 +0100
commit0f2ac0c4311e4429bfa4ede1d96ce467b5dceb5b (patch)
treeb4dbe07617ca818b182a18f27d0d4e6bafc91841 /tests/Makefile
parent0c0d858e4f9423fb9697bad9a012cb67fcee75e0 (diff)
Added tests
Diffstat (limited to 'tests/Makefile')
-rw-r--r--tests/Makefile87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..44f50dc
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,87 @@
+CXXFLAGS=-g -O0
+
+include ../common.mk
+
+ifeq ($(CXXTYPE),clang++)
+CXXFLAGS+=-fprofile-instr-generate -fcoverage-mapping
+LDFLAGS+=-fprofile-instr-generate -fcoverage-mapping
+else
+# GCC
+CXXFLAGS+=--coverage
+LDFLAGS+=--coverage
+endif
+
+UNITS=\
+ base64.cpp \
+ file.cpp \
+ mime.cpp \
+ os.cpp \
+ stringhelper.cpp \
+ tempfile.cpp \
+ url.cpp
+
+UNITTESTS=\
+ test-base64.cpp \
+ test-file.cpp \
+ test-mime.cpp \
+ test-os.cpp \
+ test-stringhelper.cpp \
+ test-tempfile.cpp \
+ test-url.cpp
+
+CXXFLAGS+=\
+ -I/usr/src/googletest/googletest/include \
+ -I/usr/src/googletest/googlemock/include \
+ -I/usr/src/googletest/googletest \
+ -I/usr/src/googletest/googlemock \
+ -I..
+
+test: unittests
+ # https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
+ifeq ($(CXXTYPE),clang++)
+ LLVM_PROFILE_FILE="unittests.profraw" ./unittests
+ $(LLVMPROFDATA) merge -sparse unittests.profraw -o unittests.profdata
+ $(LLVMCOV) report --ignore-filename-regex='google' --ignore-filename-regex='test-' --ignore-filename-regex='Magick' --show-region-summary=0 -instr-profile unittests.profdata unittests
+else
+ ./unittests
+ gcovr -r ..
+endif
+
+coverage:
+ $(LLVMCOV) show -instr-profile unittests.profdata $(UNITS:.cpp=.o)
+
+unittests: libgmock.a $(UNITTESTS:.cpp=.o) $(UNITS:.cpp=.o)
+ $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+base64.o: ../base64.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+file.o: ../file.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+mime.o: ../mime.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+os.o: ../os.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+stringhelper.o: ../stringhelper.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+tempfile.o: ../tempfile.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+url.o: ../url.cpp
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+libgmock.a:
+ $(CXX) $(CXXFLAGS) -c /usr/src/googletest/googletest/src/gtest-all.cc
+ $(CXX) $(CXXFLAGS) -c /usr/src/googletest/googlemock/src/gmock-all.cc
+ $(CXX) $(CXXFLAGS) -c /usr/src/googletest/googlemock/src/gmock_main.cc
+ ar -rv libgmock.a gmock-all.o gtest-all.o gmock_main.o
+
+clean:
+ -rm -f *.o *.a unittests *.gcda *.gcno *.profraw *.profdata *.gcov