...

Text file src/cmd/go/testdata/script/cgo_path_space_quote.txt

Documentation: cmd/go/testdata/script

     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
    11env GOENV=$WORK/go.env
    12mkdir 'program files'
    13go 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
    16go env CC
    17stdout 'program files[/\\]which cc" (clang|gcc)$'
    18go env -w CC=$CC
    19env CC=
    20go env CC
    21stdout 'program files[/\\]which cc" (clang|gcc)$'
    22
    23go run .
    24stdout 1
    25
    26-- go.mod --
    27module test
    28
    29go 1.17
    30-- which cc/which cc.go --
    31package main
    32
    33import (
    34	"fmt"
    35	"os"
    36	"os/exec"
    37)
    38
    39func 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 --
    50package main
    51
    52// int x = WRAPPER_WAS_USED;
    53import "C"
    54import "fmt"
    55
    56func main() {
    57	fmt.Println(C.x)
    58}

View as plain text