Skip to content

Commit 55f376c

Browse files
committed
Makefile: add gocover target
1 parent 523b277 commit 55f376c

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ test_all:
5454
test_all_libsqlite3:
5555
@GOEXPERIMENT=cgocheck2 go test -tags "$(ALL_TEST_TAGS_JOINED),libsqlite3" -v
5656

57+
# Run tests with coverages then display in browser, if possible.
58+
.PHONY: cover
59+
cover:
60+
@./scripts/gocover.bash -tags "$(ALL_TEST_TAGS_JOINED)"
61+
62+
# Run tests with coverages then display in browser, if possible.
63+
.PHONY: cover_libsqlite3
64+
cover_libsqlite3:
65+
@./scripts/gocover.bash -tags "$(ALL_TEST_TAGS_JOINED),libsqlite3"
66+
5767
.PHONY: qtest
5868
qtest:
5969
@GOEXPERIMENT=cgocheck2 go test -tags "libsqlite3"

scripts/gocover.bash

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
# run coverage tests on the current Go package
6+
function gocover() {
7+
local exit_code=0
8+
local tmpfile
9+
tmpfile="$(mktemp -t 'gocover')" || return 1
10+
go test -covermode=atomic -coverprofile="${tmpfile}" "$@" || {
11+
exit_code=1
12+
}
13+
go tool cover -html="${tmpfile}" || {
14+
rm "${tmpfile}"
15+
exit_code=1
16+
}
17+
return $exit_code
18+
}
19+
20+
gocover "$@"

0 commit comments

Comments
 (0)