Skip to content

Commit ea9e542

Browse files
committed
internal/versions: fix package to accept go1.21.0-bigcorp
Adds support for suffixes to x/tools copy of go/version. Brings in go.dev/cl/559796. Updates golang/go#65061 Change-Id: Iaa0c98a73d8ddd8a42f0c4d3df7d4d79eb7aeb0a Reviewed-on: https://go-review.googlesource.com/c/tools/+/562838 LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Tim King <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent fef8b62 commit ea9e542

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

internal/versions/versions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package versions
66

7+
import "strings"
8+
79
// Note: If we use build tags to use go/versions when go >=1.22,
810
// we run into go.dev/issue/53737. Under some operations users would see an
911
// import of "go/versions" even if they would not compile the file.
@@ -45,6 +47,7 @@ func IsValid(x string) bool { return isValid(stripGo(x)) }
4547
// stripGo converts from a "go1.21" version to a "1.21" version.
4648
// If v does not start with "go", stripGo returns the empty string (a known invalid version).
4749
func stripGo(v string) string {
50+
v, _, _ = strings.Cut(v, "-") // strip -bigcorp suffix.
4851
if len(v) < 2 || v[:2] != "go" {
4952
return ""
5053
}

internal/versions/versions_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestIsValid(t *testing.T) {
2020
"go0.0", // ??
2121
"go1",
2222
"go2",
23+
"go1.20.0-bigcorp",
2324
} {
2425
if !versions.IsValid(x) {
2526
t.Errorf("expected versions.IsValid(%q) to hold", x)
@@ -40,6 +41,7 @@ func TestIsValid(t *testing.T) {
4041
"go1.21.2_2",
4142
"go1.21rc_2",
4243
"go1.21rc2_",
44+
"go1.600+auto",
4345
} {
4446
if versions.IsValid(x) {
4547
t.Errorf("expected versions.IsValid(%q) to not hold", x)
@@ -52,6 +54,7 @@ func TestVersionComparisons(t *testing.T) {
5254
x, y string
5355
want int
5456
}{
57+
// All comparisons of go2, go1.21.2, go1.21rc2, go1.21rc2, go1, go0.0, "", bad
5558
{"go2", "go2", 0},
5659
{"go2", "go1.21.2", +1},
5760
{"go2", "go1.21rc2", +1},
@@ -97,6 +100,11 @@ func TestVersionComparisons(t *testing.T) {
97100
{"", "", 0},
98101
{"", "bad", 0},
99102
{"bad", "bad", 0},
103+
// Other tests.
104+
{"go1.20", "go1.20.0-bigcorp", 0},
105+
{"go1.21", "go1.21.0-bigcorp", -1}, // Starting in Go 1.21, patch missing is different from explicit .0.
106+
{"go1.21.0", "go1.21.0-bigcorp", 0}, // Starting in Go 1.21, patch missing is different from explicit .0.
107+
{"go1.19rc1", "go1.19", -1},
100108
} {
101109
got := versions.Compare(item.x, item.y)
102110
if got != item.want {

0 commit comments

Comments
 (0)