| 1 |
# Return an error if the user tries to list a go source file directly in $GOROOT/src. |
| 2 |
# Tests golang.org/issue/36587 |
| 3 |
|
| 4 |
env GOROOT=$WORK/goroot |
| 5 |
env GOPATH=$WORK/gopath |
| 6 |
|
| 7 |
go env GOROOT |
| 8 |
stdout $WORK[/\\]goroot |
| 9 |
|
| 10 |
# switch to GOROOT/src |
| 11 |
cd $GOROOT/src |
| 12 |
|
| 13 |
# In module mode, 'go list ./...' should not treat .go files in GOROOT/src as an |
| 14 |
# importable package, since that directory has no valid import path. |
| 15 |
env GO111MODULE=on |
| 16 |
go list ... |
| 17 |
stdout -count=1 '^.+$' |
| 18 |
stdout '^fmt$' |
| 19 |
! stdout foo |
| 20 |
|
| 21 |
go list ./... |
| 22 |
stdout -count=1 '^.+$' |
| 23 |
stdout '^fmt$' |
| 24 |
! stdout foo |
| 25 |
|
| 26 |
go list std |
| 27 |
stdout -count=1 '^.+$' |
| 28 |
stdout '^fmt$' |
| 29 |
|
| 30 |
! go list . |
| 31 |
stderr '^GOROOT/src is not an importable package$' |
| 32 |
|
| 33 |
# In GOPATH mode, 'go list ./...' should synthesize a legacy GOPATH-mode path — |
| 34 |
# not a standard-library or empty path — for the errant package. |
| 35 |
env GO111MODULE=off |
| 36 |
go list ./... |
| 37 |
stdout -count=2 '^.+$' # Both 'fmt' and GOROOT/src should be listed. |
| 38 |
stdout '^fmt$' |
| 39 |
[!GOOS:windows] stdout ^_$WORK/goroot/src$ |
| 40 |
[GOOS:windows] stdout goroot/src$ # On windows the ":" in the volume name is mangled |
| 41 |
|
| 42 |
go list ... |
| 43 |
! stdout goroot/src |
| 44 |
|
| 45 |
go list std |
| 46 |
! stdout goroot/src |
| 47 |
|
| 48 |
go list . |
| 49 |
[!GOOS:windows] stdout ^_$WORK/goroot/src$ |
| 50 |
[GOOS:windows] stdout goroot/src$ |
| 51 |
|
| 52 |
# switch to GOPATH/src |
| 53 |
cd $GOPATH/src |
| 54 |
|
| 55 |
# GO111MODULE=off,GOPATH |
| 56 |
env GO111MODULE=off |
| 57 |
go list ./... |
| 58 |
[!GOOS:windows] stdout ^_$WORK/gopath/src$ |
| 59 |
[GOOS:windows] stdout gopath/src$ |
| 60 |
|
| 61 |
go list all |
| 62 |
! stdout gopath/src |
| 63 |
|
| 64 |
-- $WORK/goroot/src/go.mod -- |
| 65 |
module std |
| 66 |
|
| 67 |
go 1.14 |
| 68 |
-- $WORK/goroot/src/foo.go -- |
| 69 |
package foo |
| 70 |
-- $WORK/goroot/src/fmt/fmt.go -- |
| 71 |
package fmt |
| 72 |
-- $WORK/goroot/src/cmd/README -- |
| 73 |
This directory must exist in order for the 'cmd' pattern to have something to |
| 74 |
match against. |
| 75 |
-- $GOPATH/src/foo.go -- |
| 76 |
package foo |