# 'go get pkg' should not upgrade to a retracted version.
cp go.mod.orig go.mod
go mod edit -require example.com/retract/self/prev@v1.1.0
go get example.com/retract/self/prev
go list -m example.com/retract/self/prev
stdout '^example.com/retract/self/prev v1.1.0$'

# 'go get pkg' should not downgrade from a retracted version when no higher
# version is available.
cp go.mod.orig go.mod
go mod edit -require example.com/retract/self/prev@v1.9.0
go get example.com/retract/self/prev
stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$'
stderr '^go: to switch to the latest unretracted version, run:\n\tgo get example.com/retract/self/prev@latest\n$'
go list -m example.com/retract/self/prev
stdout '^example.com/retract/self/prev v1.9.0$'

# 'go get pkg@latest' should downgrade from a retracted version.
cp go.mod.orig go.mod
go mod edit -require example.com/retract/self/prev@v1.9.0
go get example.com/retract/self/prev@latest
go list -m example.com/retract/self/prev
stdout '^example.com/retract/self/prev v1.1.0$'

# 'go get pkg@version' should update to a specific version, even if that
# version is retracted.
cp go.mod.orig go.mod
go get example.com/retract@v1.0.0-bad
stderr '^go: warning: example.com/retract@v1.0.0-bad: retracted by module author: bad$'
go list -m example.com/retract
stdout '^example.com/retract v1.0.0-bad$'

# 'go get -u' should not downgrade from a retracted version when no higher
# version is available.
cp go.mod.orig go.mod
go mod edit -require example.com/retract/self/prev@v1.9.0
go get -u ./use
stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$'
go list -m example.com/retract/self/prev
stdout '^example.com/retract/self/prev v1.9.0$'

# 'go get' should warn if a module needed to build named packages is retracted.
# 'go get' should not warn about unrelated modules.
go get ./empty
! stderr retracted
go get ./use
stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$'

-- go.mod.orig --
module example.com/use

go 1.15

-- use/use.go --
package use

import _ "example.com/retract/self/prev"
-- empty/empty.go --
package empty
