Skip to content

Commit fe02a62

Browse files
authored
Merge pull request #6 from jay-tux/coverage
Coverage
2 parents 45a1eb5 + 9a0d513 commit fe02a62

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ docs/*
22
test/obj/*
33
test/bin/*
44
test/conan/*
5+
cov/*
56

67
!**/.gitkeep
78

89
compile_flags.txt
10+
coverage.info

Makefile

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ TEST_DIR=$(abspath ./test/src/)
66
INSTALL_DIR=/usr/include/fpgen
77
INCL_PATH=$(abspath ./inc)
88
DOC_DIR=$(abspath ./docs/)
9+
HTMLDIR=$(abspath ./cov/)
10+
BROWSER=firefox
911

1012
CC=g++
11-
CXXARGS=-I$(abspath ./inc) -g -c -std=c++20 -MMD
12-
LDARGS=
13+
CXXARGS=-I$(abspath ./inc) -g -c -std=c++20 -MMD -fprofile-arcs -ftest-coverage
14+
LDARGS=-fprofile-arcs -ftest-coverage
1315

1416
all:
1517
@echo "Please choose a target:"
@@ -18,22 +20,27 @@ all:
1820
@echo " -> make docs: generates the documentation using doxygen under $(DOC_DIR)"
1921
@echo " -> make test: builds and runs the tests in $(BUILD_DIR) and $(BIN_DIR) from $(TEST_DIR)"
2022
@echo " -> make clean: cleans up test builds and documentation (from $(BUILD_DIR), $(BIN_DIR), $(DOC_DIR))"
23+
@echo " -> make coverage: builds and runs the tests, then generates a coverage report in $(HTMLDIR) and opens it in $(BROWSER)"
2124
@echo ""
2225
@echo "Some targets accept additional arguments in the form of KEY=VALUE pairs:"
23-
@echo " -> CC (for test): sets the command for the C++ compiler (g++ by default)"
24-
@echo " -> CXXARGS (for test): current arguments to the compiler - not recommended to change"
25-
@echo " -> EXTRA_CXX (for test): additional compilation flags/arguments"
26-
@echo " -> LDARGS (for test): current arguments to the linker - not recommended to change"
27-
@echo " -> EXTRA_LD (for test): additional linker flags/arguments"
28-
@echo " -> BUILD_DIR (for test): build directory"
29-
@echo " -> BIN_DIR (for test): binary directory"
30-
@echo " -> TEST_DIR (for test): test sources directory"
26+
@echo " -> CC (for test and coverage): sets the command for the C++ compiler (g++ by default)"
27+
@echo " -> CXXARGS (for test and coverage): current arguments to the compiler - not recommended to change"
28+
@echo " -> EXTRA_CXX (for test and coverage): additional compilation flags/arguments"
29+
@echo " -> LDARGS (for test and coverage): current arguments to the linker - not recommended to change"
30+
@echo " -> EXTRA_LD (for test and coverage): additional linker flags/arguments"
31+
@echo " -> BUILD_DIR (for test and coverage): build directory"
32+
@echo " -> BIN_DIR (for test and coverage): binary directory"
33+
@echo " -> TEST_DIR (for test and coverage): test sources directory"
3134
@echo " -> INSTALL_DIR (for install and uninstall): sets the installation directory"
32-
@echo " -> INCL_PATH (for install, docs and test): the path to the directory with the headers, if you run make from another directory"
35+
@echo " -> INCL_PATH (for install, docs, test and coverage): the path to the directory with the headers, if you run make from another directory"
3336
@echo " -> DOC_DIR (for docs): the path to the build directory for the documentation"
37+
@echo " -> BROWSER (for coverage): the browser in which to open the coverage report"
38+
@echo " -> HTMLDIR (for coverage): the directory in which to generate the coverage report"
3439
@echo " Current/default arguments: "
3540
@echo " CC=$(CC) CXXARGS=$(CXXARGS) LDARGS=$(LDARGS) EXTRA_CXX=$(EXTRA_CXX) EXTRA_LD=$(EXTRA_LD)"
3641
@echo " BUILD_DIR=$(BUILD_DIR) BIN_DIR=$(BIN_DIR) TEST_DIR=$(TEST_DIR) INSTALL_DIR=$(INSTALL_DIR) INCL_PATH=$(INCL_PATH) DOC_DIR=$(DOC_DIR)"
42+
@echo " BROWSER=$(BROWSER) HTMLDIR=$(HTMLDIR)"
43+
@echo ""
3744

3845
install:
3946
([ ! -d $(INSTALL_DIR) ] && mkdir -p $(INSTALL_DIR)) || true
@@ -53,4 +60,10 @@ clean:
5360
rm -rf $(DOC_DIR)/*
5461
cd $(TEST_DIR)/.. && make clean OBJD="$(BUILD_DIR)" BIND="$(BIN_DIR)" SRCD="$(TEST_DIR)"
5562

56-
.PHONY: install uninstall test clean docs
63+
coverage:
64+
make CC="$(CC)" OBJD="$(BUILD_DIR)" BIND="$(BIN_DIR)" SRCD="$(TEST_DIR)" CXXARGS="$(CXXARGS) $(EXTRA_CXX) -I$(INCL_PATH)" LDARGS="$(LDARGS) $(EXTRA_LD)" -C $(TEST_DIR)/..
65+
lcov --directory "$(BUILD_DIR)" --output-file coverage.info -c --exclude '*gmock' --exclude '*gtest*' --exclude '/usr/*'
66+
genhtml coverage.info --output-directory "$(HTMLDIR)"
67+
$(BROWSER) $(HTMLDIR)/index.html
68+
69+
.PHONY: install uninstall test clean docs coverage

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# fpgen
2-
*Functional programming in C++ using C++20 coroutines*
2+
*Functional programming in C++ using C++20 coroutines*
3+
![](https://img.shields.io/badge/test_coverage-98%25-brightgreen)
4+
35

46
## Aim
57
`fpgen` aims to bring you an easy-to-use framework for stream programming in C++. Generators can be created, manipulated and lazily aggregated at will using a set of simple functions. Iterators over the generator make it easy to iterate over lazy functions.
@@ -28,4 +30,4 @@ Got another idea? Drop a feature request on the repo.
2830
## Requirements
2931
This project strongly depends on C++20. For an optimal experience, I recommend GCC version 11.2 or greater.
3032
For the tests, we rely on Google Test via the Conan package manager, so make sure you have that installed as well.
31-
To generate coverage reports, we require `gcov`, `lcov` and `genhtml`.
33+
To generate coverage reports, we require `gcov`, `lcov` and `genhtml`.

cov/.gitkeep

Whitespace-only changes.

test/src/test_sources.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ TEST(sources, from_set) {
2929
}
3030

3131
TEST(sources, enumerate_vector) {
32-
std::vector<char> values = { 'a', 'c', 'e', 'k', 'j', 't' };
32+
std::vector<char> values = {'a', 'c', 'e', 'k', 'j', 't'};
3333
size_t prev = 0;
34-
for(auto v : fpgen::enumerate(values)) {
34+
for (auto v : fpgen::enumerate(values)) {
3535
EXPECT_EQ(std::get<0>(v), prev);
3636
EXPECT_EQ(values[prev], std::get<1>(v));
3737
prev++;

0 commit comments

Comments
 (0)