|
8 | 8 | # TODO(#51483): when runtime.GOROOT() returns the empty string,
|
9 | 9 | # go/build should default to 'go env GOROOT' instead.
|
10 | 10 |
|
11 |
| -env GOROOT= |
12 | 11 | env GOROOT_FINAL=
|
13 | 12 |
|
| 13 | +[trimpath] env GOROOT= |
14 | 14 | [trimpath] ! go env GOROOT
|
15 | 15 | [trimpath] stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$'
|
16 |
| -[trimpath] stop |
| 16 | +[trimpath] env GOROOT=$TESTGO_GOROOT |
| 17 | + |
| 18 | +[short] stop |
17 | 19 |
|
| 20 | +# With GOROOT still set but GOROOT_FINAL unset, 'go build' and 'go test -c' |
| 21 | +# should cause runtime.GOROOT() to report either the correct GOROOT |
| 22 | +# (without -trimpath) or no GOROOT at all (with -trimpath). |
18 | 23 |
|
19 |
| -[short] skip |
| 24 | +go build -o example.exe . |
| 25 | +go build -trimpath -o example-trimpath.exe . |
| 26 | +go test -c -o example.test.exe . |
| 27 | +go test -trimpath -c -o example.test-trimpath.exe . |
20 | 28 |
|
21 |
| -go run . |
| 29 | +env GOROOT= |
| 30 | + |
| 31 | +exec ./example.exe |
22 | 32 | stdout '^GOROOT '$TESTGO_GOROOT'$'
|
23 | 33 | stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$'
|
24 | 34 |
|
25 |
| -go test -v . |
| 35 | +! exec ./example-trimpath.exe |
| 36 | +stdout '^GOROOT $' |
| 37 | +stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)\n\z' |
| 38 | + |
| 39 | +exec ./example.test.exe -test.v |
26 | 40 | stdout '^GOROOT '$TESTGO_GOROOT'$'
|
27 | 41 | stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$'
|
28 | 42 |
|
| 43 | +! exec ./example.test-trimpath.exe -test.v |
| 44 | +stdout '^GOROOT $' |
| 45 | +stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)$' |
| 46 | + |
| 47 | +# If a correct GOROOT is baked in to the 'go' command itself, 'go run' and |
| 48 | +# 'go test' should not implicitly set GOROOT in the process environment |
| 49 | +# (because that could mask an unexpected production dependency on the GOROOT |
| 50 | +# environment variable), but 'go generate' should (because the generator may |
| 51 | +# reasonably expect to be able to locate the GOROOT for which it is generating |
| 52 | +# code). |
| 53 | + |
| 54 | +[trimpath] stop |
| 55 | +[mismatched-goroot] stop |
| 56 | + |
29 | 57 | ! go run -trimpath .
|
30 | 58 | stdout '^GOROOT $'
|
31 | 59 | stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)\nexit status 1\n\z'
|
|
0 commit comments