diff --git a/main_test.go b/main_test.go index 755beac..47d91c1 100644 --- a/main_test.go +++ b/main_test.go @@ -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