From 7cc16ce8b22ac72102b1ac70f2ecc89e91c7ab24 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Fri, 17 Aug 2018 11:14:38 -0400 Subject: [PATCH] Add -save test flag --- context_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/context_test.go b/context_test.go index 8f8d049..141ef81 100644 --- a/context_test.go +++ b/context_test.go @@ -2,12 +2,20 @@ package gg import ( "crypto/md5" + "flag" "fmt" "image/color" "math/rand" "testing" ) +var save bool + +func init() { + flag.BoolVar(&save, "save", false, "save PNG output for each test case") + flag.Parse() +} + func hash(dc *Context) string { return fmt.Sprintf("%x", md5.Sum(dc.im.Pix)) } @@ -20,7 +28,10 @@ func checkHash(t *testing.T, dc *Context, expected string) { } func saveImage(dc *Context, name string) error { - return SavePNG(name+".png", dc.Image()) + if save { + return SavePNG(name+".png", dc.Image()) + } + return nil } func TestBlank(t *testing.T) {