Skip to content

Commit

Permalink
feat: add coverage command to Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
kardolus committed Nov 7, 2024
1 parent 9132948 commit 6664862
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
32 changes: 32 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6664862

Please sign in to comment.