Skip to content

Commit 3d28e0e

Browse files
committed
cmd/go: permit "go list" error in some tests
The vendor_import test lists packages that are known bad (e.g. bad.go, invalid.go). Pass -e to permit error. The mod_vendor_auto test includes a package that imports a main package, which should be an error. Pass -e to permit error. Updates #59186. Change-Id: I3b63025c3935f55feda1a95151d4c688d0394644 Reviewed-on: https://go-review.googlesource.com/c/go/+/477838 Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 65896f6 commit 3d28e0e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/cmd/go/testdata/script/mod_vendor_auto.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ cp $WORK/modules-1.13.txt $WORK/auto/modules.txt
1111
# An explicit -mod=vendor should force use of the vendor directory.
1212
env GOFLAGS=-mod=vendor
1313

14-
go list -f {{.Dir}} -tags tools all
14+
# Pass -e to permit an error: tools.go imports a main package
15+
# "example.com/printversion".
16+
# TODO(#59186): investigate why it didn't fail without -e.
17+
go list -f {{.Dir}} -tags tools -e all
1518
stdout '^'$WORK'[/\\]auto$'
1619
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
1720
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
@@ -25,7 +28,7 @@ stderr 'go: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod
2528
# An explicit -mod=mod should force the vendor directory to be ignored.
2629
env GOFLAGS=-mod=mod
2730

28-
go list -f {{.Dir}} -tags tools all
31+
go list -f {{.Dir}} -tags tools -e all
2932
stdout '^'$WORK'[/\\]auto$'
3033
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\][email protected]$'
3134
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
@@ -44,7 +47,7 @@ stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
4447
env GOFLAGS=
4548
go mod edit -go=1.13
4649

47-
go list -f {{.Dir}} -tags tools all
50+
go list -f {{.Dir}} -tags tools -e all
4851
stdout '^'$WORK'[/\\]auto$'
4952
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\][email protected]$'
5053
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
@@ -75,7 +78,7 @@ stdout '^example.com/[email protected] example.com/[email protected]$'
7578
# An explicit -mod=mod should still force the vendor directory to be ignored.
7679
env GOFLAGS=-mod=mod
7780

78-
go list -f {{.Dir}} -tags tools all
81+
go list -f {{.Dir}} -tags tools -e all
7982
stdout '^'$WORK'[/\\]auto$'
8083
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\][email protected]$'
8184
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
@@ -97,7 +100,7 @@ env GOFLAGS=
97100
go mod edit -go=1.14
98101
go mod vendor
99102

100-
go list -f {{.Dir}} -tags tools all
103+
go list -f {{.Dir}} -tags tools -e all
101104
stdout '^'$WORK'[/\\]auto$'
102105
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
103106
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
@@ -120,7 +123,7 @@ rm go.mod
120123
rm vendor/modules.txt
121124

122125
go mod init example.com/auto
123-
go list -f {{.Dir}} -tags tools all
126+
go list -f {{.Dir}} -tags tools -e all
124127
stdout '^'$WORK'[/\\]auto$'
125128
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
126129
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
@@ -130,7 +133,7 @@ stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
130133

131134
cp go.mod.orig go.mod
132135
go mod edit -go=1.14
133-
! go list -f {{.Dir}} -tags tools all
136+
! go list -f {{.Dir}} -tags tools -e all
134137
stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
135138
stderr '^\texample.com/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt'
136139
stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
@@ -141,7 +144,7 @@ stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo
141144
# the go version is 1.13 or earlier.
142145
# An incomplete or missing vendor/modules.txt should resolve the vendored packages...
143146
go mod edit -go=1.13
144-
go list -mod=vendor -f {{.Dir}} -tags tools all
147+
go list -mod=vendor -f {{.Dir}} -tags tools -e all
145148
stdout '^'$WORK'[/\\]auto$'
146149
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
147150
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
@@ -158,7 +161,7 @@ stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo
158161
go mod vendor
159162
cmp $WORK/modules-1.13.txt vendor/modules.txt
160163

161-
go list -mod=vendor -f {{.Dir}} -tags tools all
164+
go list -mod=vendor -f {{.Dir}} -tags tools -e all
162165
stdout '^'$WORK'[/\\]auto$'
163166
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
164167
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
@@ -170,7 +173,7 @@ go mod vendor
170173
cmp $WORK/modules-1.14.txt vendor/modules.txt
171174

172175
# Then, -mod=vendor should kick in automatically and succeed.
173-
go list -f {{.Dir}} -tags tools all
176+
go list -f {{.Dir}} -tags tools -e all
174177
stdout '^'$WORK'[/\\]auto$'
175178
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
176179
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'

src/cmd/go/testdata/script/vendor_import.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Imports
22
env GO111MODULE=off
3-
go list -f '{{.ImportPath}} {{.Imports}}' 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'
3+
4+
# Pass -e to permit errors (e.g. bad.go, invalid.go)
5+
go list -f '{{.ImportPath}} {{.Imports}}' -e 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'
46
cmp stdout want_vendor_imports.txt
57

68
-- want_vendor_imports.txt --

0 commit comments

Comments
 (0)