Documentation
¶
Overview ¶
Command gotest runs `go test` and refuses to call a selection a pass when part of it selected nothing.
⛔⛔ `ok` IS ABOUT THE TESTS THAT RAN, NOT ABOUT THE ONE YOU ASKED FOR. Measured on 2026-11-09, in go-zpkg/zbk, while checking a README gate:
$ go test -run 'TestREADME|TestUsage|TestMain' ./cmd/zbk ok github.com/go-zpkg/zbk/cmd/zbk 0.159s
The gate was `TestTheREADMECountsTheSubcommandsItHas`, and `TestREADME` matched NOTHING. Three other alternatives did — the same run with -v shows TestMainMultiCallDispatch, TestUsageAndErrors, TestMainSeam and TestRunTestUsage — so the selection was not empty, `go test` had nothing to warn about, and the `ok` was true. The gate had simply not run, and ran red the moment it was named correctly:
39 subcommands, and numberWords does not spell that
⛔ GO ONLY WARNS WHEN THE SELECTION IS WHOLLY EMPTY, and even then it exits 0. Measured the same day:
$ go test -run NoSuchTestNameAtAll ./cmd/covblocks ; echo $? ok …/cmd/covblocks 0.051s [no tests to run] 0
So the information exists in both cases and the VERDICT does not. That is what this adds, and it is the only thing it adds: every argument is passed through to `go test` unchanged.
gotest -run 'TestFoo|TestBar' ./pkg # fails if either matched nothing gotest ./... # no -run: a plain pass-through
⭐ IT CHECKS EACH ALTERNATIVE, not the selection as a whole, because that is where the defect lives: a pattern with four alternatives and one typo reports the three that worked.
⛔ AND IT ADDS -v WHEN IT HAS TO, saying so. The names that ran are only printed by `go test -v`; without it there is nothing to check against, and silently running a different command than the one asked for is worse than the extra output.
Exit status: 0 the selection ran and `go test` passed, 1 an alternative matched no test or `go test` failed, 2 the arguments could not be read.