go 1.14
-- .info --
{"Version":"v1.0.0"}
+-- missingmod.go --
+package missingmod
# Without credentials, downloading a module from a path that requires HTTPS
# basic auth should fail.
env NETRC=$WORK/empty
-! go list all
+! go mod tidy
stderr '^\tserver response: ACCESS DENIED, buddy$'
stderr '^\tserver response: File\? What file\?$'
env GO111MODULE=on
-go get rsc.io/QUOTE
+go get -d
go list -m all
stdout '^rsc.io/quote v1.5.2'
stdout '^rsc.io/QUOTE v1.5.2'
-- go.mod --
module x
+
+-- use.go --
+package use
+
+import _ "rsc.io/QUOTE/QUOTE"
env GO111MODULE=on
# Concurrent builds should succeed, even if they need to download modules.
+go get -d ./x ./y
go build ./x &
go build ./y
wait
# go doc should find module documentation
env GO111MODULE=on
+env GOFLAGS=-mod=mod
[short] skip
# Check when module x is inside GOPATH/src.
# path used in source code, not to the absolute path relative to GOROOT.
cd $GOROOT/src
+env GOFLAGS=
go doc cryptobyte
stdout '// import "golang.org/x/crypto/cryptobyte"'
# (example.com not example.com/something)
env GO111MODULE=on
-go build
+go get -d
-- go.mod --
module x
! 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 all
+go list -m -mod=mod 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
-# Download a module
-go mod download -modcacherw rsc.io/quote
+# Download modules and populate go.sum.
+go get -d -modcacherw
exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod
# 'go mod verify' should fail if we delete a file.
require rsc.io/quote v1.5.2
+-- use.go --
+package use
+
+import _ "rsc.io/quote"
+
-- empty --
env GO111MODULE=on
-go list x
+go get -d x
go list -m all
stdout 'rsc.io/breaker v2.0.0\+incompatible'
# indirect tag should be removed upon seeing direct import.
cp $WORK/tmp/uselang.go x.go
-go list
+go get -d
grep 'rsc.io/quote v1.5.2$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+$' go.mod
env GO111MODULE=on
go mod init m
-go list example.com/notags
+go get -d example.com/notags
go list -m all
stdout '^example.com/notags v0.0.0-20190507143103-cc8cbe209b64$'
+# Populate go.sum
+go mod download
+
# go list should succeed to load a package ending with ".go" if the path does
# not correspond to an existing local file. Listing a pattern ending with
# ".go/" should try to list a package regardless of whether a file exists at the
env GO111MODULE=on
# latest rsc.io/quote should be v1.5.2 not v1.5.3-pre1
-go list
+go get -d
go list -m all
stdout 'rsc.io/quote v1.5.2'
cd $WORK/testdata
go mod init testdata.tld/foo
-# Building a package within that module should resolve its dependencies.
-go build
+# Getting a package within that module should resolve its dependencies.
+go get -d
grep 'rsc.io/quote' go.mod
# Tidying the module should preserve those dependencies.
cd $WORK/_ignored
go mod init testdata.tld/foo
-go build
+go get
grep 'rsc.io/quote' go.mod
go mod tidy
env GO111MODULE=on
+env GOFLAGS=-mod=mod
# modconv uses git directly to examine what old 'go get' would
[!net] skip
[!exec:git] skip
-# go build should populate go.mod from Gopkg.lock
-cp go.mod1 go.mod
-go build
+# go mod init should populate go.mod from Gopkg.lock
+go mod init x
stderr 'copying requirements from Gopkg.lock'
go list -m all
-! stderr 'copying requirements from Gopkg.lock'
-stdout 'rsc.io/sampler v1.0.0'
-
-# go list should populate go.mod from Gopkg.lock
-cp go.mod1 go.mod
-go list
-stderr 'copying requirements from Gopkg.lock'
-go list
-! stderr 'copying requirements from Gopkg.lock'
-go list -m all
stdout 'rsc.io/sampler v1.0.0'
# test dep replacement
go mod init
cmpenv go.mod go.mod.replace
--- go.mod1 --
-module x
-
-- x.go --
package x
replace z v1.0.0 => rsc.io/quote v1.0.0
-require rsc.io/quote v1.0.0
\ No newline at end of file
+require rsc.io/quote v1.0.0
env GO111MODULE=on
+go get -d rsc.io/fortune
go list -f '{{.Target}}' rsc.io/fortune
! stdout fortune@v1
stdout 'fortune(\.exe)?$'
+go get -d rsc.io/fortune/v2
go list -f '{{.Target}}' rsc.io/fortune/v2
! stdout v2
stdout 'fortune(\.exe)?$'
# golang.org/x/internal should be importable from other golang.org/x modules.
go mod edit -module=golang.org/x/anything
-go build .
+go get -d .
# ...and their tests...
go test
stdout PASS
# ...but that should not leak into other modules.
+go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'
# Internal packages in the standard library should not leak into modules.
+go get -d ./fromstd
! go build ./fromstd
stderr 'use of internal package internal/testenv not allowed'
# Dependencies should be able to use their own internal modules...
go mod edit -module=golang.org/notx
-go build ./throughdep
+go get -d ./throughdep
# ... but other modules should not, even if they have transitive dependencies.
+go get -d .
! go build .
stderr 'use of internal package golang.org/x/.* not allowed'
# And transitive dependencies still should not leak.
+go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'
# Replacing an internal module should keep it internal to the same paths.
go mod edit -module=golang.org/notx
go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal
-go build ./throughdep
+go get -d ./throughdep
+go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'
go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal
-go build ./throughdep
+go get -d ./throughdep
+go get -d ./baddep
! go build ./baddep
stderr golang.org[/\\]notx[/\\]useinternal
stderr 'use of internal package golang.org/x/.* not allowed'
env GO111MODULE=on
env GOPROXY=direct
env GOSUMDB=off
+env GOFLAGS=-mod=mod
# Regression test for golang.org/issue/27173: if the user (or go.mod file)
# requests a pseudo-version that does not match both the module path and commit
[short] skip
# list {{.Dir}} shows main module and go.mod but not not-yet-downloaded dependency dir.
-go list -m -f '{{.Path}} {{.Main}} {{.GoMod}} {{.Dir}}' all
+go list -mod=mod -m -f '{{.Path}} {{.Main}} {{.GoMod}} {{.Dir}}' all
stdout '^x true .*[\\/]src[\\/]go.mod .*[\\/]src$'
stdout '^rsc.io/quote false .*[\\/]v1.5.2.mod $'
# list {{.Dir}} shows dependency after download (and go list without -m downloads it)
-go list -f '{{.Dir}}' rsc.io/quote
+go list -mod=mod -f '{{.Dir}}' rsc.io/quote
stdout '.*mod[\\/]rsc.io[\\/]quote@v1.5.2$'
# downloaded dependencies are read-only
# list {{.Dir}} shows replaced directories
cp go.mod2 go.mod
-go list -f {{.Dir}} rsc.io/quote
+go list -mod=mod -f {{.Dir}} rsc.io/quote
go list -m -f '{{.Path}} {{.Version}} {{.Dir}}{{with .Replace}} {{.GoMod}} => {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' all
stdout 'mod[\\/]rsc.io[\\/]quote@v1.5.1'
stdout 'v1.3.0.*mod[\\/]rsc.io[\\/]sampler@v1.3.1 .*[\\/]v1.3.1.mod => v1.3.1.*sampler@v1.3.1 .*[\\/]v1.3.1.mod'
stdout ^math/big
# rsc.io/quote/buggy should be listable as a package
-go list rsc.io/quote/buggy
+go list -mod=mod rsc.io/quote/buggy
# rsc.io/quote/buggy should not be listable as a module
go list -m -e -f '{{.Error.Err}}' nonexist rsc.io/quote/buggy
# go list with path to directory should work
+# populate go.sum
+go get -d
+
env GO111MODULE=off
go list -f '{{.ImportPath}}' $GOROOT/src/math
stdout ^math$
-- x.go --
package x
+
+import _ "rsc.io/quote"
# For a while, (*modfetch.codeRepo).Stat was not checking for a go.mod file,
# which would produce a hard error at the subsequent call to GoMod.
-go list all
+go get -d
-- go.mod --
module example.com
# module within the module cache.
# Verifies golang.org/issue/29548
-env GO111MODULE=on
-go mod download rsc.io/quote@v1.5.1 rsc.io/quote@v1.5.2
+# Populate go.sum and download dependencies.
+go get -d
+
+# Ensure v1.5.2 is also in the cache so we can list it.
+go mod download rsc.io/quote@v1.5.2
! go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
stderr '^directory ..[/\\]pkg[/\\]mod[/\\]rsc.io[/\\]quote@v1.5.2 outside available modules$'
require rsc.io/quote v1.5.2
replace rsc.io/quote => rsc.io/quote v1.5.1
+
+-- use.go --
+package use
+
+import _ "rsc.io/quote"
env GO111MODULE=on
+# Populate go.sum
+go list -m -mod=mod all
+
+# Check for upgrades.
go list -m -u all
stdout 'rsc.io/quote v1.2.0 \[v1\.5\.2\]'
# Try listing a package that imports a package
# in a module without a requirement.
go mod edit -droprequire example.com/badchain/a
-! go list m/use
+! go list -mod=mod m/use
cmp stderr list-missing-expected
-! go list -test m/testuse
+! go list -mod=mod -test m/testuse
cmp stderr list-missing-test-expected
-- go.mod.orig --
# Unknown lines should be ignored in dependency go.mod files.
-env GO111MODULE=on
-go list -m all
+go list -m -mod=mod all
# ... and in replaced dependency go.mod files.
cp go.mod go.mod.usesub
-go list -m all
+go list -m -mod=mod all
# ... but not in the main module.
cp go.mod.bad go.mod
-! go list -m all
+! go list -m -mod=mod all
stderr 'unknown directive: hello'
-- go.mod --
stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt'
! grep rsc.io/badzip go.mod
-# TODO(golang.org/issue/31730): 'go build' should print the error below if the
-# requirement is not present.
go mod edit -require rsc.io/badzip@v1.0.0
-! go build rsc.io/badzip
+! go build -mod=mod rsc.io/badzip
stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt'
-- go.mod --
env GO111MODULE=on
-! go list -deps use.go
+! 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.mod --
cd x
go mod edit -require=rsc.io/quote@v1.5.2
go mod edit -replace=rsc.io/quote@v1.5.2=rsc.io/quote@v1.0.0
+go mod tidy # populate go.sum
# Build a binary and ensure that it can output its own debug info.
# The debug info should be accessible before main starts (golang.org/issue/29628).
# v2 import should use a downloaded module
# both without an explicit go.mod entry ...
cp tmp/use_v2.go x.go
+go get -d .
go list -deps -f {{.Dir}}
stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
# module, but not should not include test dependencies of packages imported only
# by other root patterns.
+env GOFLAGS=-mod=mod
cp go.mod go.mod.orig
go list -deps all x/otherroot
chmod 0604 go.sum
go mod edit -module=golang.org/issue/34634
-go build .
+go get -d
cmp go.mod go.mod.want
cmp go.sum go.sum.want
env GO111MODULE=on
+# Populate go.sum.
+# TODO(golang.org/issue/41297): we shouldn't need go.sum. None of the commands
+# below depend on the build list.
+go mod download
+
go list -m -versions rsc.io/quote
stdout '^rsc.io/quote v1.0.0 v1.1.0 v1.2.0 v1.2.1 v1.3.0 v1.4.0 v1.5.0 v1.5.1 v1.5.2 v1.5.3-pre1$'
-- go.mod --
module x
require rsc.io/quote v1.0.0
+
+-- use.go --
+package use
+
+import _ "rsc.io/quote"
cp go.mod go.mod.orig
# Make sure the test builds without replacement.
-go build -o a1.exe .
+go build -mod=mod -o a1.exe .
exec ./a1.exe
stdout 'Don''t communicate by sharing memory'
# 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/v3@v3.1.0=./local/rsc.io/quote/v3
-go build -o a5.exe ./usenewmodule
+go build -mod=mod -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
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
cmp go.mod go.mod.orig
# 'go list' should resolve imports using replacements.
+go get -d
go list all
stdout 'example.com/a/b$'
stdout 'example.com/x/v3$'
# With the selected version excluded, commands that load only modules should
# drop the excluded module.
-go list -m all
+go list -m -mod=mod all
stderr '^go: dropping requirement on excluded version rsc.io/sampler v1\.99\.99$'
stdout '^x$'
! stdout '^rsc.io/sampler'
# from the next-highest version.
cp go.mod.orig go.mod
-go list -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all
+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 $'
! stdout '^rsc.io/sampler v1.99.99'
# build with newer version available
cp go.mod2 go.mod
-go list -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all
+go list -mod=mod -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all
stderr '^go: dropping requirement on excluded version rsc.io/quote v1\.5\.1$'
stdout 'rsc.io/quote v1.5.2'
# build with excluded newer version
cp go.mod3 go.mod
-go list -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all
+go list -mod=mod -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all
! stderr '^go: dropping requirement'
stdout 'rsc.io/quote v1.5.1'
# Control case: verify that go.mod.tidy is actually tidy.
cp go.mod.tidy go.mod
-go list all
+go list -mod=mod all
cmp go.mod go.mod.tidy
# "// indirect" comments should be removed if direct dependencies are seen.
# changes.
cp go.mod.indirect go.mod
-go list all
+go list -mod=mod all
cmp go.mod go.mod.tidy
# "// indirect" comments should be added if appropriate.
# A missing "go" version directive should be added.
# However, that should not remove other redundant requirements.
cp go.mod.nogo go.mod
-go list all
+go list -mod=mod all
cmpenv go.mod go.mod.currentgo
cp go.mod go.mod.orig
+# Populate go.sum.
+go mod download
+
# 'go list pkg' does not report an error when a retracted version is used.
go list -e -f '{{if .Error}}{{.Error}}{{end}}' ./use
! stdout .
# Importing a package from a module with a retracted latest version will
# select the latest non-retracted version.
-go list ./use_self_prev
+go get -d ./use_self_prev
go list -m example.com/retract/self/prev
stdout '^example.com/retract/self/prev v1.1.0$'
exists $GOPATH/pkg/mod/cache/download/example.com/retract/self/prev/@v/v1.9.0.mod
# If the latest unretracted version of a module is replaced, 'go list' should
# obtain retractions from the replacement.
+# Populate go.sum.
+go get -d
+
# The latest version, v1.9.0, is not available on the proxy.
! go list -m -retracted example.com/retract/missingmod
stderr '^go list -m: loading module retractions: example.com/retract/missingmod@v1.9.0:.*404 Not Found$'
go list -m -retracted -f '{{if .Replace}}replaced{{end}}' example.com/retract
! stdout .
go mod edit -replace example.com/retract@v1.0.0-good=example.com/retract@v1.0.0-bad
-go list -m -retracted -f '{{range .Retracted}}{{.}}{{end}}' example.com/retract
+go list -m -mod=mod -retracted -f '{{range .Retracted}}{{.}}{{end}}' example.com/retract
stdout '^bad$'
-go list -m -retracted -f '{{with .Replace}}{{range .Retracted}}{{.}}{{end}}{{end}}' example.com/retract
+go list -m -mod=mod -retracted -f '{{with .Replace}}{{range .Retracted}}{{.}}{{end}}{{end}}' example.com/retract
stdout '^bad$'
-- go.mod --
example.com/retract v1.0.0-good
example.com/retract/missingmod v1.0.0
)
+-- use.go --
+package use
+
+import (
+ _ "example.com/retract"
+ _ "example.com/retract/missingmod"
+)
-- missingmod-v1.0.0/go.mod --
module example.com/retract/missingmod
# When we attempt to resolve an import that doesn't exist, we should not save
# hashes for downloaded modules.
# Verifies golang.org/issue/36260.
-go list -e -tags=ignore ./noexist
+# TODO(golang.org/issue/26603): use 'go mod tidy -e' when implemented.
+go list -e -mod=mod -tags=ignore ./noexist
! exists go.sum
# When an import is resolved successfully, we should only save hashes for
# the module that provides the package, not for other modules looked up.
# Verifies golang.org/issue/31580.
-go list ./exist
+go get -d ./exist
grep '^example.com/join v1.1.0 h1:' go.sum
! grep '^example.com/join/subpkg' go.sum
cp go.sum go.list.sum
# Should use the checksum database to validate new go.sum lines,
# but not need to fetch any new data from the proxy.
rm go.sum
-go list -x rsc.io/quote
+go list -mod=mod -x rsc.io/quote
! stderr github
! stderr proxy.golang.org/rsc.io/quote
stderr sum.golang.org/tile
env TESTGOPROXY404=1
go clean -modcache
rm go.sum
-go list -x rsc.io/quote
+go list -mod=mod -x rsc.io/quote
stderr 'proxy.golang.org.*404 testing'
stderr github.com/rsc
cmp go.sum saved.sum
env GO111MODULE=on
[!symlink] skip
-# 'go list' should resolve modules of imported packages.
+# 'go get -d' should resolve modules of imported packages.
+go get -d
go list -deps -f '{{.Module}}' .
stdout golang.org/x/text
+go get -d ./subpkg
go list -deps -f '{{.Module}}' ./subpkg
stdout golang.org/x/text
# Create a copy of the module using symlinks in src/links.
mkdir links
symlink links/go.mod -> $GOPATH/src/go.mod
+symlink links/go.sum -> $GOPATH/src/go.sum
symlink links/issue.go -> $GOPATH/src/issue.go
mkdir links/subpkg
symlink links/subpkg/issue.go -> $GOPATH/src/subpkg/issue.go
env GO111MODULE=on
+env GOFLAGS=-mod=mod
[short] skip
# TODO(bcmills): Convert the 'go test' calls below to 'go list -test' once 'go
env GO111MODULE=on
+env GOFLAGS=-mod=mod
[short] skip
# golang.org/issue/30166: 'go mod tidy' should not crash if a replaced module is
[short] skip
# Initially, we are at v1.0.0 for all dependencies.
+go get -d
cp go.mod go.mod.orig
go list -m all
stdout '^patch.example.com/direct v1.0.0'
env GOPROXY=direct
cd empty
-! go list launchpad.net/gocheck
+! go get -d launchpad.net/gocheck
stderr '"bzr": executable file not found'
cd ..
# 1.11 used to give the cryptic error "cannot find module for path" here, but
# only for a main package.
cd main
-! go build
+! go build -mod=mod
stderr '"bzr": executable file not found'
cd ..
env GO111MODULE=on
[short] skip
+# Populate go.mod and go.sum.
+go mod tidy
+
# initial conditions: using sampler v1.3.0, not listed in go.mod.
go list -deps
stdout rsc.io/sampler
# Packages below module root should not be mentioned in go.sum.
rm go.sum
go mod edit -droprequire rsc.io/quote
-go list rsc.io/quote/buggy # re-resolves import path and updates go.mod
+go get -d rsc.io/quote/buggy
grep '^rsc.io/quote v1.5.2/go.mod ' go.sum
! grep buggy go.sum
env GO111MODULE=on
[short] skip
+# Populate go.sum.
+go mod tidy
+
go list -test all
stdout rsc.io/quote
stdout golang.org/x/text/language
# 'go list' and other commands with build flags should work.
# They should update the alternate go.mod when a dependency is missing.
go mod edit -droprequire rsc.io/quote
-go list .
+go list -mod=mod .
grep rsc.io/quote go.alt.mod
-go build -n .
-go test -n .
+go build -n -mod=mod .
+go test -n -mod=mod .
go get -d rsc.io/quote
[short] skip
# Check that 'go version' and 'go version -m' work on a binary built in module mode.
+go get -d rsc.io/fortune
go build -o fortune.exe rsc.io/fortune
go version fortune.exe
stdout '^fortune.exe: .+'
[short] skip
go mod download example.com/printversion@v0.1.0 example.com/printversion@v1.0.0
-
+go get -d example.com/printversion@v0.1.0
go install example.com/printversion
go run example.com/printversion