1 env GOTOOLCHAIN=auto
2 env TESTGO_VERSION=go1.21.1
3
4 # Basic switch should work.
5 env TESTGO_VERSION_SWITCH=switch
6 go version
7 stdout go1.21.99
8
9 # Toolchain target mismatch should be detected.
10 env TESTGO_VERSION_SWITCH=mismatch
11 ! go version
12 stderr '^go: toolchain go1.21.1 invoked to provide go1.21.99$'
13
14 # Toolchain loop should be detected.
15 env TESTGO_VERSION_SWITCH=loop
16 ! go version
17 stderr -count=10 '^go: switching from go1.21.1 to go1.21.99 \[depth 9[0-9]\]$'
18 stderr -count=1 '^go: switching from go1.21.1 to go1.21.99 \[depth 100\]$'
19 stderr '^go: too many toolchain switches$'
20
21 [short] skip
22
23 # Internal env vars should not leak to go test or go run.
24 env TESTGO_VERSION_SWITCH=switch
25 go version
26 stdout go1.21.99
27 go test
28 stdout clean
29 go run .
30 stdout clean
31
32 -- go.mod --
33 module m
34 go 1.21.99
35
36 -- m_test.go --
37 package main
38
39 import "testing"
40
41 func TestEnv(t *testing.T) {
42 // the check is in func init in m.go
43 }
44
45 -- m.go --
46 package main
47
48 import "os"
49
50 func 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
63 func main() {
64 }
65
66
View as plain text