Documentation ¶
Overview ¶
Package etch provides a simple facility to write graphical regression tests. The Assertf function provides the common case functionality. Provide it the test variable, along the image you have and want, and it will fail your case if want != have.
Optionally, provide a filename to store the graphical difference as an uncompressed PNG if the test fails.
The Extra data in the image (have but don't want) is represented in Red The Missing data (want, but dont have) is represented in Blue These can be changed by modifying Extra and Missing package variables
To simplify the package, the alpha channel is ignored. A color triplet is equal to another if it's R,G,B values are identical.
The foreground variable, fg, is what to paint on the delta image if two pixels match The background variable, BG, is the common background color between two images
If two pixels at the same (x,y) coordinate don't match, the ambiguity is resolved by comparing the image you have's color value at that coordinate to the background color. If the color matches, the pixel you have is missing. Otherwise, it's extra.
This may seem confusing, so a worked example is made available in the README
Index ¶
- Variables
- func Assert(t *testing.T, have, want image.Image, filename string)
- func AssertFile(t *testing.T, have image.Image, wantfile string, filename string)
- func Assertf(t *testing.T, have, want image.Image, filename string, fm string, ...)
- func Delta(a, b image.Image) (delta *image.RGBA, ok bool)
- func EqualRGB(c0, c1 color.Color) bool
- func ReadFile(t *testing.T, file string) (img image.Image)
- func Report(have, want, delta image.Image) image.Image
- func WriteFile(t *testing.T, file string, img image.Image)
Constants ¶
This section is empty.
Variables ¶
var ( // Colors from as/frame Red = image.NewUniform(color.RGBA{255, 0, 0, 255}) Blue = image.NewUniform(color.RGBA{0, 0, 255, 255}) Black = image.NewUniform(color.RGBA{0, 0, 0, 255}) White = image.NewUniform(color.RGBA{255, 255, 255, 255}) Gray = image.NewUniform(color.RGBA{33, 33, 33, 255}) Peach = image.NewUniform(color.RGBA{255, 248, 232, 255}) // Defaults used by this package // BG should be the similar background color between two images BG = Peach Extra = Red Missing = Blue )
Functions ¶
func Assert ¶
Assert compares two test images and fails the provided test if the images differ at any pixel(x,y). It saves the delta as a png to the given filename (if set) and provides the path to that image in an error string upon failure.
func AssertFile ¶
AssertFile is like assert, but reads the wanted result from the named file
func Assertf ¶
Assertf is like assert, except it logs a custom message with a format string and interface parameter list (like fmt.Printf)
func Delta ¶
Delta computes a difference between image a and b by comparing each pixel to the fg and BG colors. If a pixel in a and b are equal, the delta pixel is fg. Otherwise the pixel is either red or blue depending if its extra or missing respectively.
func ReadFile ¶
ReadFile reads in the named file and returns it as an image.Image. The supported format is an uncompressed PNG.
Types ¶
This section is empty.