# Note that `go test` binaries don't get stamped with versions,
# so the local tests below end up with a "devel" gofumpt version.
env GO_VERSION_TEST=go1.18.29
exec gofumpt foo.go
cmp stdout foo.go.golden
exec gofumpt outdated.go
cmp stdout foo.go.golden
exec gofumpt -extra foo.go
cmp stdout foo.go.golden-extra
exec gofumpt -lang=go1 foo.go
cmp stdout foo.go.golden-lang
exec gofumpt -d nochange.go
! stdout .
exec gofumpt -d foo.go.golden
! stdout .
exec gofumpt -d -extra foo.go.golden-extra
! stdout .
[short] stop 'the rest of this test builds gofumpt binaries'
# We want a published version of gofumpt on the public module proxies,
# because that's the only way that its module version will be included.
# Using a directory replace directive will not work.
# This means that any change in how gofumpt reports its own version
# will require two pull requests, the second one updating the test script.
# We could consider using go-internal/goproxytest, but then we would need to
# manually run something like go-internal/cmd/txtar-addmod reguarly.
# Or teach goproxytest to serve a mock version of gofumpt from its local checkout.
# Either way, both are relatively overkill for now.
# Update this pseudo-version to master from time to time as needed.
env GOBIN=${WORK}/bin
env GOFUMPT_PUBLISHED_VERSION=v0.8.1-0.20250831111522-b5fd2eb6e821
# TODO: update these once the library fix hits master
# gofumpt as the main binary with a real module version.
go install mvdan.cc/gofumpt@${GOFUMPT_PUBLISHED_VERSION}
exec ${GOBIN}/gofumpt foo.go
cmp stdout foo.go.golden-released
# gofumpt as a library with a real module version.
cd ${GOMOD_DIR}/testdata/gofumpt-external
go install .
cd ${WORK}
stdin foo.go
exec ${GOBIN}/gofumpt-external
cmp stdout foo.go.golden-external
-- go.mod --
module test
go 1.16
-- foo.go --
package p
//gofumpt:diagnose
-- outdated.go --
package p
//gofumpt:diagnose v0.1.0
-- nochange.go --
package p
//gofumpt:diagnosefoobar
-- foo.go.golden --
package p
//gofumpt:diagnose version: (devel) (go1.18.29) flags: -lang=go1.16 -modpath=test
-- foo.go.golden-extra --
package p
//gofumpt:diagnose version: (devel) (go1.18.29) flags: -lang=go1.16 -modpath=test -extra
-- foo.go.golden-lang --
package p
//gofumpt:diagnose version: (devel) (go1.18.29) flags: -lang=go1 -modpath=test
-- foo.go.golden-released --
package p
//gofumpt:diagnose version: v0.8.1-0.20250831111522-b5fd2eb6e821 (go1.18.29) flags: -lang=go1.16 -modpath=test
-- foo.go.golden-external --
package p
//gofumpt:diagnose version: v0.8.1-0.20250831111522-b5fd2eb6e821 (go1.18.29) flags: -lang=go1.16 -modpath=