env GO111MODULE=on
[short] skip

# downgrade sampler should downgrade quote
cp go.mod.orig go.mod
go get rsc.io/sampler@v1.0.0
go list -m all
stdout 'rsc.io/quote v1.4.0'
stdout 'rsc.io/sampler v1.0.0'

# downgrade sampler away should downgrade quote further
go get rsc.io/sampler@none
go list -m all
stdout 'rsc.io/quote v1.3.0'

# downgrade should report inconsistencies and not change go.mod
go get rsc.io/quote@v1.5.1
go list -m all
stdout 'rsc.io/quote v1.5.1'
stdout 'rsc.io/sampler v1.3.0'
! go get rsc.io/sampler@v1.0.0 rsc.io/quote@v1.5.2 golang.org/x/text@none
stderr 'go get: inconsistent versions:\n\trsc.io/quote@v1.5.2 requires golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c \(not golang.org/x/text@none\), rsc.io/sampler@v1.3.0 \(not rsc.io/sampler@v1.0.0\)'
go list -m all
stdout 'rsc.io/quote v1.5.1'
stdout 'rsc.io/sampler v1.3.0'

# go get -u args should limit upgrades
cp go.mod.empty go.mod
go get -u rsc.io/quote@v1.4.0 rsc.io/sampler@v1.0.0
go list -m all
stdout 'rsc.io/quote v1.4.0'
stdout 'rsc.io/sampler v1.0.0'
! stdout golang.org/x/text

# downgrading away quote should also downgrade away latemigrate/v2,
# since there are no older versions. v2.0.0 is incompatible.
cp go.mod.orig go.mod
go list -m -versions example.com/latemigrate/v2
stdout v2.0.0 # proxy may serve incompatible versions
go get rsc.io/quote@none
go list -m all
! stdout 'example.com/latemigrate/v2'

-- go.mod.orig --
module x
require (
	rsc.io/quote v1.5.1
	example.com/latemigrate/v2 v2.0.1
)
-- go.mod.empty --
module x
-- x.go --
package x
