goldens

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 7 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 goldens compares rendered images with the golden PNGs of a package's tests.

A golden lives in the testdata/goldens directory of the package under test. On a mismatch Check writes the image it got and a picture of the differences beside the golden, as <name>.actual.png and <name>.diff.png. Running the tests with -update-goldens rewrites the goldens; every changed one must be looked at before it is committed.

Flutter: flutter_test/lib/src/goldens.dart

Index

Constants

View Source
const DefaultTolerance = 2

DefaultTolerance is the largest difference in one channel of one pixel, out of 255, that Check accepts. It absorbs the float rounding of different processors.

View Source
const TagGoldenMissing = "GoldenMissing"

TagGoldenMissing is the tag of the error of a golden image that does not exist (ReadPNG).

Flutter: no counterpart

Variables

This section is empty.

Functions

func Check

func Check(t testingT, name string, img image.Image)

Check compares img with testdata/goldens/<name>.png, with DefaultTolerance.

Flutter: flutter_test/lib/src/matchers.dart matchesGoldenFile

func CheckTolerance

func CheckTolerance(t testingT, name string, img image.Image, tolerance int)

CheckTolerance is Check with an explicit tolerance for each channel of each pixel.

Flutter: flutter_test/lib/src/matchers.dart matchesGoldenFile

func ReadPNG

func ReadPNG(path string) (*image.RGBA, error)

ReadPNG loads a PNG file as premultiplied RGBA. A missing file is the error GoldenMissing.

Flutter: no counterpart

func WritePNG

func WritePNG(path string, img *image.RGBA) error

WritePNG saves an image as a PNG file, creating the directories.

Flutter: no counterpart

Types

type Result

type Result struct {
	// SizeMismatch says that the images have different sizes; nothing else is
	// set then.
	SizeMismatch bool
	// Pixels is the number of pixels with a channel that differs by more than
	// the tolerance.
	Pixels int
	// MaxDiff is the largest difference of any channel of any pixel.
	MaxDiff int
	// Diff shows the pixels that differ more than the tolerance in red over a
	// faded copy of the golden; nil if the images match.
	Diff *image.RGBA
}

Result is the outcome of comparing two images.

Flutter: flutter_test/lib/src/goldens.dart ComparisonResult

func Compare

func Compare(want, got *image.RGBA, tolerance int) Result

Compare compares two images pixel by pixel; a channel may differ by up to tolerance.

Flutter: flutter_test/lib/src/goldens.dart GoldenFileComparator.compare

func (Result) OK

func (r Result) OK() bool

OK says that the images match.

Jump to

Keyboard shortcuts

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