mirror of https://github.com/go-python/gopy.git
gopy: add test for gofmt'd code
This commit is contained in:
parent
d8d6050a7f
commit
7c437e90f3
29
main_test.go
29
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
|
||||
|
|
Loading…
Reference in New Issue