testverbhelp

package
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testverbhelp is the per-tool check of the verb-help rule (the CLI style's rule (b), #4505; pkg/nsprint/verbflag is the one seam that implements it): `<tool> <verb> -h` and `--help` print that verb's help on stdout and exit 0, with nothing on stderr, no file written and no dial. The check opens no socket: it is a unit-tier check.

Each tool's test names its verbs and, for each, the flags that would point the verb at a place: a path flag gets {dir}/..., a store address gets {addr}. They are given BEFORE -h, so the parser has taken them when it meets -h, and the check then holds that nothing was created under {dir}. {addr} is RefusedAddr, a loopback port nothing listens on: the check owns no socket, and a verb that dials before it answers -h meets a refusal and fails the exit or stderr clause. How long help takes is a performance check, not a unit one: it is held only under -tags perf (budget_perf.go), and the perf job runs it through each tool's perf-only TestEveryVerbsHelpIsWithinTheBudget.

Index

Constants

View Source
const (
	GapUsage       = "usage"
	GapDescription = "description"
	GapExample     = "example"
	GapExitCodes   = "exit-codes"
	// GapFlagPrefix is followed by a flag's name: the flag has no description.
	GapFlagPrefix = "flag-undescribed:"
	// GapMissingPrefix is followed by a flag's name: the refusal names it, -h does not print it.
	GapMissingPrefix = "flag-missing:"
)

Gap names, as the ledger spells them.

View Source
const RefusedAddr = "127.0.0.1:1"

RefusedAddr is what {addr} becomes: loopback port 1, where nothing listens, so a dial is refused at once and the check needs no listener of its own.

View Source
const UnknownFlag = "--no-such-flag-breadcrumb"

UnknownFlag is a flag no verb defines. Every verb that is handed it refuses.

Variables

This section is empty.

Functions

func Check

func Check(t *testing.T, run Run, cases []Case)

Check runs every case with -h and with --help, in parallel subtests.

func Complete

func Complete(t *testing.T, cases []Case, seen []captured)

Complete holds every case's captured help to the rule, against the ledger.

func Completeness

func Completeness(run Run, c Case, dir string) (tool string, gaps []string)

Completeness runs one case with -h, and with an unknown flag to read the set's flags, and returns the verb's tool and gaps.

func Gaps

func Gaps(help, refusal string) []string

Gaps is what the help text lacks of the rule, in the ledger's spelling, sorted. refusal is the stderr of the verb handed UnknownFlag ("" when not known); the flags it lists are the set's.

func HelpVerb

func HelpVerb(t *testing.T, run Run, tool string, verbs ...string)

HelpVerb checks `<tool> help <verb>` for a tool whose help verb takes one: the same help `<verb> -h` prints, on stdout, at exit 0, nothing on stderr.

func Judge

func Judge(key string, gaps, ledgered []string) []string

Judge compares one verb's gaps with its ledger row (nil: none), and returns the problems: a gap not in the ledger, a ledger part already fixed.

func Ledger

func Ledger(text string) (map[string][]string, error)

Ledger is the ledger's rows: "<tool> <verb>" to its gaps. A malformed line is an error.

func LedgerPath

func LedgerPath() string

LedgerPath is the shrink-only ledger, found from this source file.

func One

func One(t *testing.T, run Run, c Case, spelling string)

One runs one case with one spelling of help and asserts the rule.

func Problems

func Problems(run Run, c Case, spelling, dir string) []string

Problems runs one case with one spelling of help, with {dir} as dir, and returns every way it broke the rule; none is a pass.

func RefusalProblems

func RefusalProblems(run Run, c Case, dir string) []string

RefusalProblems runs one case with UnknownFlag and returns every way the refusal broke the rule: a tool or verb never fails silently, and every refusal carries a breadcrumb to the fix. It is the runtime half of internal/ci's remedy and no-ok-on-failure rules, run through the same seam every verb parses its flags with:

  • the exit is not 0: an invocation the verb cannot parse did not succeed;
  • something is said on stderr, and it names the flag or the usage, or a remedy in the house form (oneline.HasRemedy): never silent, and a breadcrumb to the fix;
  • no line on stdout closes with OK: the last word of a failed run is never OK;
  • nothing is written under {dir} and nothing dials: the refusal comes before the work.

Types

type Case

type Case struct {
	Verb  string
	Flags []string
}

Case is one verb ("send", "slots take") and the flags given before -h. "{dir}" and "{addr}" in a flag are replaced by the case's temp directory and RefusedAddr.

type Run

type Run func(args []string, stdout, stderr io.Writer) int

Run is the tool, in process: args after the tool's name, the two streams, the exit code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL