Kevin Herro has uploaded this change for review.
cmd/go: in tests, reduce usage of -mod=mod and populate go.sum files
This change addresses two broad issues in the cmd/go integration tests:
First, this change makes the tests more idiomatic. If something is
missing from go.mod or go.sum, we should run go get -d, go mod tidy, or
go mod download first.
Second, this change fills in missing sums without modifying go.mod in
tests that include literal go.sum files.
Fixes #41302
Change-Id: I7b97a1d79bc8e739a3df3869cb60f6586a40cb03
---
M src/cmd/go/testdata/script/mod_doc.txt
M src/cmd/go/testdata/script/mod_download.txt
M src/cmd/go/testdata/script/mod_load_badzip.txt
M src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt
M src/cmd/go/testdata/script/mod_replace.txt
M src/cmd/go/testdata/script/mod_replace_gopkgin.txt
M src/cmd/go/testdata/script/mod_require_exclude.txt
7 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/src/cmd/go/testdata/script/mod_doc.txt b/src/cmd/go/testdata/script/mod_doc.txt
index 595ad67..ceb9058 100644
--- a/src/cmd/go/testdata/script/mod_doc.txt
+++ b/src/cmd/go/testdata/script/mod_doc.txt
@@ -1,10 +1,10 @@
# go doc should find module documentation
env GO111MODULE=on
-env GOFLAGS=-mod=mod
[short] skip
# Check when module x is inside GOPATH/src.
+go get -d ./y
go doc y
stdout 'Package y is.*alphabet'
stdout 'import "x/y"'
@@ -12,6 +12,7 @@
stdout 'Package y is.*alphabet'
! go doc quote.Hello
stderr 'doc: symbol quote is not a type' # because quote is not in local cache
+go get -d rsc.io/quote
go list rsc.io/quote # now it is
go doc quote.Hello
stdout 'Hello returns a greeting'
@@ -39,8 +40,10 @@
# Check that a sensible error message is printed when a package is not found.
env GOPROXY=off
+! go get example.com/hello
+stderr 'go get example.com/hello: module lookup disabled by GOPROXY=off'
! go doc example.com/hello
-stderr '^doc: cannot find module providing package example.com/hello: module lookup disabled by GOPROXY=off$'
+stderr '^doc: no required module provides package example.com/hello; to add it:\n\tgo get example.com/hello$'
# When in a module with a vendor directory, doc should use the vendored copies
# of the packages. 'std' and 'cmd' are convenient examples of such modules.
diff --git a/src/cmd/go/testdata/script/mod_download.txt b/src/cmd/go/testdata/script/mod_download.txt
index 8a9faff..31e13d5 100644
--- a/src/cmd/go/testdata/script/mod_download.txt
+++ b/src/cmd/go/testdata/script/mod_download.txt
@@ -46,10 +46,11 @@
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
# module loading will page in the info and mod files
-go list -m -mod=mod all
+go mod download
+go list -m all
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
-! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
# download will fetch and unpack the zip file
go mod download
diff --git a/src/cmd/go/testdata/script/mod_load_badzip.txt b/src/cmd/go/testdata/script/mod_load_badzip.txt
index 65374d2..52651ae 100644
--- a/src/cmd/go/testdata/script/mod_load_badzip.txt
+++ b/src/cmd/go/testdata/script/mod_load_badzip.txt
@@ -6,8 +6,9 @@
! grep rsc.io/badzip go.mod
go mod edit -require rsc.io/bad...@v1.0.0
-! go build -mod=mod rsc.io/badzip
+! go get -d rsc.io/badzip
stderr 'zip for rsc.io/bad...@v1.0.0 has unexpected file rsc.io/bad...@v1.0.0.txt'
+! go build rsc.io/badzip
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt b/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt
index 9c250e7..310487b 100644
--- a/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt
+++ b/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt
@@ -1,7 +1,21 @@
env GO111MODULE=on
-! go list -mod=mod -deps use.go
-stderr '^use.go:4:2: package example.com/missingpkg/deprecated provided by example.com/missingpkg at latest version v1.0.0 but not at required version v1.0.1-beta$'
+# 'go get -d' should report errors on transitively imported packages.
+! go get -d
+stderr -count=6 '^.'
+stderr '^go: downloading example.com v1.0.0$'
+stderr '^go: downloading example.com/usemissingpre v1.0.0$'
+stderr '^go: downloading example.com/missingpkg v1.0.0$'
+stderr '^go: downloading example.com/missingpkg v1.0.1-beta$'
+stderr 'm imports\n\texample.com/missingpkg/deprecated: cannot find module providing package example.com/missingpkg/deprecated'
+
+! go list -deps use.go
+stdout -count=3 '^.'
+stdout '^example.com/missingpkg/deprecated$'
+stdout '^example.com/usemissingpre$'
+stdout '^command-line-arguments$'
+stderr '^use.go:4:2: no required module provides package example.com/missingpkg/deprecated; to add it:\n\tgo get example.com/missingpkg/deprecated$'
+stderr '^use.go:5:2: no required module provides package example.com/usemissingpre; to add it:\n\tgo get example.com/usemissingpre$'
-- go.mod --
module m
diff --git a/src/cmd/go/testdata/script/mod_replace.txt b/src/cmd/go/testdata/script/mod_replace.txt
index dc9667f..2bde6e1 100644
--- a/src/cmd/go/testdata/script/mod_replace.txt
+++ b/src/cmd/go/testdata/script/mod_replace.txt
@@ -4,7 +4,8 @@
cp go.mod go.mod.orig
# Make sure the test builds without replacement.
-go build -mod=mod -o a1.exe .
+go mod download
+go build -o a1.exe .
exec ./a1.exe
stdout 'Don''t communicate by sharing memory'
@@ -32,7 +33,8 @@
# Modules that do not (yet) exist upstream can be replaced too.
cp go.mod.orig go.mod
go mod edit -replace=not-rsc.io/quote/v...@v3.1.0=./local/rsc.io/quote/v3
-go build -mod=mod -o a5.exe ./usenewmodule
+go get -d not-rsc.io/quote/v...@v3.1.0
+go build -o a5.exe ./usenewmodule
! stderr 'finding not-rsc.io/quote/v3'
grep 'not-rsc.io/quote/v3 v3.1.0' go.mod
exec ./a5.exe
diff --git a/src/cmd/go/testdata/script/mod_replace_gopkgin.txt b/src/cmd/go/testdata/script/mod_replace_gopkgin.txt
index d24f37b..3fb9230 100644
--- a/src/cmd/go/testdata/script/mod_replace_gopkgin.txt
+++ b/src/cmd/go/testdata/script/mod_replace_gopkgin.txt
@@ -11,12 +11,12 @@
env GO111MODULE=on
env GOPROXY=direct
env GOSUMDB=off
-env GOFLAGS=-mod=mod
# Replacing gopkg.in/[…].vN with a repository with a root go.mod file
# specifying […].vN and a compatible version should succeed, even if
# the replacement path is not a gopkg.in path.
cd 4-to-4
+go get -d ./...
go list -m gopkg.in/src-d/go-git.v4
# Previous versions of the "go" command accepted v0 and v1 pseudo-versions
@@ -24,18 +24,23 @@
# As a special case, we continue to accept those.
cd ../4-to-0
+go get -d ./...
go list -m gopkg.in/src-d/go-git.v4
cd ../4-to-1
+go get -d ./...
go list -m gopkg.in/src-d/go-git.v4
cd ../4-to-incompatible
+go get -d ./...
go list -m gopkg.in/src-d/go-git.v4
# A mismatched gopkg.in path should not be able to replace a different major version.
cd ../3-to-gomod-4
+! go get -d ./...
+stderr '^go: gopkg\.in/src-d/go-git\.v3@v3\.2\.0 \(replaced by gopkg\.in/src-d/go-git\.v3@v3\.0\.0-20190801152248-0d1a009cbb60\): version "v3\.0\.0-20190801152248-0d1a009cbb60" invalid: go\.mod has non-\.\.\.\.v3 module path "gopkg\.in/src-d/go-git\.v4" at revision 0d1a009cbb60$'
! go list -m gopkg.in/src-d/go-git.v3
-stderr '^go list -m: gopkg\.in/src-d/go-git\.v3@v3\.2\.0 \(replaced by gopkg\.in/src-d/go-git\.v3@v3\.0\.0-20190801152248-0d1a009cbb60\): version "v3\.0\.0-20190801152248-0d1a009cbb60" invalid: go\.mod has non-\.\.\.\.v3 module path "gopkg\.in/src-d/go-git\.v4" at revision 0d1a009cbb60$'
+stderr '^go list -m: gopkg\.in/src-d/go-git\.v3@v3\.2\.0 \(replaced by gopkg\.in/src-d/go-git\.v3@v3\.0\.0-20190801152248-0d1a009cbb60\): missing go\.sum entry; to add it:\n\tgo mod download gopkg.in/src-d/go-git\.v3$'
-- 4-to-4/go.mod --
module golang.org/issue/34254
diff --git a/src/cmd/go/testdata/script/mod_require_exclude.txt b/src/cmd/go/testdata/script/mod_require_exclude.txt
index 5b6143d..a9395a8 100644
--- a/src/cmd/go/testdata/script/mod_require_exclude.txt
+++ b/src/cmd/go/testdata/script/mod_require_exclude.txt
@@ -20,8 +20,9 @@
# With the selected version excluded, commands that load only modules should
# drop the excluded module.
-go list -m -mod=mod all
+go mod download
stderr '^go: dropping requirement on excluded version rsc.io/sampler v1\.99\.99$'
+go list -m all
stdout '^x$'
! stdout '^rsc.io/sampler'
cmp go.mod go.moddrop
@@ -29,7 +30,9 @@
# With the latest version excluded, 'go list' should resolve needed packages
# from the next-highest version.
+# here!!
cp go.mod.orig go.mod
+# go mod download rsc.io/sam...@1.99.99
go list -mod=mod -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all
stderr '^go: dropping requirement on excluded version rsc.io/sampler v1\.99\.99$'
stdout '^x $'
To view, visit change 311189. To unsubscribe, or for help writing mail filters, visit settings.