-
Notifications
You must be signed in to change notification settings - Fork 249
/
compilation_test.go
84 lines (78 loc) · 1.58 KB
/
compilation_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package daemon
import (
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"testing"
)
func TestCompilation(t *testing.T) {
if testing.Short() {
t.Skip("short mode")
}
if !requireMinor(5) {
t.Skip(runtime.Version(), "cross-compilation requires compiler bootstrapping")
}
pairs := []string{
"darwin/amd64",
"dragonfly/amd64",
"freebsd/386",
"freebsd/amd64",
"freebsd/arm",
"linux/386",
"linux/amd64",
"linux/arm",
"linux/arm64",
"linux/riscv64",
"netbsd/386",
"netbsd/amd64",
"netbsd/arm",
"openbsd/386",
"openbsd/amd64",
"openbsd/arm",
"solaris/amd64",
"windows/386",
"windows/amd64",
// TODO(yar): support plan9
//"plan9/386",
//"plan9/amd64",
//"plan9/arm",
}
env := os.Environ()
for i := range pairs {
p := pairs[i]
pair := strings.Split(p, "/")
goos, goarch := pair[0], pair[1]
if goos == "solaris" && !requireMinor(7) {
t.Log("skip, solaris requires at least go1.7")
continue
}
if goarch == "riscv64" && !requireMinor(14) {
t.Log("skip, riscv64 requires at least go1.14")
continue
}
cmd := exec.Command("go", "build", "./")
env := append([]string(nil), env...)
cmd.Env = append(env, "GOOS="+goos, "GOARCH="+goarch)
out, err := cmd.CombinedOutput()
if len(out) > 0 {
t.Log(p, "\n", string(out))
}
if err != nil {
t.Error(p, err)
}
}
}
func requireMinor(minor int) bool {
str := runtime.Version()
if !strings.HasPrefix(str, "go1.") {
return true
}
str = strings.TrimPrefix(str, "go1.")
ver, err := strconv.ParseFloat(str, 10)
if err != nil {
return false
}
return ver >= float64(minor)
}