aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dist/test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2023-05-08 14:39:57 -0400
committerAustin Clements <austin@google.com>2023-05-12 12:00:05 +0000
commit2484e1331a6054ffa25e2e6a4146943251171c56 (patch)
tree13d8ab09c60f5c51d659f7651fedaf4820ede7be /src/cmd/dist/test.go
parent711609d55f7d1254e0400fd870c97d5c5a259a99 (diff)
downloadgo-2484e1331a6054ffa25e2e6a4146943251171c56.tar.gz
go-2484e1331a6054ffa25e2e6a4146943251171c56.zip
misc/swig: restructure as a driver
Currently, the misc/swig tests directly use Swig and C++ and will fail to build if either Swig or a C++ compiler are not present. Typically, we hide this fact from users because dist test itself checks for Swig and a C++ compiler before even attempting to run this test, though users will see this is they try to go test ./... from misc. However, we're about to move the misc/swig tests into the cmd module, where they will be much more visible and much more likely to run unintentionally. To prevent build errors, this CL restructures these tests into a single pure Go test plus two test packages hidden in testdata. This is relatively easy to do for this test because there are only four test cases total. The pure Go test can check for the necessary build tools before trying to build and run the tests in testdata. This also gives us the opportunity to move the LTO variant of these tests out of dist and into the test itself, simplifying dist. For #37486. Change-Id: Ibda089b4069e36866cb31867a7006c790be2d8b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/493599 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/dist/test.go')
-rw-r--r--src/cmd/dist/test.go96
1 files changed, 2 insertions, 94 deletions
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
index 2e0072f44f..95c27ce327 100644
--- a/src/cmd/dist/test.go
+++ b/src/cmd/dist/test.go
@@ -870,21 +870,8 @@ func (t *tester) registerTests() {
if goos != "android" {
t.registerTest("cgo_testfortran", "", &goTest{dir: "cmd/cgo/internal/testfortran", timeout: 5 * time.Minute}, rtHostTest{})
}
- if t.hasSwig() && goos != "android" {
- t.registerTest("swig_stdio", "", &goTest{dir: "../misc/swig/stdio"})
- if t.hasCxx() {
- t.registerTest("swig_callback", "", &goTest{dir: "../misc/swig/callback"})
- const cflags = "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option"
- t.registerTest("swig_callback_lto", "",
- &goTest{
- dir: "../misc/swig/callback",
- env: []string{
- "CGO_CFLAGS=" + cflags,
- "CGO_CXXFLAGS=" + cflags,
- "CGO_LDFLAGS=" + cflags,
- },
- })
- }
+ if goos != "android" {
+ t.registerTest("swig", "", &goTest{dir: "../misc/swig"})
}
}
if t.cgoEnabled {
@@ -1412,85 +1399,6 @@ func (t *tester) hasBash() bool {
return true
}
-func (t *tester) hasCxx() bool {
- cxx, _ := exec.LookPath(compilerEnvLookup("CXX", defaultcxx, goos, goarch))
- return cxx != ""
-}
-
-func (t *tester) hasSwig() bool {
- swig, err := exec.LookPath("swig")
- if err != nil {
- return false
- }
-
- // Check that swig was installed with Go support by checking
- // that a go directory exists inside the swiglib directory.
- // See https://golang.org/issue/23469.
- output, err := exec.Command(swig, "-go", "-swiglib").Output()
- if err != nil {
- return false
- }
- swigDir := strings.TrimSpace(string(output))
-
- _, err = os.Stat(filepath.Join(swigDir, "go"))
- if err != nil {
- return false
- }
-
- // Check that swig has a new enough version.
- // See https://golang.org/issue/22858.
- out, err := exec.Command(swig, "-version").CombinedOutput()
- if err != nil {
- return false
- }
-
- re := regexp.MustCompile(`[vV]ersion +(\d+)([.]\d+)?([.]\d+)?`)
- matches := re.FindSubmatch(out)
- if matches == nil {
- // Can't find version number; hope for the best.
- return true
- }
-
- major, err := strconv.Atoi(string(matches[1]))
- if err != nil {
- // Can't find version number; hope for the best.
- return true
- }
- if major < 3 {
- return false
- }
- if major > 3 {
- // 4.0 or later
- return true
- }
-
- // We have SWIG version 3.x.
- if len(matches[2]) > 0 {
- minor, err := strconv.Atoi(string(matches[2][1:]))
- if err != nil {
- return true
- }
- if minor > 0 {
- // 3.1 or later
- return true
- }
- }
-
- // We have SWIG version 3.0.x.
- if len(matches[3]) > 0 {
- patch, err := strconv.Atoi(string(matches[3][1:]))
- if err != nil {
- return true
- }
- if patch < 6 {
- // Before 3.0.6.
- return false
- }
- }
-
- return true
-}
-
// hasParallelism is a copy of the function
// internal/testenv.HasParallelism, which can't be used here
// because cmd/dist can not import internal packages during bootstrap.