Skip to content

Commit

Permalink
feat: local coverage report
Browse files Browse the repository at this point in the history
Generate single coverage report for `interchaintest` and
`manifest-ledger`. Generated Protobuf files are excluded from coverage
metric.
  • Loading branch information
fmorency committed Mar 25, 2024
1 parent 412972c commit 0777886
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .coverageignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pb.go
*.pb.gw.go
*.pulsar.go
*_simulation.go
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ endif
.PHONY: get-heighliner local-image

#################
### Build ###
### Test ###
#################

test:
Expand All @@ -141,6 +141,27 @@ test-integration:

.PHONY: test test-integration

#################
### Test ###
#################

coverage: ## Run coverage report
@echo "--> Running coverage"
@go test -race -cpu=$$(nproc) -covermode=atomic -coverprofile=coverage.out $$(go list ./...) ./interchaintest/... -coverpkg=github.com/liftedinit/manifest-ledger/... > /dev/null 2>&1
@echo "--> Running coverage filter"
@./scripts/filter-coverage.sh
@echo "--> Running coverage report"
@go tool cover -func=coverage-filtered.out
@echo "--> Running coverage html"
@go tool cover -html=coverage-filtered.out -o coverage.html
@echo "--> Coverage report available at coverage.html"
@echo "--> Cleaning up coverage files"
@rm coverage.out
@echo "--> Running coverage complete"

.PHONY: coverage


##################
### Protobuf ###
##################
Expand Down
15 changes: 15 additions & 0 deletions scripts/filter-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

coverage_profile="coverage.out"
filtered_coverage_profile="coverage-filtered.out"
exclusion_file=".coverageignore"

cp "$coverage_profile" "$filtered_coverage_profile"

while read -r pattern; do
files_to_exclude=$(find . -type f -regex ".*$pattern")
for file in $files_to_exclude; do
relative_path=$(realpath --relative-to="." "$file")
grep -v "$relative_path" "$filtered_coverage_profile" > temp_coverage.out && mv temp_coverage.out "$filtered_coverage_profile"
done
done < "$exclusion_file"

0 comments on commit 0777886

Please sign in to comment.