Report the module version for a go install build (closes #18)
check / check (push) Failing after 1s
check / check (push) Failing after 1s
--version printed "dev" for any binary not built with make build, so a user running a go install build could not say what version they had. resolveVersion now falls back to the module version from runtime/debug.ReadBuildInfo() when the build-time stamp is absent, ignoring the "(devel)" of a local build. The stamped value still wins when present. It takes the build info as an argument, so a test covers the choice without a real build. Model: opus-4-8
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestResolveVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
release := &debug.BuildInfo{Main: debug.Module{Version: "v1.2.3"}}
|
||||
local := &debug.BuildInfo{Main: debug.Module{Version: "(devel)"}}
|
||||
empty := &debug.BuildInfo{}
|
||||
|
||||
t.Run("stamped value wins over build info", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.Equal(t, "v0.1.0", resolveVersion("v0.1.0", release))
|
||||
})
|
||||
|
||||
t.Run("go install reports the module version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.Equal(t, "v1.2.3", resolveVersion(devVersion, release))
|
||||
})
|
||||
|
||||
t.Run("a local build stays dev", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.Equal(t, devVersion, resolveVersion(devVersion, local))
|
||||
})
|
||||
|
||||
t.Run("no version anywhere stays dev", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.Equal(t, devVersion, resolveVersion(devVersion, empty))
|
||||
require.Equal(t, devVersion, resolveVersion(devVersion, nil))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user