testsuite: arm: Relax register selection [PR116623]
[official-gcc.git] / libgo / misc / cgo / test / pkg_test.go
blob14013a4cd962b621f6e5a9a4cade19c0504edcb6
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package cgotest
7 import (
8 "os"
9 "os/exec"
10 "path/filepath"
11 "runtime"
12 "strings"
13 "testing"
16 // TestCrossPackageTests compiles and runs tests that depend on imports of other
17 // local packages, using source code stored in the testdata directory.
19 // The tests in the misc directory tree do not have a valid import path in
20 // GOPATH mode, so they previously used relative imports. However, relative
21 // imports do not work in module mode. In order to make the test work in both
22 // modes, we synthesize a GOPATH in which the module paths are equivalent, and
23 // run the tests as a subprocess.
25 // If and when we no longer support these tests in GOPATH mode, we can remove
26 // this shim and move the tests currently located in testdata back into the
27 // parent directory.
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.")
39 GOPATH, err := os.MkdirTemp("", "cgotest")
40 if err != nil {
41 t.Fatal(err)
43 defer os.RemoveAll(GOPATH)
45 modRoot := filepath.Join(GOPATH, "src", "cgotest")
46 if err := overlayDir(modRoot, "testdata"); err != nil {
47 t.Fatal(err)
49 if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
50 t.Fatal(err)
53 cmd := exec.Command("go", "test")
54 if testing.Verbose() {
55 cmd.Args = append(cmd.Args, "-v")
57 if testing.Short() {
58 cmd.Args = append(cmd.Args, "-short")
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)