1 # This test checks that the CC environment variable may contain quotes and
2 # spaces. Arguments are normally split on spaces, tabs, newlines. If an
3 # argument contains these characters, the entire argument may be quoted
4 # with single or double quotes. This is the same as -gcflags and similar
5 # options.
6
7 [short] skip
8 [!exec:clang] [!exec:gcc] skip
9 [!cgo] skip
10
11 env GOENV=$WORK/go.env
12 mkdir 'program files'
13 go build -o 'program files' './which cc/which cc.go'
14 [exec:clang] env CC='"'$PWD${/}program' 'files${/}which' 'cc"' 'clang
15 [!exec:clang] env CC='"'$PWD${/}program' 'files${/}which' 'cc"' 'gcc
16 go env CC
17 stdout 'program files[/\\]which cc" (clang|gcc)$'
18 go env -w CC=$CC
19 env CC=
20 go env CC
21 stdout 'program files[/\\]which cc" (clang|gcc)$'
22
23 go run .
24 stdout 1
25
26 -- go.mod --
27 module test
28
29 go 1.17
30 -- which cc/which cc.go --
31 package main
32
33 import (
34 "fmt"
35 "os"
36 "os/exec"
37 )
38
39 func main() {
40 args := append([]string{"-DWRAPPER_WAS_USED=1"}, os.Args[2:]...)
41 cmd := exec.Command(os.Args[1], args...)
42 cmd.Stdout = os.Stdout
43 cmd.Stderr = os.Stderr
44 if err := cmd.Run(); err != nil {
45 fmt.Fprintln(os.Stderr, err)
46 os.Exit(1)
47 }
48 }
49 -- hello.go --
50 package main
51
52 // int x = WRAPPER_WAS_USED;
53 import "C"
54 import "fmt"
55
56 func main() {
57 fmt.Println(C.x)
58 }
59
View as plain text