Skip to content

Commit 482da51

Browse files
hirochachachaianlancetaylor
authored andcommitted
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 978af9c commit 482da51

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/cmd/go/go_test.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,13 +4055,26 @@ func TestCgoFlagContainsSpace(t *testing.T) {
40554055
tg := testgo(t)
40564056
defer tg.cleanup()
40574057

4058-
tg.tempFile("src/cc/main.go", fmt.Sprintf(`package main
4058+
tg.tempFile(fmt.Sprintf("src/%s/main.go", testCC), fmt.Sprintf(`package main
40594059
import (
40604060
"os"
40614061
"os/exec"
40624062
)
40634063
40644064
func main() {
4065+
cmd := exec.Command(%q, os.Args[1:]...)
4066+
cmd.Stdin = os.Stdin
4067+
cmd.Stdout = os.Stdout
4068+
cmd.Stderr = os.Stderr
4069+
err := cmd.Run()
4070+
if err != nil {
4071+
panic(err)
4072+
}
4073+
4074+
if os.Args[len(os.Args)-1] == "trivial.c" {
4075+
return
4076+
}
4077+
40654078
var success bool
40664079
for _, arg := range os.Args {
40674080
switch arg {
@@ -4080,24 +4093,18 @@ func TestCgoFlagContainsSpace(t *testing.T) {
40804093
if !success {
40814094
panic("args should contains '-Ic flags' or '-Lld flags'")
40824095
}
4083-
cmd := exec.Command(%q, os.Args[1:]...)
4084-
cmd.Stdin = os.Stdin
4085-
cmd.Stdout = os.Stdout
4086-
err := cmd.Run()
4087-
if err != nil {
4088-
panic(err)
4089-
}
40904096
}
40914097
`, testCC))
4092-
tg.cd(tg.path("src/cc"))
4098+
tg.cd(tg.path(fmt.Sprintf("src/%s", testCC)))
40934099
tg.run("build")
4094-
tg.setenv("CC", tg.path("src/cc/cc"))
4095-
tg.tempFile("src/cgo/cgo.go", `package main
4100+
tg.setenv("CC", tg.path(fmt.Sprintf("src/%s/%s", testCC, testCC)))
4101+
4102+
tg.tempFile("src/cgo/main.go", `package main
40964103
// #cgo CFLAGS: -I"c flags"
40974104
// #cgo LDFLAGS: -L"ld flags"
40984105
import "C"
40994106
func main() {}
41004107
`)
4101-
path := tg.path("src/cgo/cgo.go")
4102-
tg.run("run", path)
4108+
tg.cd(tg.path("src/cgo"))
4109+
tg.run("run", "main.go")
41034110
}

0 commit comments

Comments
 (0)