summaryrefslogtreecommitdiffhomepage
path: root/tests/Makefile
blob: e36198ba302bb2f2dc71c0b2a9ba6b2f3ad281ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
CXXFLAGS=-g -O0

ifeq ($(CXX),clang++-14)
CXXFLAGS+=-fprofile-instr-generate -fcoverage-mapping
else
# GCC
CXXFLAGS+=--coverage
endif

include ../common.mk

LDFLAGS+=-fprofile-instr-generate -fcoverage-mapping

UNITS=storage.cpp config.cpp file.cpp compiledsql.cpp qrcode.cpp whiteboard.cpp

UNITTESTS=test-config.cpp \
	  test-storage.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 ($(CXX),clang++-14)
	LLVM_PROFILE_FILE="unittests.profraw" ./unittests
	llvm-profdata-14 merge -sparse unittests.profraw -o unittests.profdata
	llvm-cov-14 report --ignore-filename-regex='google' --ignore-filename-regex='test-' --show-region-summary=0 -instr-profile unittests.profdata unittests
endif

coverage:
	llvm-cov-14 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 $<

config.o: ../config.cpp
	$(CXX) $(CXXFLAGS) -o $@ -c $<

file.o: ../file.cpp
	$(CXX) $(CXXFLAGS) -o $@ -c $<

storage.o: ../storage.cpp
	$(CXX) $(CXXFLAGS) -o $@ -c $<

compiledsql.o: ../compiledsql.cpp
	$(CXX) $(CXXFLAGS) -o $@ -c $<

whiteboard.o: ../whiteboard.cpp
	$(CXX) $(CXXFLAGS) -o $@ -c $<

qrcode.o: ../qrcode.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 *.gcno *.profraw *.profdata