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

View as plain text