Commit e3f15e3b authored by Russ Cox's avatar Russ Cox

cmd/go: convert even more module tests to scripts

Change-Id: Iba185e00e9df2462e9089566053f6c64e24a6a92
Reviewed-on: https://go-review.googlesource.com/124698Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
parent 4d5bf3cc
This diff is collapsed.
env GO111MODULE=on
# explicit get should report errors about bad names
! go get appengine
stderr 'cannot find module providing package appengine'
! go get x/y.z
stderr 'cannot find module providing package x/y.z'
# build should skip over appengine imports
! go build
! stderr appengine
stderr 'cannot find module providing package nonexistent.rsc.io'
-- go.mod --
module x
-- x.go --
package x
import _ "appengine"
import _ "nonexistent.rsc.io" // domain does not exist
env GO111MODULE=on
! go get rsc.io/badfile1 rsc.io/badfile2 rsc.io/badfile3 rsc.io/badfile4 rsc.io/badfile5
! stderr 'unzip.*badfile1'
stderr 'unzip.*badfile2/@v/v1.0.0.zip:.*malformed file path "☺.go": invalid char ''☺'''
stderr 'unzip.*badfile3/@v/v1.0.0.zip: malformed file path "x\?y.go": invalid char ''\?'''
stderr 'unzip.*badfile4/@v/v1.0.0.zip: case-insensitive file name collision: "x/Y.go" and "x/y.go"'
stderr 'unzip.*badfile5/@v/v1.0.0.zip: case-insensitive file name collision: "x/y" and "x/Y"'
-- go.mod --
module x
env GO111MODULE=on
go get rsc.io/QUOTE
go list -m all
stdout '^rsc.io/quote v1.5.2'
stdout '^rsc.io/QUOTE v1.5.2'
go list -f 'DIR {{.Dir}} DEPS {{.Deps}}' rsc.io/QUOTE/QUOTE
stdout 'DEPS.*rsc.io/quote'
stdout 'DIR.*!q!u!o!t!e'
-- go.mod --
module x
# Use download cache for -getmode=local.
env GO111MODULE=on
env GOPATH=$WORK/gopath1
cd $WORK/x
! go list -getmode=local all
go list all
go list -getmode=local all
env GOPROXY=file:///nonexist
go list -getmode=local all
grep v1.5.1 $GOPATH/src/mod/cache/download/rsc.io/quote/@v/list
# Use download cache as file:/// proxy.
env GOPATH=$WORK/gopath2
env GOPROXY=file:///nonexist
! go list -getmode=local all
! go list all
env GOPROXY=file://$WORK/gopath1/src/mod/cache/download
! go list -getmode=local all
go list all
grep v1.5.1 $GOPATH/src/mod/cache/download/rsc.io/quote/@v/list
-- $WORK/x/go.mod --
module x
require rsc.io/quote v1.5.1
-- $WORK/x/x.go --
package x
import _ "rsc.io/quote"
env GO111MODULE=on
# 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
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'
-- go.mod1 --
module x
-- x.go --
package x
-- Gopkg.lock --
[[projects]]
name = "rsc.io/sampler"
version = "v1.0.0"
env GO111MODULE=on
# list {{.Dir}} shows main module but not not-yet-downloaded dependency
go list -m -f '{{.Path}} {{.Main}} {{.Dir}}' all
stdout '^x true .*[\\/]src$'
stdout '^rsc.io/quote false $'
# list {{.Dir}} shows dependency after download
go list -f {{.Dir}} rsc.io/quote
stdout 'mod[\\/]rsc.io[\\/]quote@v1.5.2'
# downloaded dependencies are read-only
exists -readonly $GOPATH/src/mod/rsc.io/quote@v1.5.2
exists -readonly $GOPATH/src/mod/rsc.io/quote@v1.5.2/buggy
# go clean -modcache can delete read-only dependencies
go clean -modcache
! exists $GOPATH/src/mod/rsc.io/quote@v1.5.2
# list {{.Dir}} shows replaced directories
cp go.mod2 go.mod
go list -f {{.Dir}} rsc.io/quote
go list -m -f '{{.Path}} {{.Version}} {{.Dir}}{{with .Replace}} => {{.Version}} {{.Dir}}{{end}}' all
stdout 'mod[\\/]rsc.io[\\/]quote@v1.5.1'
stdout 'v1.3.0.*mod[\\/]rsc.io[\\/]sampler@v1.3.1 => v1.3.1.*sampler@v1.3.1'
# list std should work
go list std
stdout ^math/big
# rsc.io/quote/buggy should be listable as a package
go list 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
stdout '^module "nonexist" is not a known dependency'
stdout '^module "rsc.io/quote/buggy" is not a known dependency'
! go list -m nonexist rsc.io/quote/buggy
stderr '^go list -m nonexist: module "nonexist" is not a known dependency'
stderr '^go list -m rsc.io/quote/buggy: module "rsc.io/quote/buggy" is not a known dependency'
# Module loader does not interfere with list -e (golang.org/issue/24149).
go list -e -f '{{.Error.Err}}' database
stdout 'no Go files in '
! go list database
stderr 'no Go files in '
-- go.mod --
module x
require rsc.io/quote v1.5.2
-- go.mod2 --
module x
require rsc.io/quote v1.5.1
replace rsc.io/sampler v1.3.0 => rsc.io/sampler v1.3.1
-- x.go --
package x
import _ "rsc.io/quote"
env GO111MODULE=on
# With good go.sum, verify succeeds by avoiding download.
cp go.sum.good go.sum
go mod -verify
! exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With bad go.sum, verify succeeds by avoiding download.
cp go.sum.bad go.sum
go mod -verify
! exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With bad go.sum, sync (which must download) fails.
# Even if the bad sum is in the old legacy go.modverify file.
rm go.sum
cp go.sum.bad go.modverify
! go mod -sync
stderr 'checksum mismatch'
! exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With good go.sum, sync works (and moves go.modverify to go.sum).
rm go.sum
cp go.sum.good go.modverify
go mod -sync
exists $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
exists $GOPATH/src/mod/rsc.io/quote@v1.1.0/quote.go
! exists go.modverify
# go.sum should have the new checksum for go.mod
grep '^rsc.io/quote v1.1.0/go.mod ' go.sum
# verify should work
go mod -verify
# basic loading of module graph should detect incorrect go.mod files.
go mod -graph
cp go.sum.bad2 go.sum
! go mod -graph
stderr 'go.mod: checksum mismatch'
# go.sum should be created and updated automatically.
rm go.sum
go mod -graph
exists go.sum
grep '^rsc.io/quote v1.1.0/go.mod ' go.sum
! grep '^rsc.io/quote v1.1.0 ' go.sum
go mod -sync
grep '^rsc.io/quote v1.1.0/go.mod ' go.sum
grep '^rsc.io/quote v1.1.0 ' go.sum
# sync should ignore missing ziphash; verify should not
rm $GOPATH/src/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash
go mod -sync
! go mod -verify
# Packages below module root should not be mentioned in go.sum.
rm go.sum
go mod -droprequire rsc.io/quote
go list rsc.io/quote/buggy # re-resolves import path and updates go.mod
grep '^rsc.io/quote v1.5.2/go.mod ' go.sum
! grep buggy go.sum
# non-existent packages below module root should not be mentioned in go.sum
go mod -droprequire rsc.io/quote
! go list rsc.io/quote/morebuggy
grep '^rsc.io/quote v1.5.2/go.mod ' go.sum
! grep buggy go.sum
-- go.mod --
module x
require rsc.io/quote v1.1.0
-- x.go --
package x
import _ "rsc.io/quote"
-- go.sum.good --
rsc.io/quote v1.1.0 h1:a3YaZoizPtXyv6ZsJ74oo2L4/bwOSTKMY7MAyo4O/0c=
-- go.sum.bad --
rsc.io/quote v1.1.0 h1:a3YaZoizPtXyv6ZsJ74oo2L4/bwOSTKMY7MAyo4O/1c=
-- go.sum.bad2 --
rsc.io/quote v1.1.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl1=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment