]> Cypherpunks repositories - gostls13.git/commitdiff
go/internal/gccgoimporter: fix test when using gccgo before GCC 7
authorIan Lance Taylor <iant@golang.org>
Fri, 30 Nov 2018 20:44:34 +0000 (12:44 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 30 Nov 2018 21:10:51 +0000 (21:10 +0000)
In TestObjImporter skip tests that use type aliases when using a
version of gccgo before GCC 7, since that is when type aliases were
added.

Fixes #29006

Change-Id: I676bae9f023931cf95ac9b4d4de893fe8517af9b
Reviewed-on: https://go-review.googlesource.com/c/152078
Reviewed-by: Than McIntosh <thanm@google.com>
src/go/internal/gccgoimporter/importer_test.go

index 30b51db9d4d0a58c5b8b0db723924ce0b686ed88..9725fd429fb1dfa400b91c298ca4924945dbd762 100644 (file)
@@ -11,6 +11,8 @@ import (
        "os"
        "os/exec"
        "path/filepath"
+       "regexp"
+       "strconv"
        "testing"
 )
 
@@ -120,6 +122,25 @@ func TestObjImporter(t *testing.T) {
                t.Skip("This test needs gccgo")
        }
 
+       verout, err := exec.Command(gpath, "--version").CombinedOutput()
+       if err != nil {
+               t.Logf("%s", verout)
+               t.Fatal(err)
+       }
+       vers := regexp.MustCompile(`([0-9]+)\.([0-9]+)`).FindSubmatch(verout)
+       if len(vers) == 0 {
+               t.Fatalf("could not find version number in %s", verout)
+       }
+       major, err := strconv.Atoi(string(vers[1]))
+       if err != nil {
+               t.Fatal(err)
+       }
+       minor, err := strconv.Atoi(string(vers[2]))
+       if err != nil {
+               t.Fatal(err)
+       }
+       t.Logf("gccgo version %d.%d", major, minor)
+
        tmpdir, err := ioutil.TempDir("", "")
        if err != nil {
                t.Fatal(err)
@@ -135,6 +156,14 @@ func TestObjImporter(t *testing.T) {
        arimp := GetImporter([]string{artmpdir}, arinitmap)
 
        for _, test := range importerTests {
+               // Support for type aliases was added in GCC 7.
+               if test.pkgpath == "aliases" || test.pkgpath == "issue27856" {
+                       if major < 7 {
+                               t.Logf("skipping %q: not supported before gccgo version 7", test.pkgpath)
+                               continue
+                       }
+               }
+
                gofile := filepath.Join("testdata", test.pkgpath+".go")
                if _, err := os.Stat(gofile); os.IsNotExist(err) {
                        continue