]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix TestCgoContainsSpace
authorHiroshi Ioka <hirochachacha@gmail.com>
Fri, 12 May 2017 00:04:55 +0000 (09:04 +0900)
committerIan Lance Taylor <iant@golang.org>
Fri, 12 May 2017 01:10:11 +0000 (01:10 +0000)
TestCgoContainsSpace builds a small program which mimics $CC.
Usually, $CC attempts to compile a trivial code to detect its own
supported flags (i.e. "-no-pie", which must be passed on some systems),
however the mimic didn't consider these cases.

This CL solve the issue.

Also, use the same name as $CC, it may solve other potential problems.

Fixes #20324

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

src/cmd/go/go_test.go

index 131a0985aeb6367a66f930026f1c7703825c81b0..73489ca27420f0f44338fb1090f7e78b9fcc51fc 100644 (file)
@@ -4055,13 +4055,26 @@ func TestCgoFlagContainsSpace(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
 
-       tg.tempFile("src/cc/main.go", fmt.Sprintf(`package main
+       tg.tempFile(fmt.Sprintf("src/%s/main.go", testCC), fmt.Sprintf(`package main
                import (
                        "os"
                        "os/exec"
                )
 
                func main() {
+                       cmd := exec.Command(%q, os.Args[1:]...)
+                       cmd.Stdin = os.Stdin
+                       cmd.Stdout = os.Stdout
+                       cmd.Stderr = os.Stderr
+                       err := cmd.Run()
+                       if err != nil {
+                               panic(err)
+                       }
+
+                       if os.Args[len(os.Args)-1] == "trivial.c" {
+                               return
+                       }
+
                        var success bool
                        for _, arg := range os.Args {
                                switch arg {
@@ -4080,24 +4093,18 @@ func TestCgoFlagContainsSpace(t *testing.T) {
                        if !success {
                                panic("args should contains '-Ic flags' or '-Lld flags'")
                        }
-                       cmd := exec.Command(%q, os.Args[1:]...)
-                       cmd.Stdin = os.Stdin
-                       cmd.Stdout = os.Stdout
-                       err := cmd.Run()
-                       if err != nil {
-                               panic(err)
-                       }
                }
        `, testCC))
-       tg.cd(tg.path("src/cc"))
+       tg.cd(tg.path(fmt.Sprintf("src/%s", testCC)))
        tg.run("build")
-       tg.setenv("CC", tg.path("src/cc/cc"))
-       tg.tempFile("src/cgo/cgo.go", `package main
+       tg.setenv("CC", tg.path(fmt.Sprintf("src/%s/%s", testCC, testCC)))
+
+       tg.tempFile("src/cgo/main.go", `package main
                // #cgo CFLAGS: -I"c flags"
                // #cgo LDFLAGS: -L"ld flags"
                import "C"
                func main() {}
        `)
-       path := tg.path("src/cgo/cgo.go")
-       tg.run("run", path)
+       tg.cd(tg.path("src/cgo"))
+       tg.run("run", "main.go")
 }