Add -save test flag
This commit is contained in:
parent
eb261f0bd1
commit
7cc16ce8b2
@ -2,12 +2,20 @@ package gg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"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 {
|
func hash(dc *Context) string {
|
||||||
return fmt.Sprintf("%x", md5.Sum(dc.im.Pix))
|
return fmt.Sprintf("%x", md5.Sum(dc.im.Pix))
|
||||||
}
|
}
|
||||||
@ -20,8 +28,11 @@ func checkHash(t *testing.T, dc *Context, expected string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveImage(dc *Context, name string) error {
|
func saveImage(dc *Context, name string) error {
|
||||||
|
if save {
|
||||||
return SavePNG(name+".png", dc.Image())
|
return SavePNG(name+".png", dc.Image())
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestBlank(t *testing.T) {
|
func TestBlank(t *testing.T) {
|
||||||
dc := NewContext(100, 100)
|
dc := NewContext(100, 100)
|
||||||
|
Loading…
Reference in New Issue
Block a user