Correct testing method and documentation

This commit is contained in:
Miroslav Vasilev 2025-03-18 23:19:43 +02:00
parent 4ec217f145
commit 888a87ab86
Signed by: mvv
GPG key ID: 92BACFBE98721A3F
2 changed files with 8 additions and 17 deletions

View file

@ -3,11 +3,9 @@ pushd $(dirname "$0")/.. # run from root dir
rm -rf ./coverage
mkdir ./coverage/
go build -cover -o target/pilgrim_coverage main.go
chmod 777 ./target/pilgrim_coverage
GOCOVERDIR=coverage ./target/pilgrim_coverage
go test --cover -coverpkg=./internal/pilgrim... -covermode=count -coverprofile=./coverage/cover.out ./...
go tool covdata percent -i=coverage
go tool cover -html=./coverage/cover.out
popd # switch back to dir we started from

View file

@ -22,25 +22,18 @@ $ go test ./...
### Coverage
To calculate test coverage, you have to build a special coverage binary and
execute it. To do this, run the following in the root directory:
To calculate test coverage, you have to run `go test` with `--cover`:
```bash
$ go build -cover -o target/pilgrim_coverage main.go
$ go test --cover -coverpkg=./internal/pilgrim... -covermode=count -coverprofile=./coverage/cover.out ./...
```
To calculate the coverage, execute the binary. You must setup the `GOCOVERDIR`
environment variable in order to instruct the go coverage tool where to place
the coverage data. The standard place for this in `pilgrim` is `coverage`:
```bash
$ chmod 777 ./target/pilgrim_coverage
$ GOCOVERDIR=coverage ./target/pilgrim_coverage
```
We only care about packages whose name starts with `pilgrim`. The rest are
ignored.
This will produce several files containing the coverage data. To turn this into
a human-readable format, use the go coverage tool:
To display the coverage report, use the `cover` tool:
```bash
$ go tool covdata percent -i=coverage
$ go tool cover -html=./coverage/cover.out
```
Alternatively, run the `test_coverage.sh` script inside the `bin` directory: