Skip to content

Commit 1e06071

Browse files
sky-xoclaude
andcommitted
fix(cli): fix broken test logic for version fallback case
The condition `wantContain != "" && got != wantContain` was always false when wantContain was empty, meaning the test for empty version fallback never actually ran. - Replace unused wantContain field with checkNotEmpty boolean flag - Remove duplicate TestVersionWithEmptyFallsToDev function - Group var declarations in root.go into single var block 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1131c4c commit 1e06071

2 files changed

Lines changed: 15 additions & 36 deletions

File tree

internal/cli/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
)
1717

1818
// version and commit can be set via ldflags at build time (e.g., make build)
19-
var version = ""
20-
var commit = ""
19+
var (
20+
version = ""
21+
commit = ""
22+
)
2123

2224
// Version returns the version string, checking ldflags first, then Go module info
2325
func Version() string {

internal/cli/version_test.go

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ func TestVersion(t *testing.T) {
1212
}()
1313

1414
tests := []struct {
15-
name string
16-
version string
17-
commit string
18-
wantContain string
19-
wantExact string
15+
name string
16+
version string
17+
commit string
18+
wantExact string
19+
checkNotEmpty bool // when true, just verify non-empty output
2020
}{
2121
{
2222
name: "tagged release version",
@@ -55,10 +55,10 @@ func TestVersion(t *testing.T) {
5555
wantExact: "dev",
5656
},
5757
{
58-
name: "empty version falls back",
59-
version: "",
60-
commit: "",
61-
wantContain: "", // Will be "dev" or module version
58+
name: "empty version falls back",
59+
version: "",
60+
commit: "",
61+
checkNotEmpty: true, // Will be "dev" or module version
6262
},
6363
}
6464

@@ -72,32 +72,9 @@ func TestVersion(t *testing.T) {
7272
if tt.wantExact != "" && got != tt.wantExact {
7373
t.Errorf("Version() = %q, want %q", got, tt.wantExact)
7474
}
75-
if tt.wantContain != "" && got != tt.wantContain {
76-
// For empty version case, we just check it returns something
77-
if got == "" {
78-
t.Errorf("Version() returned empty string")
79-
}
75+
if tt.checkNotEmpty && got == "" {
76+
t.Errorf("Version() returned empty string")
8077
}
8178
})
8279
}
8380
}
84-
85-
func TestVersionWithEmptyFallsToDev(t *testing.T) {
86-
// Save original values
87-
origVersion := version
88-
origCommit := commit
89-
defer func() {
90-
version = origVersion
91-
commit = origCommit
92-
}()
93-
94-
// When both are empty and no module info, should return "dev"
95-
version = ""
96-
commit = ""
97-
98-
got := Version()
99-
// It will either return "dev" or a module version - both are valid
100-
if got == "" {
101-
t.Error("Version() should not return empty string")
102-
}
103-
}

0 commit comments

Comments
 (0)