diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-31 13:07:40 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-31 13:07:40 -0500 |
| commit | 47ca509e69b6a1472a735a4b9521a952e7434491 (patch) | |
| tree | 9101eb376d233c455f653ad857474b3a0dae767f /languages/go/coverage-makefile.txt | |
| parent | af478a42b18c4d5e0712c4cb43036126d36c56b5 (diff) | |
| download | rulesets-47ca509e69b6a1472a735a4b9521a952e7434491.tar.gz rulesets-47ca509e69b6a1472a735a4b9521a952e7434491.zip | |
feat(go): add coverage-summary as a Go bundle coverage slice
Third language in the coverage-summary fan-out, after Elisp and Python. Same kernel: count every source file on disk that's absent from the coverage profile as 0% and weight the project number by file, so an untested file stays visible instead of being averaged away.
The script at languages/go/claude/scripts/coverage-summary.go parses a cover.out profile, maps each import-path-qualified entry back to an on-disk relative path using the module path from go.mod, and reports a file-weighted number plus the missing files. It's standard library only, so it runs anywhere via go run, and it doesn't reimplement the per-function table that go tool cover -func already prints. I proved it against a real go test -coverprofile run, not just a synthetic fixture, since the Go toolchain is installed here.
Two findings to flag. Modern go test ./... already lists every module package in the profile at 0% even when untested, so for in-module code the missing-file list is usually empty. The detection earns its keep on build-tagged files and dirs outside ./.... And this is a coverage-only slice of a Go bundle that doesn't otherwise exist yet: there's no go.md rule file, so sync-language-bundle.sh can't fingerprint it (detection keys on a bundle's own .claude/rules). The script installs via make install-lang LANG=go but won't be sync-maintained until the Go bundle gets real rules and a CLAUDE.md. Building that out is the natural companion task.
Tests are black-box: a Go test in its own throwaway module runs the script via go run against temp fixtures and checks output, so the shipped script dir stays test-free. They cover missing-file detection, all-tracked, _test.go exclusion, and the missing-report error. make test gained a go test discovery path for languages/*/tests, guarded so environments without Go skip it cleanly.
Diffstat (limited to 'languages/go/coverage-makefile.txt')
| -rw-r--r-- | languages/go/coverage-makefile.txt | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/languages/go/coverage-makefile.txt b/languages/go/coverage-makefile.txt new file mode 100644 index 0000000..7aba9e9 --- /dev/null +++ b/languages/go/coverage-makefile.txt @@ -0,0 +1,43 @@ +# Go coverage — Makefile fragment + setup recommendation +# +# This file is owned by the project, not the rulesets bundle. The bundle never +# edits your Makefile. Copy the two targets below into your own Makefile (and +# adjust the variables at the top), then delete this file or keep it as a note. +# +# What you get: +# make coverage runs the suite with a coverage profile and prints +# `go tool cover -func`'s own per-function table +# make coverage-summary prints a file-weighted project number and every +# source file on disk absent from the profile, at 0%. +# +# Why the summary matters: it weights by file and counts a file absent from the +# profile as 0%, so an untested file stays visible instead of being averaged +# away. Note that modern `go test ./...` already lists every module package in +# the profile (at 0% when untested), so for in-module code the missing-file list +# is usually empty; it earns its keep on files outside the test compilation +# (build-tagged files, a dir not covered by ./...). The summary does not +# reimplement the per-function table — `go tool cover -func` already prints it. +# +# --------------------------------------------------------------------------- +# Prerequisite: none beyond the Go toolchain. `go test -coverprofile` and +# `go tool cover` ship with Go; the summary script is pure standard library. +# --------------------------------------------------------------------------- + +# Variables — adjust to your layout. +GO ?= go +SOURCE_DIR ?= . +COVERAGE_FILE ?= cover.out +# The summary script ships with the bundle under .claude/scripts/ (gitignored). +COVERAGE_SUMMARY ?= .claude/scripts/coverage-summary.go + +coverage: + @$(GO) test ./... -coverprofile=$(COVERAGE_FILE) + @$(GO) tool cover -func=$(COVERAGE_FILE) + @$(MAKE) coverage-summary + +coverage-summary: + @if [ ! -f $(COVERAGE_FILE) ]; then \ + echo "[!] No coverage file at $(COVERAGE_FILE). Run 'make coverage' first."; \ + exit 1; \ + fi + @$(GO) run $(COVERAGE_SUMMARY) $(COVERAGE_FILE) $(SOURCE_DIR) . |
