From 482da5180375404439d58cf4f865ed8bc37c6a63 Mon Sep 17 00:00:00 2001 From: Hiroshi Ioka Date: Fri, 12 May 2017 09:04:55 +0900 Subject: [PATCH] cmd/go: fix TestCgoContainsSpace 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/cmd/go/go_test.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 131a0985ae..73489ca274 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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") } -- 2.48.1