From 66648624b9456259ccb3a3e0b5abba9407a53437 Mon Sep 17 00:00:00 2001 From: kardolus Date: Thu, 7 Nov 2024 09:00:23 +0100 Subject: [PATCH] feat: add coverage command to Makefile --- .gitignore | 1 + Makefile | 5 ++++- scripts/coverage.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 scripts/coverage.sh diff --git a/.gitignore b/.gitignore index 004caf9..de60567 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ bin/ # Compiled binaries *.exe # Windows executables *.out # Output files *.test # Test binaries +coverage.html # Code coverage reports # Logs, Temp Files, & Runtime Data logs/ # Application logs diff --git a/Makefile b/Makefile index eaef0ec..23b975c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Default goal when running `make` .DEFAULT_GOAL := help -.PHONY: help all-tests binaries commit contract install integration reinstall shipit unit updatedeps +.PHONY: help all-tests binaries commit contract coverage install integration reinstall shipit unit updatedeps # Help command to list all available targets help: ## Show this help message @@ -19,6 +19,9 @@ commit: ## Generate a commit message using ChatGPT based on git diff contract: ## Run contract tests ./scripts/contract.sh +coverage: ## Generate a combined coverage report for unit, integration, and contract tests + ./scripts/coverage.sh + install: ## Build the binaries for the specified OS (default: darwin) ./scripts/install.sh $(TARGET_OS) diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100755 index 0000000..ff85d6d --- /dev/null +++ b/scripts/coverage.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$( dirname "${BASH_SOURCE[0]}" )/.." + +# Clean up any previous coverage data +rm -f coverage.out coverage_unit.out coverage_integration.out coverage_contract.out + +# Run Unit Tests with coverage +echo "Run Unit Tests with Coverage" +CONFIG_PATH="file://$PWD" TESTING=true go test -mod=vendor ./... -v -cover -coverpkg=./... -coverprofile=coverage_unit.out -run Unit + +# Run Integration Tests with coverage +echo "Run Integration Tests with Coverage" +CONFIG_PATH="file://$PWD" TESTING=true go test -mod=vendor ./test/... -v -cover -coverpkg=./... -coverprofile=coverage_integration.out -run Integration + +# Run Contract Tests with coverage +echo "Run Contract Tests with Coverage" +CONFIG_PATH="file://$PWD" TESTING=true go test -mod=vendor ./test/... -v -cover -coverpkg=./... -coverprofile=coverage_contract.out -run Contract + +# Merge the coverage profiles +echo "Merging Coverage Profiles" +echo "mode: set" > coverage.out +tail -q -n +2 coverage_unit.out coverage_integration.out coverage_contract.out >> coverage.out || true + +# Generate an HTML report +echo "Generating HTML Coverage Report" +go tool cover -html=coverage.out -o test/coverage.html + +echo -e "\n\033[0;32m** Coverage Report Generated: test/coverage.html **\033[0m" + +rm -f coverage.out coverage_unit.out coverage_integration.out coverage_contract.out