]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testshared: do not run gccgo tests when gccgo is too old
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Sun, 23 Aug 2015 22:44:36 +0000 (10:44 +1200)
committerIan Lance Taylor <iant@golang.org>
Wed, 26 Aug 2015 01:19:55 +0000 (01:19 +0000)
Fixes #12083

Change-Id: I8256739b33cf08d84dec23120d527667de2e6eea
Reviewed-on: https://go-review.googlesource.com/13822
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/testshared/shared_test.go

index 6ef448c4f2759417fb632009f8d85f3478b75291..2e123641631cf94ed1595b4a56e265f5782b2b28 100644 (file)
@@ -460,24 +460,39 @@ func TestTwoGopathShlibs(t *testing.T) {
        run(t, "executable linked to GOPATH library", "./bin/exe2")
 }
 
-// Build a GOPATH package into a shared library with gccgo and an executable that
-// links against it.
-func TestGoPathShlibGccgo(t *testing.T) {
+// If gccgo is not available or not new enough call t.Skip. Otherwise,
+// return a build.Context that is set up for gccgo.
+func prepGccgo(t *testing.T) build.Context {
        gccgoName := os.Getenv("GCCGO")
        if gccgoName == "" {
                gccgoName = "gccgo"
        }
-       _, err := exec.LookPath(gccgoName)
+       gccgoPath, err := exec.LookPath(gccgoName)
        if err != nil {
                t.Skip("gccgo not found")
        }
-
-       libgoRE := regexp.MustCompile("libgo.so.[0-9]+")
-
+       cmd := exec.Command(gccgoPath, "-dumpversion")
+       output, err := cmd.CombinedOutput()
+       if err != nil {
+               t.Fatalf("%s -dumpversion failed: %v\n%s", gccgoPath, err, output)
+       }
+       if string(output) < "5" {
+               t.Skipf("gccgo too old (%s)", strings.TrimSpace(string(output)))
+       }
        gccgoContext := build.Default
        gccgoContext.InstallSuffix = suffix + "_fPIC"
        gccgoContext.Compiler = "gccgo"
        gccgoContext.GOPATH = os.Getenv("GOPATH")
+       return gccgoContext
+}
+
+// Build a GOPATH package into a shared library with gccgo and an executable that
+// links against it.
+func TestGoPathShlibGccgo(t *testing.T) {
+       gccgoContext := prepGccgo(t)
+
+       libgoRE := regexp.MustCompile("libgo.so.[0-9]+")
+
        depP, err := gccgoContext.Import("dep", ".", build.ImportComment)
        if err != nil {
                t.Fatalf("import failed: %v", err)
@@ -497,21 +512,10 @@ func TestGoPathShlibGccgo(t *testing.T) {
 // library with gccgo, another GOPATH package that depends on the first and an
 // executable that links the second library.
 func TestTwoGopathShlibsGccgo(t *testing.T) {
-       gccgoName := os.Getenv("GCCGO")
-       if gccgoName == "" {
-               gccgoName = "gccgo"
-       }
-       _, err := exec.LookPath(gccgoName)
-       if err != nil {
-               t.Skip("gccgo not found")
-       }
+       gccgoContext := prepGccgo(t)
 
        libgoRE := regexp.MustCompile("libgo.so.[0-9]+")
 
-       gccgoContext := build.Default
-       gccgoContext.InstallSuffix = suffix + "_fPIC"
-       gccgoContext.Compiler = "gccgo"
-       gccgoContext.GOPATH = os.Getenv("GOPATH")
        depP, err := gccgoContext.Import("dep", ".", build.ImportComment)
        if err != nil {
                t.Fatalf("import failed: %v", err)