Documentation
¶
Overview ¶
Package teststyle audits Go tests for declarative style and black-box-by-default package structure.
Index ¶
Constants ¶
const ( RuleNoIf = "teststyle-no-if" RuleNoSwitch = "teststyle-no-switch" RuleNoGoto = "teststyle-no-goto" RuleWhiteBoxFileName = "teststyle-whitebox-filename" RuleWhiteBoxJustification = "teststyle-whitebox-justification" DefaultWhiteBoxJustificationPrefix = "// White-box testing required:" )
Variables ¶
var Analyzer = mustAnalyzer(Config{})
Analyzer is the default go/analysis entrypoint with all rules enabled and no baseline.
var ErrBaselineMismatch = errors.New("teststyle baseline mismatch")
Functions ¶
func NewAnalyzer ¶
NewAnalyzer returns a configured go/analysis analyzer.
func WriteBaseline ¶
WriteBaseline writes a deterministic baseline JSON file.
Types ¶
type Baseline ¶
type Baseline struct {
TestConditionals []ConditionalBaseline `json:"test_conditionals"`
WhiteBoxFiles []WhiteBoxBaseline `json:"white_box_files"`
}
Baseline records known test-style violations. Cleanup PRs should reduce this file; ordinary feature PRs should keep it unchanged.
func ReadBaseline ¶
ReadBaseline reads a baseline JSON file.
func ScanWithConfig ¶
ScanWithConfig scans root with a custom rule configuration.
func (Baseline) HasFinding ¶
HasFinding reports whether finding is recorded in the baseline.
type ConditionalBaseline ¶
type ConditionalBaseline struct {
Path string `json:"path"`
Function string `json:"function"`
Kind string `json:"kind"`
Count int `json:"count"`
}
ConditionalBaseline records prohibited conditional statements in one test function, grouped by statement kind.
type Config ¶
type Config struct {
DisabledRules []string `json:"disabled_rules"`
BaselinePath string `json:"baseline_path"`
Root string `json:"root"`
WhiteBoxJustificationPrefix string `json:"white_box_justification_prefix"`
// SkipExamples exempts parameterless Example* functions from the
// conditional rules. An example is documentation first: the `if err !=
// nil` it shows is often exactly what a reader should copy, so a
// repository can keep examples idiomatic while holding Test* and Fuzz*
// functions declarative. White-box file rules are unaffected, since they
// judge files rather than functions.
SkipExamples bool `json:"skip_examples"`
}
Config controls enabled rules and optional baseline filtering.
type Finding ¶
type Finding struct {
RuleID string
Path string
Line int
Column int
Package string
Function string
Kind string
Reason string
Message string
// contains filtered or unexported fields
}
Finding is a machine-readable test-style violation.
type WhiteBoxBaseline ¶
type WhiteBoxBaseline struct {
Path string `json:"path"`
Package string `json:"package"`
Reason string `json:"reason"`
}
WhiteBoxBaseline records a same-package test file that still needs black-box conversion or an explicit white-box justification.