Install from @latest, retract v0.0.1, print a go-installed binary's version (closes #116)
check / check (push) Waiting to run
check / check (push) Waiting to run
README "Install" now leads with go install ...@latest: until 1.0 each release is a v0.0.N tag on main's tip, so @latest gives that tip once it has passed the build. It also says what @main and v0.0.1 give and how to check an installed binary. go.mod retracts v0.0.1, the early build without a database. sfdupes --version printed "dev" for every go-installed binary, since only the linker set Version. When the linker sets none, it now prints the main module's version from runtime/debug.ReadBuildInfo; "dev" is left only when neither is known. Version is now empty by default. The retraction takes effect only once a release carrying it is the newest. Model: opus-5-5
This commit is contained in:
+38
-1
@@ -9,6 +9,7 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -714,6 +715,8 @@ func TestRunVersion(t *testing.T) {
|
||||
|
||||
// README §Subcommands: the version is one line on stdout, with
|
||||
// nothing on stderr, and exits 0.
|
||||
info, _ := debug.ReadBuildInfo()
|
||||
|
||||
for _, arg := range []string{"--version", "-v"} {
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
@@ -722,7 +725,7 @@ func TestRunVersion(t *testing.T) {
|
||||
t.Errorf("run(%s) = %d, want %d", arg, code, exitOK)
|
||||
}
|
||||
|
||||
want := "sfdupes " + Version + "\n"
|
||||
want := "sfdupes " + buildVersion(Version, info) + "\n"
|
||||
if got := stdout.String(); got != want {
|
||||
t.Errorf("run(%s) stdout = %q, want %q", arg, got, want)
|
||||
}
|
||||
@@ -733,6 +736,40 @@ func TestRunVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// README "Install": the linker's version wins; otherwise the main
|
||||
// module's version that Go recorded; "dev" when neither is known.
|
||||
tagged := &debug.BuildInfo{Main: debug.Module{Version: "v0.0.2"}}
|
||||
pseudo := &debug.BuildInfo{Main: debug.Module{
|
||||
Version: "v1.0.0-rc2.0.20261016120000-4e4a94d0c2a1",
|
||||
}}
|
||||
devel := &debug.BuildInfo{Main: debug.Module{Version: "(devel)"}}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
linker string
|
||||
info *debug.BuildInfo
|
||||
want string
|
||||
}{
|
||||
{"linker set", "v0.0.2-3-g4e4a94d", tagged, "v0.0.2-3-g4e4a94d"},
|
||||
{"linker set, no build info", "4e4a94d", nil, "4e4a94d"},
|
||||
{"build info with a tag", "", tagged, "v0.0.2"},
|
||||
{"build info with a pseudo-version", "", pseudo,
|
||||
"v1.0.0-rc2.0.20261016120000-4e4a94d0c2a1"},
|
||||
{"(devel)", "", devel, "dev"},
|
||||
{"no build info", "", nil, "dev"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
if got := buildVersion(c.linker, c.info); got != c.want {
|
||||
t.Errorf("%s: buildVersion(%q, ...) = %q, want %q",
|
||||
c.name, c.linker, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunVersionWriteFailureIsFatal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user