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