Documentation
¶
Overview ¶
Package golden compares rendered pixels against committed PNG snapshots ("goldens"), so render-level tests can assert byte-stable output on any machine. Snapshots are produced from the bundled fixture font (see render/golden.go), so nothing depends on the host's installed fonts and there is no skip path: a golden run renders the same pixels everywhere.
Policy:
- A golden compares exact-equal by default, pixel for pixel and channel for channel, in the straight-alpha NRGBA form PNG stores. The deterministic font plus the fixed rasterizer make exact equality the normal state, not an aspiration.
- Tolerance relaxes equality for deliberately fuzzy comparisons: a pixel matches when every channel differs by at most Tolerance.ChannelDiff, and the test still passes when at most Tolerance.MaxMismatch pixels exceed that. Use it sparingly; every snapshot in the tree today is exact.
- A reference (Reference) is an image another renderer produced, the independent truth a renderer is held to. Anti-aliasing never agrees byte for byte across renderers, so references compare within a Tolerance, and UPDATE_GOLDEN never rewrites them.
- A test FAILS when its golden is missing. New widgets must land with their snapshots, otherwise the golden net has a hole nobody notices until it misses a real regression.
- Running with UPDATE_GOLDEN=1 in the environment rewrites every golden the run touches instead of comparing (missing ones are simply written), which is also how the missing-golden failure is resolved. After a deliberate visual change, regenerate and review the diff: `UPDATE_GOLDEN=1 go test ./render ./widget`, then `git diff -- '*testdata/golden*'`. The regeneration round-trip must leave the tree unchanged when nothing changed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check compares img against dir/name.png. It Fatalf's on any mismatch: missing golden, dimension drift, or pixels outside tol. With UPDATE_GOLDEN=1 it writes the golden instead and passes.
func Reference ¶
Reference compares img against the image at path that another renderer produced, the independent truth img is held to. Unlike a golden, UPDATE_GOLDEN never rewrites it: the code under test cannot produce its own reference. Pixels compare premultiplied, since a nearly transparent pixel's straight color is noise between renderers.
Types ¶
type TB ¶
TB is the subset of testing.TB the harness needs, so this package stays importable from non-test code and test doubles.
type Tolerance ¶
type Tolerance struct {
// ChannelDiff is the largest per-channel absolute difference
// (0-255) a pixel may show and still match.
ChannelDiff uint8
// MaxMismatch is how many pixels may exceed ChannelDiff before the
// comparison fails.
MaxMismatch int
}
Tolerance relaxes the default exact-equality comparison. The zero value demands byte-identical pixels.