From 1b3ab926a1a058f780acebd53b37a454fe26fa4b Mon Sep 17 00:00:00 2001 From: jay-tux Date: Wed, 16 Feb 2022 12:29:19 +0100 Subject: [PATCH 1/3] Update gitignore to ignore coverage reports --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d9f9ed5..496097d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,9 @@ docs/* test/obj/* test/bin/* test/conan/* +cov/* !**/.gitkeep compile_flags.txt +coverage.info From b47e6b21b1a550d39552c7437692a44cd6fb0dd4 Mon Sep 17 00:00:00 2001 From: jay-tux Date: Wed, 16 Feb 2022 12:30:56 +0100 Subject: [PATCH 2/3] Coverage target to generate HTML coverage reports --- Makefile | 37 +++++++++++++++++++++++++------------ cov/.gitkeep | 0 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 cov/.gitkeep diff --git a/Makefile b/Makefile index 30ce30a..e49209d 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,12 @@ TEST_DIR=$(abspath ./test/src/) INSTALL_DIR=/usr/include/fpgen INCL_PATH=$(abspath ./inc) DOC_DIR=$(abspath ./docs/) +HTMLDIR=$(abspath ./cov/) +BROWSER=firefox CC=g++ -CXXARGS=-I$(abspath ./inc) -g -c -std=c++20 -MMD -LDARGS= +CXXARGS=-I$(abspath ./inc) -g -c -std=c++20 -MMD -fprofile-arcs -ftest-coverage +LDARGS=-fprofile-arcs -ftest-coverage all: @echo "Please choose a target:" @@ -18,22 +20,27 @@ all: @echo " -> make docs: generates the documentation using doxygen under $(DOC_DIR)" @echo " -> make test: builds and runs the tests in $(BUILD_DIR) and $(BIN_DIR) from $(TEST_DIR)" @echo " -> make clean: cleans up test builds and documentation (from $(BUILD_DIR), $(BIN_DIR), $(DOC_DIR))" + @echo " -> make coverage: builds and runs the tests, then generates a coverage report in $(HTMLDIR) and opens it in $(BROWSER)" @echo "" @echo "Some targets accept additional arguments in the form of KEY=VALUE pairs:" - @echo " -> CC (for test): sets the command for the C++ compiler (g++ by default)" - @echo " -> CXXARGS (for test): current arguments to the compiler - not recommended to change" - @echo " -> EXTRA_CXX (for test): additional compilation flags/arguments" - @echo " -> LDARGS (for test): current arguments to the linker - not recommended to change" - @echo " -> EXTRA_LD (for test): additional linker flags/arguments" - @echo " -> BUILD_DIR (for test): build directory" - @echo " -> BIN_DIR (for test): binary directory" - @echo " -> TEST_DIR (for test): test sources directory" + @echo " -> CC (for test and coverage): sets the command for the C++ compiler (g++ by default)" + @echo " -> CXXARGS (for test and coverage): current arguments to the compiler - not recommended to change" + @echo " -> EXTRA_CXX (for test and coverage): additional compilation flags/arguments" + @echo " -> LDARGS (for test and coverage): current arguments to the linker - not recommended to change" + @echo " -> EXTRA_LD (for test and coverage): additional linker flags/arguments" + @echo " -> BUILD_DIR (for test and coverage): build directory" + @echo " -> BIN_DIR (for test and coverage): binary directory" + @echo " -> TEST_DIR (for test and coverage): test sources directory" @echo " -> INSTALL_DIR (for install and uninstall): sets the installation directory" - @echo " -> INCL_PATH (for install, docs and test): the path to the directory with the headers, if you run make from another directory" + @echo " -> INCL_PATH (for install, docs, test and coverage): the path to the directory with the headers, if you run make from another directory" @echo " -> DOC_DIR (for docs): the path to the build directory for the documentation" + @echo " -> BROWSER (for coverage): the browser in which to open the coverage report" + @echo " -> HTMLDIR (for coverage): the directory in which to generate the coverage report" @echo " Current/default arguments: " @echo " CC=$(CC) CXXARGS=$(CXXARGS) LDARGS=$(LDARGS) EXTRA_CXX=$(EXTRA_CXX) EXTRA_LD=$(EXTRA_LD)" @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)" + @echo " BROWSER=$(BROWSER) HTMLDIR=$(HTMLDIR)" + @echo "" install: ([ ! -d $(INSTALL_DIR) ] && mkdir -p $(INSTALL_DIR)) || true @@ -53,4 +60,10 @@ clean: rm -rf $(DOC_DIR)/* cd $(TEST_DIR)/.. && make clean OBJD="$(BUILD_DIR)" BIND="$(BIN_DIR)" SRCD="$(TEST_DIR)" -.PHONY: install uninstall test clean docs +coverage: + 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)/.. + lcov --directory "$(BUILD_DIR)" --output-file coverage.info -c --exclude '*gmock' --exclude '*gtest*' --exclude '/usr/*' + genhtml coverage.info --output-directory "$(HTMLDIR)" + $(BROWSER) $(HTMLDIR)/index.html + +.PHONY: install uninstall test clean docs coverage diff --git a/cov/.gitkeep b/cov/.gitkeep new file mode 100644 index 0000000..e69de29 From 9a0d513f8dd1fc27e88701d6d8916eaeebfaa1e1 Mon Sep 17 00:00:00 2001 From: jay-tux Date: Wed, 16 Feb 2022 12:33:30 +0100 Subject: [PATCH 3/3] update readme --- README.md | 6 ++++-- test/src/test_sources.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 106b576..d5f44b4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # fpgen -*Functional programming in C++ using C++20 coroutines* +*Functional programming in C++ using C++20 coroutines* +![](https://img.shields.io/badge/test_coverage-98%25-brightgreen) + ## Aim `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. ## Requirements This project strongly depends on C++20. For an optimal experience, I recommend GCC version 11.2 or greater. For the tests, we rely on Google Test via the Conan package manager, so make sure you have that installed as well. -To generate coverage reports, we require `gcov`, `lcov` and `genhtml`. +To generate coverage reports, we require `gcov`, `lcov` and `genhtml`. diff --git a/test/src/test_sources.cpp b/test/src/test_sources.cpp index d27fb1d..0322130 100644 --- a/test/src/test_sources.cpp +++ b/test/src/test_sources.cpp @@ -29,9 +29,9 @@ TEST(sources, from_set) { } TEST(sources, enumerate_vector) { - std::vector values = { 'a', 'c', 'e', 'k', 'j', 't' }; + std::vector values = {'a', 'c', 'e', 'k', 'j', 't'}; size_t prev = 0; - for(auto v : fpgen::enumerate(values)) { + for (auto v : fpgen::enumerate(values)) { EXPECT_EQ(std::get<0>(v), prev); EXPECT_EQ(values[prev], std::get<1>(v)); prev++;