aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/build_cwd_newline.txt
blob: 8f74c01c81272a86982c13cc8b60396cf6beeab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
[windows] skip 'filesystem normalizes / to \'
[plan9] skip 'filesystem disallows \n in paths'

# If the directory path containing a package to be built includes a newline,
# the go command should refuse to even try to build the package.

env DIR=$WORK${/}${newline}'package main'${newline}'func main() { panic("uh-oh")'${newline}'/*'

mkdir $DIR
cd $DIR
exec pwd
cp $WORK/go.mod ./go.mod
cp $WORK/main.go ./main.go
cp $WORK/main_nocgo.go ./main_nocgo.go
cp $WORK/main_test.go ./main_test.go

! go build -o $devnull .
stderr 'package example: invalid package directory .*uh-oh'

[cgo] ! go build -o $devnull main.go
[!cgo] ! go build -o $devnull main_nocgo.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'

! go run .
stderr 'package example: invalid package directory .*uh-oh'

[cgo] ! go run main.go
[!cgo] ! go run main_nocgo.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'

! go test .
stderr 'package example: invalid package directory .*uh-oh'

[cgo] ! go test -v main.go main_test.go
[!cgo] ! go test -v main_nocgo.go main_test.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'

	# Note: this command fails on release-branch.go1.19 but succeeds
	# on release-branch.go1.20 and later. I (bcmills) suspect it may
	# have been fixed by CL 437298.
! go list -compiled -e -f '{{with .CompiledGoFiles}}{{.}}{{end}}' .
stderr 'package example: invalid package directory .*uh-oh'
! stdout .
! exists obj_

# Since we do preserve $PWD (or set it appropriately) for commands, and we do
# not resolve symlinks unnecessarily, referring to the contents of the unsafe
# directory via a safe symlink should be ok, and should not inject the data from
# the symlink target path.

[!symlink] stop 'remainder of test checks symlink behavior'
[short] stop 'links and runs binaries'

symlink $WORK${/}link -> $DIR

[cgo] go run $WORK${/}link${/}main.go
[!cgo] go run $WORK${/}link${/}main_nocgo.go
! stdout panic
! stderr panic
stderr '^ok$'

[cgo] go test -v $WORK${/}link${/}main.go $WORK${/}link${/}main_test.go
[!cgo] go test -v $WORK${/}link${/}main_nocgo.go $WORK${/}link${/}main_test.go
! stdout panic
! stderr panic
stdout '^ok$'   # 'go test' combines the test's stdout into stderr

cd $WORK/link

[cgo] ! go run $DIR${/}main.go
[!cgo] ! go run $DIR${/}main_nocgo.go
stderr 'package command-line-arguments: invalid package directory .*uh-oh'

go run .
! stdout panic
! stderr panic
stderr '^ok$'

[cgo] go run main.go
[!cgo] go run main_nocgo.go
! stdout panic
! stderr panic
stderr '^ok$'

go test -v
! stdout panic
! stderr panic
stdout '^ok$'  # 'go test' combines the test's stdout into stderr

go test -v .
! stdout panic
! stderr panic
stdout '^ok$'  # 'go test' combines the test's stdout into stderr


-- $WORK/go.mod --
module example
go 1.19
-- $WORK/main.go --
package main

import "C"

func main() {
	/* nothing here */
	println("ok")
}
-- $WORK/main_nocgo.go --
//go:build !cgo

package main

func main() {
	/* nothing here */
	println("ok")
}
-- $WORK/main_test.go --
package main

import "testing"

func TestMain(*testing.M) {
	main()
}