Skip to content

Commit

Permalink
cmd/go: permit "go list" error in some tests
Browse files Browse the repository at this point in the history
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 <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
  • Loading branch information
cherrymui committed Mar 22, 2023
1 parent 65896f6 commit 3d28e0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/cmd/go/testdata/script/mod_vendor_auto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ cp $WORK/modules-1.13.txt $WORK/auto/modules.txt
# An explicit -mod=vendor should force use of the vendor directory.
env GOFLAGS=-mod=vendor

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

go list -f {{.Dir}} -tags tools all
go list -f {{.Dir}} -tags tools -e all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
Expand All @@ -44,7 +47,7 @@ stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
env GOFLAGS=
go mod edit -go=1.13

go list -f {{.Dir}} -tags tools all
go list -f {{.Dir}} -tags tools -e all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
Expand Down Expand Up @@ -75,7 +78,7 @@ stdout '^example.com/printversion@v1.0.0 example.com/version@v1.0.0$'
# An explicit -mod=mod should still force the vendor directory to be ignored.
env GOFLAGS=-mod=mod

go list -f {{.Dir}} -tags tools all
go list -f {{.Dir}} -tags tools -e all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
Expand All @@ -97,7 +100,7 @@ env GOFLAGS=
go mod edit -go=1.14
go mod vendor

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

go mod init example.com/auto
go list -f {{.Dir}} -tags tools all
go list -f {{.Dir}} -tags tools -e all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
Expand All @@ -130,7 +133,7 @@ stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'

cp go.mod.orig go.mod
go mod edit -go=1.14
! go list -f {{.Dir}} -tags tools all
! go list -f {{.Dir}} -tags tools -e all
stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt'
stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
Expand All @@ -141,7 +144,7 @@ stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo
# the go version is 1.13 or earlier.
# An incomplete or missing vendor/modules.txt should resolve the vendored packages...
go mod edit -go=1.13
go list -mod=vendor -f {{.Dir}} -tags tools all
go list -mod=vendor -f {{.Dir}} -tags tools -e all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
Expand All @@ -158,7 +161,7 @@ stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo
go mod vendor
cmp $WORK/modules-1.13.txt vendor/modules.txt

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

# Then, -mod=vendor should kick in automatically and succeed.
go list -f {{.Dir}} -tags tools all
go list -f {{.Dir}} -tags tools -e all
stdout '^'$WORK'[/\\]auto$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/go/testdata/script/vendor_import.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Imports
env GO111MODULE=off
go list -f '{{.ImportPath}} {{.Imports}}' 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'

# Pass -e to permit errors (e.g. bad.go, invalid.go)
go list -f '{{.ImportPath}} {{.Imports}}' -e 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'
cmp stdout want_vendor_imports.txt

-- want_vendor_imports.txt --
Expand Down

0 comments on commit 3d28e0e

Please sign in to comment.