forked from go-hep/hep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhep_test.go
More file actions
40 lines (34 loc) · 776 Bytes
/
hep_test.go
File metadata and controls
40 lines (34 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright ©2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hep
import (
"bytes"
"os/exec"
"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, buf.String(), err)
}
if len(buf.Bytes()) != 0 {
t.Fatalf("some files were not gofmt'ed:\n%s\n", buf.String())
}
}