Skip to content

Commit 7889f8c

Browse files
authored
tests: generate coverage info report (#972)
Adds two toplevel make targets: - make coverage-html: generates out/coverage.html - make coverage-browser: opens a browser page with the coverage report loaded Signed-off-by: Steve Beattie <steve.beattie@chainguard.dev>
1 parent 1971699 commit 7889f8c

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

DEVELOPMENT.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ integration tests:
2727

2828
```make integration```
2929

30+
## Viewing test coverage
31+
32+
Generate an html report in `out/coverage.html`:
33+
34+
```make coverage-html```
35+
36+
Open the coverage report in a browser automatically:
37+
38+
```make coverage-browser```
39+
3040

3141
## Writing rule tests
3242

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ install-yara-x: out/$(YARA_X_REPO)/.git/commit-$(YARA_X_COMMIT)
131131
test:
132132
go test -race ./pkg/...
133133

134+
# unit tests only
135+
.PHONY: coverage
136+
coverage: out/mal.coverage
137+
138+
# generate the html report
139+
.PHONY: coverage-html
140+
coverage-html: out/coverage.html
141+
142+
# pop open the html page in a browser directly
143+
.PHONY: coverage-browser
144+
coverage-browser: out/mal.coverage
145+
go tool cover -html=$<
146+
147+
# generate the html report
148+
out/coverage.html: out/mal.coverage
149+
go tool cover -html=$< -o $@
150+
151+
# we always want to regen the coverage data file
152+
.PHONY: out/mal.coverage
153+
out/mal.coverage:
154+
mkdir -p out
155+
go test -coverprofile $@ -race ./pkg/... -coverpkg ./pkg/...
156+
134157
# integration tests only
135158
.PHONY: integration
136159
integration: out/$(SAMPLES_REPO)/.decompressed-$(SAMPLES_COMMIT)

0 commit comments

Comments
 (0)