-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.go
61 lines (49 loc) · 1.14 KB
/
validation.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tempcube
import (
"fmt"
"os"
"path"
"github.com/pkg/errors"
)
func PathList(d, p string) []string {
return []string{
fmt.Sprintf("%s/%s.go", d, p),
fmt.Sprintf("%s/%s_helper.go", d, p),
fmt.Sprintf("%s/%s_test.go", d, p),
fmt.Sprintf("%s/%s_helper_test.go", d, p),
}
}
func Validate(p, sc string) error {
fmt.Println("validate testing...")
_, f := path.Split(p)
pt := "test_" + f
err := Build(p, pt, sc)
if err != nil {
return errors.Wrap(err, "generating code")
}
defer os.RemoveAll(pt)
cmds := PathList(pt, f)
// gofmt
for _, cmd := range cmds {
o, err := Command("go fmt " + cmd)
if err != nil {
return errors.Wrapf(err, "gofmt failed, Out: %s, Error", o)
}
if o != "" && o != cmd {
return errors.Wrapf(err, "gofmt failed, Out: %s, Error", o)
}
}
fmt.Println("... validation test OK")
fmt.Println("testing ...")
// go test
cmd := fmt.Sprintf("cd %s && go test", pt)
o, err := Command(cmd)
if err != nil && o[0:4] != "PASS" {
// there is no test
if o[0:7] != "testing" {
return errors.Wrapf(err, "go test failed, Out: %s, Error", o)
}
}
fmt.Println("... testing OK")
return nil
}