...

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

Documentation: cmd/go/testdata/script

     1[GOOS:windows] skip 'filesystem normalizes / to \'
     2[GOOS:plan9] skip 'filesystem disallows \n in paths'
     3
     4# If the directory path containing a package to be built includes a newline,
     5# the go command should refuse to even try to build the package.
     6
     7env DIR=$WORK${/}${newline}'package main'${newline}'func main() { panic("uh-oh")'${newline}'/*'
     8
     9mkdir $DIR
    10cd $DIR
    11exec pwd
    12cp $WORK/go.mod ./go.mod
    13cp $WORK/main.go ./main.go
    14cp $WORK/main_nocgo.go ./main_nocgo.go
    15cp $WORK/main_test.go ./main_test.go
    16
    17! go build -o $devnull .
    18stderr 'package example: invalid package directory .*uh-oh'
    19
    20[cgo] ! go build -o $devnull main.go
    21[!cgo] ! go build -o $devnull main_nocgo.go
    22stderr 'package command-line-arguments: invalid package directory .*uh-oh'
    23
    24! go run .
    25stderr 'package example: invalid package directory .*uh-oh'
    26
    27[cgo] ! go run main.go
    28[!cgo] ! go run main_nocgo.go
    29stderr 'package command-line-arguments: invalid package directory .*uh-oh'
    30
    31! go test .
    32stderr 'package example: invalid package directory .*uh-oh'
    33
    34[cgo] ! go test -v main.go main_test.go
    35[!cgo] ! go test -v main_nocgo.go main_test.go
    36stderr 'package command-line-arguments: invalid package directory .*uh-oh'
    37
    38go list -compiled -e -f '{{with .CompiledGoFiles}}{{.}}{{end}}' .
    39! stdout .
    40! stderr .
    41! exists obj_
    42
    43
    44# The cgo tool should only accept the source file if the working directory
    45# is not written in line directives in the resulting files.
    46
    47[cgo] ! go tool cgo main.go
    48[cgo] stderr 'cgo: input path contains newline character: .*uh-oh'
    49[cgo] ! exists _obj
    50
    51[cgo] go tool cgo -trimpath=$PWD main.go
    52[cgo] grep '//line main\.go:1:1' _obj/main.cgo1.go
    53[cgo] ! grep 'uh-oh' _obj/main.cgo1.go
    54[cgo] rm _obj
    55
    56
    57# Since we do preserve $PWD (or set it appropriately) for commands, and we do
    58# not resolve symlinks unnecessarily, referring to the contents of the unsafe
    59# directory via a safe symlink should be ok, and should not inject the data from
    60# the symlink target path.
    61
    62[!symlink] stop 'remainder of test checks symlink behavior'
    63[short] stop 'links and runs binaries'
    64
    65symlink $WORK${/}link -> $DIR
    66
    67[cgo] go run $WORK${/}link${/}main.go
    68[!cgo] go run $WORK${/}link${/}main_nocgo.go
    69! stdout panic
    70! stderr panic
    71stderr '^ok$'
    72
    73[cgo] go test -v $WORK${/}link${/}main.go $WORK${/}link${/}main_test.go
    74[!cgo] go test -v $WORK${/}link${/}main_nocgo.go $WORK${/}link${/}main_test.go
    75! stdout panic
    76! stderr panic
    77stdout '^ok$'   # 'go test' combines the test's stdout into stderr
    78
    79cd $WORK/link
    80
    81[cgo] ! go run $DIR${/}main.go
    82[!cgo] ! go run $DIR${/}main_nocgo.go
    83stderr 'package command-line-arguments: invalid package directory .*uh-oh'
    84
    85go run .
    86! stdout panic
    87! stderr panic
    88stderr '^ok$'
    89
    90[cgo] go run main.go
    91[!cgo] go run main_nocgo.go
    92! stdout panic
    93! stderr panic
    94stderr '^ok$'
    95
    96go test -v
    97! stdout panic
    98! stderr panic
    99stdout '^ok$'  # 'go test' combines the test's stdout into stderr
   100
   101go test -v .
   102! stdout panic
   103! stderr panic
   104stdout '^ok$'  # 'go test' combines the test's stdout into stderr
   105
   106[cgo] go tool cgo main.go
   107[cgo] grep '//line .*'${/}'link'${/}'main\.go:1:1' _obj/main.cgo1.go
   108[cgo] ! grep 'uh-oh' _obj/main.cgo1.go
   109
   110-- $WORK/go.mod --
   111module example
   112go 1.19
   113-- $WORK/main.go --
   114package main
   115
   116import "C"
   117
   118func main() {
   119	/* nothing here */
   120	println("ok")
   121}
   122-- $WORK/main_nocgo.go --
   123//go:build !cgo
   124
   125package main
   126
   127func main() {
   128	/* nothing here */
   129	println("ok")
   130}
   131-- $WORK/main_test.go --
   132package main
   133
   134import "testing"
   135
   136func TestMain(*testing.M) {
   137	main()
   138}

View as plain text