...
1env GOTOOLCHAIN=auto
2env TESTGO_VERSION=go1.21.1
3
4# Basic switch should work.
5env TESTGO_VERSION_SWITCH=switch
6go version
7stdout go1.21.99
8
9# Toolchain target mismatch should be detected.
10env TESTGO_VERSION_SWITCH=mismatch
11! go version
12stderr '^go: toolchain go1.21.1 invoked to provide go1.21.99$'
13
14# Toolchain loop should be detected.
15env TESTGO_VERSION_SWITCH=loop
16! go version
17stderr -count=10 '^go: switching from go1.21.1 to go1.21.99 \[depth 9[0-9]\]$'
18stderr -count=1 '^go: switching from go1.21.1 to go1.21.99 \[depth 100\]$'
19stderr '^go: too many toolchain switches$'
20
21[short] skip
22
23# Internal env vars should not leak to go test or go run.
24env TESTGO_VERSION_SWITCH=switch
25go version
26stdout go1.21.99
27go test
28stdout clean
29go run .
30stdout clean
31
32-- go.mod --
33module m
34go 1.21.99
35
36-- m_test.go --
37package main
38
39import "testing"
40
41func TestEnv(t *testing.T) {
42 // the check is in func init in m.go
43}
44
45-- m.go --
46package main
47
48import "os"
49
50func init() {
51 envs := []string{
52 "GOTOOLCHAIN_INTERNAL_SWITCH_COUNT",
53 "GOTOOLCHAIN_INTERNAL_SWITCH_VERSION",
54 }
55 for _, e := range envs {
56 if v := os.Getenv(e); v != "" {
57 panic("$"+e+"="+v)
58 }
59 }
60 os.Stdout.WriteString("clean\n")
61}
62
63func main() {
64}
65
View as plain text