Text file src/cmd/go/testdata/script/gotoolchain_path.txt

     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  
     6  env TESTGO_VERSION=go1.21pre3
     7  
     8  # Compile a fake toolchain to put in the path under various names.
     9  env GOTOOLCHAIN=
    10  mkdir $WORK/bin
    11  go 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  
    16  go version
    17  stdout go1.21pre3
    18  
    19  # GOTOOLCHAIN=go1.50.0
    20  env GOTOOLCHAIN=go1.50.0
    21  ! go version
    22  stderr 'running go1.50.0 from PATH'
    23  
    24  # GOTOOLCHAIN=path with toolchain line
    25  env GOTOOLCHAIN=local
    26  go mod init m
    27  go mod edit -toolchain=go1.50.0
    28  grep go1.50.0 go.mod
    29  env GOTOOLCHAIN=path
    30  ! go version
    31  stderr 'running go1.50.0 from PATH'
    32  
    33  # GOTOOLCHAIN=path with go line
    34  env GOTOOLCHAIN=local
    35  go mod edit -toolchain=none -go=1.50.0
    36  grep 'go 1.50.0' go.mod
    37  ! grep toolchain go.mod
    38  env GOTOOLCHAIN=path
    39  ! go version
    40  stderr 'running go1.50.0 from PATH'
    41  
    42  # GOTOOLCHAIN=auto with toolchain line
    43  env GOTOOLCHAIN=local
    44  go mod edit -toolchain=go1.50.0 -go=1.21
    45  grep 'go 1.21$' go.mod
    46  grep 'toolchain go1.50.0' go.mod
    47  env GOTOOLCHAIN=auto
    48  ! go version
    49  stderr 'running go1.50.0 from PATH'
    50  
    51  # GOTOOLCHAIN=auto with go line
    52  env GOTOOLCHAIN=local
    53  go mod edit -toolchain=none -go=1.50.0
    54  grep 'go 1.50.0$' go.mod
    55  ! grep toolchain go.mod
    56  env GOTOOLCHAIN=auto
    57  ! go version
    58  stderr 'running go1.50.0 from PATH'
    59  
    60  # NewerToolchain should find Go 1.50.0.
    61  env GOTOOLCHAIN=local
    62  go mod edit -toolchain=none -go=1.22
    63  grep 'go 1.22$' go.mod
    64  ! grep toolchain go.mod
    65  env GOTOOLCHAIN=path
    66  ! go run rsc.io/fortune@v0.0.1
    67  stderr 'running go1.50.0 from PATH'
    68  
    69  -- fakego.go --
    70  package main
    71  
    72  import (
    73  	"fmt"
    74  	"os"
    75  	"path/filepath"
    76  	"strings"
    77  )
    78  
    79  func 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  }
    86  

View as plain text