-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhelpers_test.go
62 lines (55 loc) · 1.38 KB
/
helpers_test.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
62
package goof
import (
"os"
"os/exec"
"reflect"
"strings"
"testing"
)
const importPath = "github.com/zeebo/goof"
var troop Troop
type suite struct{}
func Test(t *testing.T) {
// normal test invocations don't come with dwarf info, so we can't actually
// run the tests :(
//
// it's ok. skip it here and hope TestCompile checks it.
if err := troop.check(); err != nil {
t.Log("skipping test due to error:", troop.check())
t.SkipNow()
}
// this way we don't have to remember to add the tests to this function
// to run.
s := reflect.TypeOf(suite{})
for i := 0; i < s.NumMethod(); i++ {
method := s.Method(i)
if !strings.HasPrefix(method.Name, "Test") {
continue
}
t.Run(method.Name[4:], func(t *testing.T) {
method.Func.Call([]reflect.Value{
reflect.ValueOf(suite{}),
reflect.ValueOf(t),
})
})
}
}
// TestCompile tries to actually run the tests on an environment that can
// compile the test. HEH.
func TestCompile(t *testing.T) {
if os.Getenv("GOOF_SKIP_COMPILE") != "" {
t.SkipNow()
}
if err := exec.Command("go", "test", "-c", importPath).Run(); err != nil {
t.Logf("skipping compile test due to error: %v", err)
t.SkipNow()
}
cmd := exec.Command("./goof.test", "-test.v")
cmd.Env = append(cmd.Env, "GOOF_SKIP_COMPILE=true")
output, err := cmd.CombinedOutput()
if err != nil {
t.Logf("%s", output)
t.Fatal(err)
}
t.Log("\n" + string(output))
}