gopy: add test for gofmt'd code

This commit is contained in:
Sebastien Binet 2017-06-08 14:24:20 +02:00
parent d8d6050a7f
commit 7c437e90f3
1 changed files with 29 additions and 0 deletions

View File

@ -14,6 +14,35 @@ import (
"testing"
)
func TestGofmt(t *testing.T) {
exe, err := exec.LookPath("goimports")
if err != nil {
switch e := err.(type) {
case *exec.Error:
if e.Err == exec.ErrNotFound {
exe, err = exec.LookPath("gofmt")
}
}
}
if err != nil {
t.Fatal(err)
}
cmd := exec.Command(exe, "-d", ".")
buf := new(bytes.Buffer)
cmd.Stdout = buf
cmd.Stderr = buf
err = cmd.Run()
if err != nil {
t.Fatalf("error running %s:\n%s\n%v", exe, string(buf.Bytes()), err)
}
if len(buf.Bytes()) != 0 {
t.Errorf("some files were not gofmt'ed:\n%s\n", string(buf.Bytes()))
}
}
type pkg struct {
path string
want []byte