diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 28360e0..df3a7ea 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -19,5 +19,7 @@ jobs: - uses: actions/checkout@v2 - name: Build run: make - - name: Run tests - run: make test + - name: Run tests and produce code coverage + run: make code-coverage + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 diff --git a/.gitignore b/.gitignore index 5317379..e267a44 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,12 @@ *.app # Executable dir -bin/ \ No newline at end of file +bin/ + +# Coverage dir +coverage/ + +# Coverage/profiling artifacts +*.gcda +*.gcno +*.gcov \ No newline at end of file diff --git a/Makefile b/Makefile index c96650e..126a070 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,11 @@ EXAMPLE_DIR = examples CXX_FLAGS = -std=c++17 -Iinclude OUT_DIR = bin +COVERAGE_CXX_FLAGS = -O0 --coverage +COVERAGE_DIR = coverage + +code-coverage: CXX_FLAGS += $(COVERAGE_CXX_FLAGS) + $(TEST_TARGETS): % : $(TEST_DIR)/%.cpp mkdir -p $(OUT_DIR) g++ $(CXX_FLAGS) -o $(OUT_DIR)/$@ $< $(TEST_LIBS) @@ -19,8 +24,15 @@ $(EXAMPLE_TARGETS): % : $(EXAMPLE_DIR)/%.cpp test: $(TEST_TARGETS) ./$(OUT_DIR)/$< +code-coverage: $(TEST_TARGETS) + ./$(OUT_DIR)/$< + mkdir -p $(COVERAGE_DIR) + mv *.gcda *.gcno $(COVERAGE_DIR) + clean: - rm $(addprefix $(OUT_DIR)/, $(TEST_TARGETS)) + rm -f $(addprefix $(OUT_DIR)/, $(TEST_TARGETS)) rmdir --ignore-fail-on-non-empty $(OUT_DIR) - -.PHONY: test clean \ No newline at end of file + rm -f $(addprefix $(COVERAGE_DIR)/, *.gcda *.gcno) + rmdir --ignore-fail-on-non-empty $(COVERAGE_DIR) + +.PHONY: test code-coverage clean diff --git a/README.md b/README.md index 708c55a..b7ec12a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # The minimalist error handling framework +[![codecov](https://codecov.io/gh/vvish/cpp_result/branch/master/graph/badge.svg)](https://codecov.io/gh/vvish/cpp_result) + ## Motivation The framework makes an attempt to provide resource efficient ways to define