...
1# This test only checks that basic PATH lookups work.
2# The full test of toolchain version selection is in gotoolchain.txt.
3
4[short] skip
5
6env TESTGO_VERSION=go1.21pre3
7
8# Compile a fake toolchain to put in the path under various names.
9env GOTOOLCHAIN=
10mkdir $WORK/bin
11go build -o $WORK/bin/go1.50.0$GOEXE ./fakego.go # adds .exe extension implicitly on Windows
12
13[!GOOS:plan9] env PATH=$WORK/bin
14[GOOS:plan9] env path=$WORK/bin
15
16go version
17stdout go1.21pre3
18
19# GOTOOLCHAIN=go1.50.0
20env GOTOOLCHAIN=go1.50.0
21! go version
22stderr 'running go1.50.0 from PATH'
23
24# GOTOOLCHAIN=path with toolchain line
25env GOTOOLCHAIN=local
26go mod init m
27go mod edit -toolchain=go1.50.0
28grep go1.50.0 go.mod
29env GOTOOLCHAIN=path
30! go version
31stderr 'running go1.50.0 from PATH'
32
33# GOTOOLCHAIN=path with go line
34env GOTOOLCHAIN=local
35go mod edit -toolchain=none -go=1.50.0
36grep 'go 1.50.0' go.mod
37! grep toolchain go.mod
38env GOTOOLCHAIN=path
39! go version
40stderr 'running go1.50.0 from PATH'
41
42# GOTOOLCHAIN=auto with toolchain line
43env GOTOOLCHAIN=local
44go mod edit -toolchain=go1.50.0 -go=1.21
45grep 'go 1.21$' go.mod
46grep 'toolchain go1.50.0' go.mod
47env GOTOOLCHAIN=auto
48! go version
49stderr 'running go1.50.0 from PATH'
50
51# GOTOOLCHAIN=auto with go line
52env GOTOOLCHAIN=local
53go mod edit -toolchain=none -go=1.50.0
54grep 'go 1.50.0$' go.mod
55! grep toolchain go.mod
56env GOTOOLCHAIN=auto
57! go version
58stderr 'running go1.50.0 from PATH'
59
60# NewerToolchain should find Go 1.50.0.
61env GOTOOLCHAIN=local
62go mod edit -toolchain=none -go=1.22
63grep 'go 1.22$' go.mod
64! grep toolchain go.mod
65env GOTOOLCHAIN=path
66! go run rsc.io/fortune@v0.0.1
67stderr 'running go1.50.0 from PATH'
68
69-- fakego.go --
70package main
71
72import (
73 "fmt"
74 "os"
75 "path/filepath"
76 "strings"
77)
78
79func main() {
80 exe, _ := os.Executable()
81 name := filepath.Base(exe)
82 name = strings.TrimSuffix(name, ".exe")
83 fmt.Fprintf(os.Stderr, "running %s from PATH\n", name)
84 os.Exit(1) // fail in case we are running this accidentally (like in "go mod edit")
85}
View as plain text