|
5 | 5 | package goversion_test
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "fmt" |
8 | 9 | "strings"
|
9 | 10 | "testing"
|
10 | 11 |
|
11 | 12 | "golang.org/x/tools/gopls/internal/util/goversion"
|
12 | 13 | )
|
13 | 14 |
|
14 | 15 | func TestMessage(t *testing.T) {
|
| 16 | + // Note(rfindley): this test is a change detector, as it must be updated |
| 17 | + // whenever we deprecate a version. |
| 18 | + // |
| 19 | + // However, I chose to leave it as is since it gives us confidence in error |
| 20 | + // messages served for Go versions that we no longer support (and therefore |
| 21 | + // no longer run in CI). |
| 22 | + type test struct { |
| 23 | + goVersion int |
| 24 | + fromBuild bool |
| 25 | + wantContains []string // string fragments that we expect to see |
| 26 | + wantIsError bool // an error, not a mere warning |
| 27 | + } |
| 28 | + |
| 29 | + deprecated := func(goVersion int, lastVersion string) test { |
| 30 | + return test{ |
| 31 | + goVersion: goVersion, |
| 32 | + fromBuild: false, |
| 33 | + wantContains: []string{ |
| 34 | + fmt.Sprintf("Found Go version 1.%d", goVersion), |
| 35 | + "not supported", |
| 36 | + fmt.Sprintf("upgrade to Go 1.%d", goversion.OldestSupported()), |
| 37 | + fmt.Sprintf("install gopls %s", lastVersion), |
| 38 | + }, |
| 39 | + wantIsError: true, |
| 40 | + } |
| 41 | + } |
| 42 | + |
15 | 43 | tests := []struct {
|
16 | 44 | goVersion int
|
17 | 45 | fromBuild bool
|
18 | 46 | wantContains []string // string fragments that we expect to see
|
19 | 47 | wantIsError bool // an error, not a mere warning
|
20 | 48 | }{
|
21 | 49 | {-1, false, nil, false},
|
22 |
| - {12, false, []string{"1.12", "not supported", "upgrade to Go 1.18", "install gopls v0.7.5"}, true}, |
23 |
| - {13, false, []string{"1.13", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, true}, |
24 |
| - {15, false, []string{"1.15", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, true}, |
25 |
| - {15, true, []string{"Gopls was built with Go version 1.15", "not supported", "upgrade to Go 1.18", "install gopls v0.9.5"}, true}, |
26 |
| - {16, false, []string{"1.16", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, false}, |
27 |
| - {17, false, []string{"1.17", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, false}, |
28 |
| - {17, true, []string{"Gopls was built with Go version 1.17", "will be unsupported by gopls v0.13.0", "upgrade to Go 1.18", "install gopls v0.11.0"}, false}, |
| 50 | + deprecated(12, "v0.7.5"), |
| 51 | + deprecated(13, "v0.9.5"), |
| 52 | + deprecated(15, "v0.9.5"), |
| 53 | + deprecated(16, "v0.11.0"), |
| 54 | + deprecated(17, "v0.11.0"), |
| 55 | + {18, false, []string{"Found Go version 1.18", "unsupported by gopls v0.16.0", "upgrade to Go 1.19", "install gopls v0.14.2"}, false}, |
| 56 | + {18, true, []string{"Gopls was built with Go version 1.18", "unsupported by gopls v0.16.0", "upgrade to Go 1.19", "install gopls v0.14.2"}, false}, |
29 | 57 | }
|
30 | 58 |
|
31 | 59 | for _, test := range tests {
|
|
0 commit comments