Documentation
¶
Overview ¶
Package testshape checks that every test marks its Arrange, Act and Assert, and that each Assert reaches a failure. CLAUDE.md's TDD process section holds the rules; cmd/testshape runs this over a package's test files.
It reads syntax alone, without type checking: test values are recognized by their declared types, and helpers by name within the package. That is enough here, because thelper fixes what a test's parameter is called, and it keeps the check to the standard library. A helper method is picked by its receiver's type where syntax shows that type (a composite literal, new, a call of one of the package's functions, or a name declared with one of those or with a type), and otherwise by name while every method of the name agrees on whether it asserts; where they disagree, the call is reported. A function literal stored under a name counts where that name is called, handed to a call or set in a composite literal, and a subtest sees the closures declared around it but none a sibling subtest declares.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run checks the packages of the named test files, each package once and whole, since a helper in one file decides whether an Assert in another reaches a failure. It prints each violation to stderr and returns 1 when there are any, 0 when there are none, and 2 when it cannot check what it was given.
Types ¶
type Rule ¶
type Rule string
Rule names what a test body got wrong.
const ( MissingMarkers Rule = "missing-markers" CodeBeforeMarker Rule = "code-before-marker" MalformedMarker Rule = "malformed-marker" MarkerPlacement Rule = "marker-placement" MarkerOrder Rule = "marker-order" EmptySection Rule = "empty-section" LabelRequired Rule = "label-required" LabelUnexpected Rule = "label-unexpected" AssertWithoutFailure Rule = "assert-without-failure" AmbiguousHelper Rule = "ambiguous-helper" SubtestLiteral Rule = "subtest-literal" TableMarker Rule = "table-marker" TableAssertion Rule = "table-assertion" )
The rules a test body is held to.
type Violation ¶
type Violation struct {
Position token.Position
// Test is the top-level test the body belongs to, including for a subtest.
Test string
Rule Rule
Message string
}
Violation is one broken rule, and how to fix it.