# retract must not be used without a module directive.
! go list -m all
stderr 'go.mod:3: no module directive found, so retract cannot be used$'

# Commands that update go.mod should fix non-canonical versions in
# retract directives.
# Verifies #44494.
go mod edit -module=rsc.io/quote/v2
! go list -m all
stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$'
go mod tidy
go list -m all
cmp go.mod go.mod.want

# If a retracted version doesn't match the module's major version suffx,
# an error should be reported.
! go mod edit -retract=v3.0.1
stderr '^go mod: -retract=v3.0.1: version "v3.0.1" invalid: should be v2, not v3$'
cp go.mod.mismatch-v2 go.mod
! go list -m all
stderr 'go.mod:3: retract rsc.io/quote/v2: version "v3.0.1" invalid: should be v2, not v3$'

cp go.mod.mismatch-v1 go.mod
! go list -m all
stderr 'go.mod:3: retract rsc.io/quote: version "v3.0.1" invalid: should be v0 or v1, not v3$'

-- go.mod --
go 1.16

retract latest
-- go.mod.want --
go 1.16

retract v2.0.1

module rsc.io/quote/v2
-- go.mod.mismatch-v2 --
go 1.16

retract v3.0.1

module rsc.io/quote/v2
-- go.mod.mismatch-v1 --
go 1.16

retract v3.0.1

module rsc.io/quote
