golden

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 tests 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`, 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

func Check(t TB, dir, name string, img *image.NRGBA, tol Tolerance)

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

func Reference(t TB, path string, img *image.NRGBA, tol Tolerance)

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.

func Update

func Update() bool

Update reports whether the run regenerates goldens instead of comparing: UPDATE_GOLDEN=1 in the environment.

Types

type TB

type TB interface {
	Helper()
	Fatalf(format string, args ...any)
	Logf(format string, args ...any)
}

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.

Jump to

Keyboard shortcuts

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