Skip to content

Commit 3916d42

Browse files
Move unittests into their own file to improve coverage calculations
1 parent 519a622 commit 3916d42

6 files changed

Lines changed: 989 additions & 1027 deletions

File tree

Makefile

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ all: sofos
1515
.PHONY: default all clean
1616

1717
clean:
18-
rm -f sofos sofos_debug sofos_unittest sofos_unittest_coverage sofos_coverage
18+
rm -f sofos sofos_debug unittest unittest_coverage sofos_coverage
1919
rm -f *.gcov *.gcda *.gcno
2020
rm -f coverage*.html
2121
rm -f clang-tidy.txt clang-format.patch
2222

2323
SOFOSCC=sofos.cc main.cc
24+
UNITCC=sofos.cc unittest.cc
2425
SOFOSHPP=sofos.hpp vcf.hpp
2526
FORMATFILES=$(SOFOSCC) $(SOFOSHPP) test_utils.hpp
2627

@@ -30,24 +31,31 @@ sofos: $(SOFOSCC) $(SOFOSHPP)
3031
sofos_debug: $(SOFOSCC) $(SOFOSHPP)
3132
$(CXX) -g -O0 $(SOFOSFLAGS) -o $@ $(SOFOSCC)
3233

33-
sofos_coverage: $(SOFOSCC) $(SOFOSHPP)
34-
$(CXX) -g -O0 $(SOFOSFLAGS) $(GCOVFLAGS) -o $@ $(SOFOSCC)
34+
unittest: $(UNITCC) $(SOFOSHPP)
35+
$(CXX) -g -O0 $(SOFOSFLAGS) -DSOFOS_UNIT_TESTS -o $@ $(UNITCC)
3536

36-
sofos_unittest: $(SOFOSCC) $(SOFOSHPP)
37-
$(CXX) -g -O0 $(SOFOSFLAGS) -DSOFOS_UNIT_TESTS -o $@ $(SOFOSCC)
37+
%_cov.o: %.cc
38+
$(CXX) -c -g -O0 $(SOFOSFLAGS) $(GCOVFLAGS) -o $@ $<
3839

39-
sofos_unittest_coverage: $(SOFOSCC) $(SOFOSHPP)
40-
$(CXX) -g -O0 $(SOFOSFLAGS) $(GCOVFLAGS) -DSOFOS_UNIT_TESTS -o $@ $(SOFOSCC)
40+
sofos_cov.o : $(SOFOSHPP)
4141

42-
test: sofos_unittest sofos_debug
43-
./sofos_unittest
42+
unit_cov.o : $(SOFOSHPP)
43+
44+
sofos_coverage: $(patsubst %.cc,%_cov.o,$(SOFOSCC))
45+
$(CXX) -g -O0 $(SOFOSFLAGS) $(GCOVFLAGS) -o $@ $^
46+
47+
unittest_coverage: $(patsubst %.cc,%_cov.o,$(UNITCC))
48+
$(CXX) -g -O0 $(SOFOSFLAGS) $(GCOVFLAGS) -DSOFOS_UNIT_TESTS -o $@ $^
49+
50+
test: unittest sofos_debug
51+
./unittest
4452
cd test && bash test-01.bash ../sofos_debug
4553

46-
coverage: sofos_coverage sofos_unittest_coverage
54+
coverage: sofos_coverage unittest_coverage
4755
rm -f *.gcda
48-
./sofos_unittest_coverage
56+
./unittest_coverage
4957
cd test && bash test-01.bash ../sofos_coverage
50-
gcovr -r . -e catch.hpp -e test_utils.hpp --html-details -o coverage.html
58+
gcovr -r . -e catch.hpp -e unittest.cc --html-details -o coverage.html
5159

5260
test_codecov: sofos_unittest_coverage sofos_coverage
5361
rm -f *.gcda
@@ -72,4 +80,4 @@ test_tidy:
7280
@$(CLANGTIDY) $(SOFOSCC) -- $(CXXFLAGS) $(SOFOSFLAGS) -Wall 2>/dev/null | tee clang-tidy.txt
7381
@test 0 -eq `cat clang-tidy.txt | wc -l`
7482

75-
.PHONY: coverage tidy format test test_codecov test_format
83+
.PHONY: coverage tidy format test test_codecov test_format cov

main.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
SOFTWARE.
2121
*****************************************************************************/
2222

23-
#ifdef SOFOS_UNIT_TESTS
24-
#define CATCH_CONFIG_MAIN
25-
#include "catch.hpp"
26-
#endif
27-
2823
#include "sofos.hpp"
2924

3025
#include <unistd.h>
@@ -67,7 +62,6 @@ void print_usage(const char* exe, std::ostream& os) {
6762
}
6863

6964
// Main program entry point
70-
#ifndef CATCH_CONFIG_MAIN
7165
int main(int argc, char* argv[]) {
7266
try {
7367
// default parameters
@@ -158,4 +152,3 @@ int main(int argc, char* argv[]) {
158152
}
159153
return EXIT_FAILURE;
160154
}
161-
#endif

0 commit comments

Comments
 (0)