1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | package gccgoimporter |
8 | |
9 | import ( |
10 | "runtime" |
11 | "strings" |
12 | "testing" |
13 | ) |
14 | |
15 | |
16 | |
17 | func HasGoBuild() bool { |
18 | switch runtime.GOOS { |
19 | case "android", "nacl": |
20 | return false |
21 | case "darwin": |
22 | if strings.HasPrefix(runtime.GOARCH, "arm") { |
23 | return false |
24 | } |
25 | } |
26 | return true |
27 | } |
28 | |
29 | |
30 | |
31 | func HasExec() bool { |
32 | switch runtime.GOOS { |
33 | case "nacl", "js": |
34 | return false |
35 | case "darwin": |
36 | if strings.HasPrefix(runtime.GOARCH, "arm") { |
37 | return false |
38 | } |
39 | } |
40 | return true |
41 | } |
42 | |
43 | |
44 | |
45 | |
46 | func MustHaveGoBuild(t *testing.T) { |
47 | if !HasGoBuild() { |
48 | t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH) |
49 | } |
50 | } |
51 | |
52 | |
53 | |
54 | |
55 | func MustHaveExec(t *testing.T) { |
56 | if !HasExec() { |
57 | t.Skipf("skipping test: cannot exec subprocess on %s/%s", runtime.GOOS, runtime.GOARCH) |
58 | } |
59 | } |
60 | |
61 | var testenv = struct { |
62 | HasGoBuild func() bool |
63 | MustHaveGoBuild func(*testing.T) |
64 | MustHaveExec func(*testing.T) |
65 | }{ |
66 | HasGoBuild: HasGoBuild, |
67 | MustHaveGoBuild: MustHaveGoBuild, |
68 | MustHaveExec: MustHaveExec, |
69 | } |
70 | |