Source file
misc/cgo/test/pkg_test.go
1
2
3
4
5 package cgotest
6
7 import (
8 "os"
9 "os/exec"
10 "path/filepath"
11 "runtime"
12 "strings"
13 "testing"
14 )
15
16
17
18
19
20
21
22
23
24
25
26
27
28 func TestCrossPackageTests(t *testing.T) {
29 switch runtime.GOOS {
30 case "android":
31 t.Skip("Can't exec cmd/go subprocess on Android.")
32 case "ios":
33 switch runtime.GOARCH {
34 case "arm64":
35 t.Skip("Can't exec cmd/go subprocess on iOS.")
36 }
37 }
38
39 GOPATH, err := os.MkdirTemp("", "cgotest")
40 if err != nil {
41 t.Fatal(err)
42 }
43 defer os.RemoveAll(GOPATH)
44
45 modRoot := filepath.Join(GOPATH, "src", "cgotest")
46 if err := overlayDir(modRoot, "testdata"); err != nil {
47 t.Fatal(err)
48 }
49 if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
50 t.Fatal(err)
51 }
52
53 cmd := exec.Command("go", "test")
54 if testing.Verbose() {
55 cmd.Args = append(cmd.Args, "-v")
56 }
57 if testing.Short() {
58 cmd.Args = append(cmd.Args, "-short")
59 }
60 cmd.Dir = modRoot
61 cmd.Env = append(os.Environ(), "GOPATH="+GOPATH, "PWD="+cmd.Dir)
62 out, err := cmd.CombinedOutput()
63 if err == nil {
64 t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
65 } else {
66 t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
67 }
68 }
69
View as plain text