TestGoVersion tests that the Go version specified in go.mod matches ./tool/go version.
(t *testing.T)
| 29 | |
| 30 | // TestGoVersion tests that the Go version specified in go.mod matches ./tool/go version. |
| 31 | func TestGoVersion(t *testing.T) { |
| 32 | // We could special-case ./tool/go path for Windows, but really there is no |
| 33 | // need to run it there. |
| 34 | if runtime.GOOS == "windows" { |
| 35 | t.Skip("Skipping test on Windows") |
| 36 | } |
| 37 | goModVersion := mustGetGoModVersion(t, true) |
| 38 | |
| 39 | goToolCmd := exec.Command("./tool/go", "version") |
| 40 | goToolOutput, err := goToolCmd.Output() |
| 41 | if err != nil { |
| 42 | t.Fatalf("Failed to get ./tool/go version: %v", err) |
| 43 | } |
| 44 | |
| 45 | // Version info will approximately look like 'go version go1.24.4 linux/amd64'. |
| 46 | parts := strings.Fields(string(goToolOutput)) |
| 47 | if len(parts) < 4 { |
| 48 | t.Fatalf("Unexpected ./tool/go version output format: %s", goToolOutput) |
| 49 | } |
| 50 | |
| 51 | goToolVersion := strings.TrimPrefix(parts[2], "go") |
| 52 | |
| 53 | if goModVersion != goToolVersion { |
| 54 | t.Errorf("Go version in go.mod (%q) does not match the version of ./tool/go (%q).\nEnsure that the go.mod refers to the same Go version as ./go.toolchain.rev.", |
| 55 | goModVersion, goToolVersion) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func mustGetGoModVersion(t *testing.T, includePatchVersion bool) string { |
| 60 | t.Helper() |
nothing calls this directly
no test coverage detected
searching dependent graphs…