Skip to content

Commit 10b3aad

Browse files
committed
goenv: improve WantGoVersion
Address PR feedback in tinygo-org#4501.
1 parent bcd6eb0 commit 10b3aad

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

goenv/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func WantGoVersion(s string, major, minor int) bool {
7171
if err != nil {
7272
return false
7373
}
74-
return ma >= major && mi >= minor
74+
return ma > major || (ma == major && mi >= minor)
7575
}
7676

7777
// GorootVersionString returns the version string as reported by the Go

goenv/version_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,33 @@ func TestParse(t *testing.T) {
3636
})
3737
}
3838
}
39+
40+
func TestWantGoVersion(t *testing.T) {
41+
tests := []struct {
42+
v string
43+
major int
44+
minor int
45+
want bool
46+
}{
47+
{"", 0, 0, false},
48+
{"go", 0, 0, false},
49+
{"go1", 0, 0, false},
50+
{"go.0", 0, 0, false},
51+
{"go1.0", 1, 0, true},
52+
{"go1.1", 1, 1, true},
53+
{"go1.23", 1, 23, true},
54+
{"go1.23.5", 1, 23, true},
55+
{"go1.23.5-rc6", 1, 23, true},
56+
{"go2.0", 1, 23, true},
57+
{"go2.0", 2, 0, true},
58+
}
59+
for _, tt := range tests {
60+
t.Run(tt.v, func(t *testing.T) {
61+
got := WantGoVersion(tt.v, tt.major, tt.minor)
62+
if got != tt.want {
63+
t.Errorf("WantGoVersion(%q, %d, %d): expected %t; got %t",
64+
tt.v, tt.major, tt.minor, tt.want, got)
65+
}
66+
})
67+
}
68+
}

0 commit comments

Comments
 (0)