build: add a make cover target for per-function coverage (closes #17)

make cover writes build/coverage.out and prints the per-function report;
make cover-html renders the same profile to build/coverage.html. The
per-package percentage make test prints cannot say which function is
untested.

Both write files, so neither is in check, and neither may be added to it:
check must not modify the working tree. Their output lands under the
already-ignored build/.

Verified: make cover printed per-function lines and a 62.6% total,
make cover-html wrote build/coverage.html, and git status stayed clean.
GOFLAGS=-count=1 make check green in 24s with the lint layer executing
(12.0s, "0 issues.", not CACHED) and the suite running for real (cmd/rogue
1.037s, game 3.410s); check is still fmt-check lint test and git status is
clean afterwards.
This commit is contained in:
2026-08-10 13:48:52 +00:00
parent 60442ce103
commit e3ab4aba8b
3 changed files with 30 additions and 3 deletions

View File

@@ -14,8 +14,10 @@ PRETTIER := prettier --tab-width 4 --prose-wrap always
# git-ignored. Targets that write outside it can commit their output. # git-ignored. Targets that write outside it can commit their output.
BUILD_DIR := build BUILD_DIR := build
BIN := $(BUILD_DIR)/rogue BIN := $(BUILD_DIR)/rogue
COVERPROF := $(BUILD_DIR)/coverage.out
COVERHTML := $(BUILD_DIR)/coverage.html
.PHONY: build check fmt fmt-check lint test .PHONY: build check cover cover-html fmt fmt-check lint test
# Format, lint, and test — the full local pre-commit gate. Keep this list # Format, lint, and test — the full local pre-commit gate. Keep this list
# to targets that write nothing into the working tree. # to targets that write nothing into the working tree.
@@ -27,6 +29,19 @@ build:
@mkdir -p $(BUILD_DIR) @mkdir -p $(BUILD_DIR)
go build -o $(BIN) ./cmd/rogue go build -o $(BIN) ./cmd/rogue
# Per-function coverage, for finding which functions are untested. The
# percentage `make test` prints is a per-package total and cannot answer
# that. Writes files, so it stays out of `check`.
cover:
@mkdir -p $(BUILD_DIR)
go test -timeout 30s -coverprofile=$(COVERPROF) $(GO_PKGS)
go tool cover -func=$(COVERPROF)
# Render the same profile as annotated source.
cover-html: cover
go tool cover -html=$(COVERPROF) -o $(COVERHTML)
@echo "wrote $(COVERHTML)"
# Format Go and Markdown in place. # Format Go and Markdown in place.
fmt: fmt:
gofmt -w . gofmt -w .

View File

@@ -80,8 +80,10 @@ For development, the `Makefile` wraps the toolchain: `make fmt` (gofmt +
prettier), `make lint` (`script/lint`, which runs golangci-lint inside the prettier), `make lint` (`script/lint`, which runs golangci-lint inside the
pinned container built from `Dockerfile.lint` — it is never installed on the pinned container built from `Dockerfile.lint` — it is never installed on the
host, so docker is required), `make test` (the suite, under the race detector host, so docker is required), `make test` (the suite, under the race detector
with coverage and a timeout), `make check` (all three), and `make build` (the with coverage and a timeout), `make check` (all three), `make build` (the
executable, into the git-ignored `build/`). Use the targets rather than the executable), and `make cover` / `make cover-html` (per-function coverage, and
the same profile as annotated source at `build/coverage.html`). Everything they
generate lands in the git-ignored `build/`. Use the targets rather than the
toolchain directly — they carry the flags the project relies on. toolchain directly — they carry the flags the project relies on.
## License ## License

10
TODO.md
View File

@@ -35,6 +35,16 @@ is finished.
# Completed Steps # Completed Steps
- 2026-08-10 `make cover` added (https://git.eeqj.de/sneak/rgoue/issues/17).
`make cover` writes `build/coverage.out` and prints the per-function report;
`make cover-html` renders the same profile to `build/coverage.html`. The
per-package percentage `make test` prints cannot say _which_ function is
untested, which is how the coverage gaps closed so far had to be found — by
grepping test files for identifiers.
Neither target is in `check`, and neither may be added to it: both write
files, and `make check` must not modify the working tree.
- 2026-08-10 `make build` added (https://git.eeqj.de/sneak/rgoue/issues/19). The - 2026-08-10 `make build` added (https://git.eeqj.de/sneak/rgoue/issues/19). The
executable is built to `build/rogue`; `README.md` no longer contains a raw executable is built to `build/rogue`; `README.md` no longer contains a raw
`go` invocation anywhere. `build` is in neither `check` nor `test` `go` invocation anywhere. `build` is in neither `check` nor `test`