]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: rewrite TestCgoFlagContainsSpace not to use a fake CC
authorRuss Cox <rsc@golang.org>
Fri, 9 Jun 2017 15:44:31 +0000 (11:44 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 18 Aug 2017 14:25:36 +0000 (14:25 +0000)
Using a fake CC fails today if runtime/cgo is stale, because the
build will try to rebuild runtime/cgo using the fake CC, and the
fake CC is not a working C compiler.

Worse, in the future, when the go command is sensitive to details like
the fact that different CCs produce different outputs, putting in
the fake CC will make runtime/cgo look stale even if it was
formerly up-to-date.

Fix both problems by not overriding CC and instead looking at
the command being run to make sure the flags are quoted as expected.

Change-Id: I4417e35cfab33a07546cc90748ddb6119d8fdb2d
Reviewed-on: https://go-review.googlesource.com/56272
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go

index 56b9b07889b3f96e12b57a4885fe5bb093374dca..b836da9f5716d71bcee6ee0926e28f2341ead963 100644 (file)
@@ -4141,65 +4141,22 @@ func TestCgoFlagContainsSpace(t *testing.T) {
        if !canCgo {
                t.Skip("skipping because cgo not enabled")
        }
-
        tg := testgo(t)
        defer tg.cleanup()
 
-       ccName := filepath.Base(testCC)
-
-       tg.tempFile(fmt.Sprintf("src/%s/main.go", ccName), fmt.Sprintf(`package main
-               import (
-                       "os"
-                       "os/exec"
-                       "strings"
-               )
-
-               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 {
-                               case strings.Contains(arg, "c flags"):
-                                       if success {
-                                               panic("duplicate CFLAGS")
-                                       }
-                                       success = true
-                               case strings.Contains(arg, "ld flags"):
-                                       if success {
-                                               panic("duplicate LDFLAGS")
-                                       }
-                                       success = true
-                               }
-                       }
-                       if !success {
-                               panic("args should contains '-Ic flags' or '-Lld flags'")
-                       }
-               }
-       `, testCC))
-       tg.cd(tg.path(fmt.Sprintf("src/%s", ccName)))
-       tg.run("build")
-       tg.setenv("CC", tg.path(fmt.Sprintf("src/%s/%s", ccName, ccName)))
-
-       tg.tempFile("src/cgo/main.go", `package main
+       tg.makeTempdir()
+       tg.cd(tg.path("."))
+       tg.tempFile("main.go", `package main
                // #cgo CFLAGS: -I"c flags"
                // #cgo LDFLAGS: -L"ld flags"
                import "C"
                func main() {}
        `)
-       tg.cd(tg.path("src/cgo"))
-       tg.run("run", "main.go")
+       tg.run("run", "-x", "main.go")
+       tg.grepStderr(`"-I[^"]+c flags"`, "did not find quoted c flags")
+       tg.grepStderrNot(`"-I[^"]+c flags".*"-I[^"]+c flags"`, "found too many quoted c flags")
+       tg.grepStderr(`"-L[^"]+ld flags"`, "did not find quoted ld flags")
+       tg.grepStderrNot(`"-L[^"]+c flags".*"-L[^"]+c flags"`, "found too many quoted ld flags")
 }
 
 // Issue #20435.