File: compilation_test.go

package info (click to toggle)
golang-github-sevlyar-go-daemon 0.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 232 kB
  • sloc: makefile: 3
file content (79 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download
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
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",
		"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
		}
		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.Atoi(str)
	if err != nil {
		return false
	}
	return ver >= minor
}