...
1env GOWORK=off
2env GO111MODULE=on
3
4# golang.org/issue/32917 and golang.org/issue/28459: 'go build' and 'go test'
5# in an empty directory should refer to the path '.' and should not attempt
6# to resolve an external module.
7cd dir
8! go get
9stderr '^go: no package to get in current directory$'
10! go get .
11stderr '^go: .: no package to get in current directory$'
12! go get ./subdir
13stderr '^go: \.[/\\]subdir \('$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]subdir\) is not a package in module rooted at '$WORK'[/\\]gopath[/\\]src[/\\]dir$'
14! go list
15! stderr 'cannot find module providing package'
16stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir$'
17
18cd subdir
19! go list
20! stderr 'cannot find module providing package'
21stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]subdir$'
22cd ..
23
24# golang.org/issue/30590: if a package is found in the filesystem
25# but is not in the main module, the error message should not say
26# "cannot find module providing package", and we shouldn't try
27# to find a module providing the package.
28! go list ./othermodule
29! stderr 'cannot find module providing package'
30stderr '^main module \(example\.com\) does not contain package example.com/othermodule$'
31
32# golang.org/issue/27122: 'go build' of a nonexistent directory should produce
33# a helpful "no Go files" error message, not a generic "unknown import path".
34! go list ./subdir
35stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]subdir$'
36
37# golang.org/issue/29280: 'go list -e' for a nonexistent directory should
38# report a nonexistent package with an error.
39go list -e -json ./subdir
40stdout '"Incomplete": true'
41
42# golang.org/issue/28155: 'go list ./testdata' should not synthesize underscores.
43go list ./testdata
44stdout '^example.com/testdata'
45
46# golang.org/issue/32921: vendor directories should only be accepted as directories
47# if the directory would actually be used to load the package.
48! go list ./vendor/nonexist
49stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]nonexist$'
50
51! go list ./vendor/pkg
52stderr '^without -mod=vendor, directory '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]pkg has no package path$'
53
54! go list -mod=vendor ./vendor/nonexist
55stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]nonexist$'
56
57! go list -mod=vendor ./vendor/unlisted
58stderr '^directory '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]unlisted is not a package listed in vendor/modules.txt$'
59
60go list -mod=vendor ./vendor/pkg
61stdout '^pkg$'
62
63# Packages within GOROOT should resolve as in any other module,
64# except that -mod=vendor is implied by default.
65cd $GOROOT/src
66! go list .
67stderr '^no Go files in '$GOROOT'[/\\]src$'
68
69! go list ./builtin
70stderr '^"builtin" is a pseudo-package, not an importable package$'
71
72! go list ./debug
73! stderr 'cannot find module providing package'
74stderr '^no Go files in '$GOROOT'[/\\]src[/\\]debug$'
75
76! go list ./golang.org/x/tools/cmd/goimports
77! stderr 'cannot find module providing package'
78stderr '^stat '$GOROOT'[/\\]src[/\\]golang.org[/\\]x[/\\]tools[/\\]cmd[/\\]goimports: directory not found'
79
80go list ./vendor/golang.org/x/net/http2/hpack
81stdout '^golang.org/x/net/http2/hpack$'
82
83# golang.org/issue/30756: packages in other GOROOTs should not get the special
84# prefixless treatment of GOROOT itself.
85cd $WORK/othergoroot/src
86! go list .
87stderr '^no Go files in '$WORK'[/\\]othergoroot[/\\]src$'
88
89go list ./builtin
90stdout '^std/builtin$' # Only the "std" in actual $GOROOT is special, and only its "builtin" is special.
91
92! go list ./bytes
93! stderr 'cannot find module providing package'
94stderr '^no Go files in '$WORK'[/\\]othergoroot[/\\]src[/\\]bytes$'
95
96! go list ./vendor/golang.org/x/net/http2/hpack
97stderr '^without -mod=vendor, directory '$WORK'[/\\]othergoroot[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack has no package path$'
98
99-- dir/go.mod --
100module example.com
101go 1.13
102-- dir/subdir/README --
103There are no Go source files in this directory.
104-- dir/othermodule/go.mod --
105module example.com/othermodule
106go 1.13
107-- dir/othermodule/om.go --
108package othermodule
109-- dir/testdata/td.go --
110package testdata
111-- dir/vendor/modules.txt --
112# pkg v0.0.0
113pkg
114-- dir/vendor/nonexist/README --
115There are no Go source files here either.
116-- dir/vendor/pkg/pkg.go --
117package pkg
118-- dir/vendor/unlisted/unlisted.go --
119package unlisted
120-- emptyroot/go.mod --
121module example.com/emptyroot
122-- emptyroot/pkg/pkg.go --
123package pkg
124-- $WORK/othergoroot/src/go.mod --
125module std
126go 1.13
127-- $WORK/othergoroot/src/builtin/builtin.go --
128package builtin
129-- $WORK/othergoroot/src/bytes/README --
130There are no Go source files in this directory.
131-- $WORK/othergoroot/src/vendor/golang.org/x/net/http2/hpack --
132package hpack
View as plain text