...
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/ ./fakego.go # adds .exe extension implicitly on Windows
12cp $WORK/bin/fakego$GOEXE $WORK/bin/go1.50.0$GOEXE
13
14[!GOOS:plan9] env PATH=$WORK/bin
15[GOOS:plan9] env path=$WORK/bin
16
17go version
18stdout go1.21pre3
19
20# GOTOOLCHAIN=go1.50.0
21env GOTOOLCHAIN=go1.50.0
22! go version
23stderr 'running go1.50.0 from PATH'
24
25# GOTOOLCHAIN=path with toolchain line
26env GOTOOLCHAIN=local
27go mod init m
28go mod edit -toolchain=go1.50.0
29grep go1.50.0 go.mod
30env GOTOOLCHAIN=path
31! go version
32stderr 'running go1.50.0 from PATH'
33
34# GOTOOLCHAIN=path with go line
35env GOTOOLCHAIN=local
36go mod edit -toolchain=none -go=1.50.0
37grep 'go 1.50.0' go.mod
38! grep toolchain go.mod
39env GOTOOLCHAIN=path
40! go version
41stderr 'running go1.50.0 from PATH'
42
43# GOTOOLCHAIN=auto with toolchain line
44env GOTOOLCHAIN=local
45go mod edit -toolchain=go1.50.0 -go=1.21
46grep 'go 1.21$' go.mod
47grep 'toolchain go1.50.0' go.mod
48env GOTOOLCHAIN=auto
49! go version
50stderr 'running go1.50.0 from PATH'
51
52# GOTOOLCHAIN=auto with go line
53env GOTOOLCHAIN=local
54go mod edit -toolchain=none -go=1.50.0
55grep 'go 1.50.0$' go.mod
56! grep toolchain go.mod
57env GOTOOLCHAIN=auto
58! go version
59stderr 'running go1.50.0 from PATH'
60
61# NewerToolchain should find Go 1.50.0.
62env GOTOOLCHAIN=local
63go mod edit -toolchain=none -go=1.22
64grep 'go 1.22$' go.mod
65! grep toolchain go.mod
66env GOTOOLCHAIN=path
67! go run rsc.io/fortune@v0.0.1
68stderr 'running go1.50.0 from PATH'
69
70-- fakego.go --
71package main
72
73import (
74 "fmt"
75 "os"
76 "path/filepath"
77 "strings"
78)
79
80func main() {
81 exe, _ := os.Executable()
82 name := filepath.Base(exe)
83 name = strings.TrimSuffix(name, ".exe")
84 fmt.Fprintf(os.Stderr, "running %s from PATH\n", name)
85 os.Exit(1) // fail in case we are running this accidentally (like in "go mod edit")
86}
View as plain text