...

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

Documentation: cmd/go/testdata/script

     1# Test the GODEBUG=toolchaintrace behavior
     2# See https://go.dev/issue/63939
     3env GODEBUG=toolchaintrace=1
     4env TESTGO_VERSION=go1.21.0
     5env TESTGO_VERSION_SWITCH=switch
     6env GOTOOLCHAIN=auto
     7
     8# Go line is newer than local go version.
     9go mod init m
    10go mod edit -go=1.21.1
    11go version
    12stderr -count=1 'go: upgrading toolchain to go1.21.1 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)'
    13stderr -count=1 'go: using go1.21.1 toolchain from cache located at .*'
    14stdout 'go version go1.21.1'
    15rm go.mod
    16
    17# Toolchain line is newer than go line.
    18go mod init m
    19go mod edit -go=1.21.1 -toolchain=go1.21.2
    20go version
    21stderr -count=1 'go: upgrading toolchain to go1.21.2 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)'
    22stderr -count=1 'go: using go1.21.2 toolchain from cache located at .*'
    23stdout 'go version go1.21.2'
    24rm go.mod
    25
    26# Go line is newer than local go version and toolchain line.
    27go mod init m
    28go mod edit -go=1.22 -toolchain=go1.21.2
    29go version
    30stderr -count=1 'go: upgrading toolchain to go1.21.2 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)'
    31stderr -count=1 'go: upgrading toolchain to go1.22.0 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)'
    32stderr -count=1 'go: using go1.22.0 toolchain from cache located at .*'
    33stdout 'go version go1.22.0'
    34rm go.mod
    35
    36# No switch.
    37go mod init m
    38go mod edit -go=1.21.0 -toolchain=go1.21.0
    39go version
    40stderr -count=1 'go: using local toolchain go1.21.0'
    41! stderr 'go: upgrading toolchain'
    42stdout 'go version go1.21.0'
    43rm go.mod
    44
    45# GOTOOLCHAIN+auto is older than go line and toolchain line.
    46go mod init m
    47go mod edit -go=1.22 -toolchain=go1.21.2
    48env GOTOOLCHAIN=go1.21.0+auto
    49go version
    50stderr -count=1 'go: default toolchain set to go1.21.0 from GOTOOLCHAIN=go1.21.0\+auto'
    51stderr -count=1 'go: upgrading toolchain to go1.21.2 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=<name>\+auto\)'
    52stderr -count=1 'go: upgrading toolchain to go1.22.0 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=<name>\+auto\)'
    53stderr -count=1 'go: using go1.22.0 toolchain from cache located at .*'
    54stdout 'go version go1.22.0'
    55rm go.mod
    56
    57# GOTOOLCHAIN is older than go line and toolchain line.
    58go mod init m
    59go mod edit -go=1.22 -toolchain=go1.21.2
    60env GOTOOLCHAIN=go1.21.1
    61go version
    62stderr -count=1 'go: default toolchain set to go1.21.1 from GOTOOLCHAIN=go1.21.1'
    63stderr -count=1 'go: using go1.21.1 toolchain from cache located at .*'
    64! stderr 'go: upgrading toolchain'
    65stdout 'go version go1.21.1'
    66rm go.mod
    67env GOTOOLCHAIN=auto
    68
    69# GOTOOLCHAIN+auto is newer than go line and toolchain line.
    70go mod init m
    71go mod edit -go=1.21.1 -toolchain=go1.21.2
    72env GOTOOLCHAIN=go1.22.0+auto
    73go version
    74stderr -count=1 'go: default toolchain set to go1.22.0 from GOTOOLCHAIN=go1.22.0\+auto'
    75stderr -count=1 'go: using go1.22.0 toolchain from cache located at .*'
    76stdout 'go version go1.22.0'
    77rm go.mod
    78
    79# GOTOOLCHAIN=local
    80env GOTOOLCHAIN=local
    81go mod init m
    82go mod edit -go=1.21.1 -toolchain=go1.21.2
    83go version
    84stderr -count=1 'go: default toolchain set to go1.21.0 from GOTOOLCHAIN=local'
    85stderr -count=1 'go: using local toolchain go1.21.0'
    86stdout 'go version go1.21.0'
    87rm go.mod
    88
    89[short] stop 'requires build'
    90# If toolchain found in PATH, ensure we print that.
    91env GOTOOLCHAIN=auto
    92env TESTGO_VERSION_SWITCH=
    93mkdir $WORK/bin
    94go build -o $WORK/bin/go1.22.0$GOEXE ./fake/fakego.go  # adds .exe extension implicitly on Windows
    95[!GOOS:plan9] env PATH=$WORK/bin
    96[GOOS:plan9] env path=$WORK/bin
    97go mod init m
    98go mod edit -go=1.22.0
    99! go version
   100stderr -count=1 'go: upgrading toolchain to go1.22.0 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)'
   101stderr -count=1 'go: using go1.22.0 toolchain located in system PATH \('$WORK'[/\\]bin[/\\]go1.22.0'$GOEXE'\)'
   102stderr 'running go1.22.0 from PATH'
   103rm go.mod
   104
   105
   106-- fake/fakego.go --
   107package main
   108
   109import (
   110	"fmt"
   111	"os"
   112	"path/filepath"
   113	"strings"
   114)
   115
   116func main() {
   117	exe, _ := os.Executable()
   118	name := filepath.Base(exe)
   119	name = strings.TrimSuffix(name, ".exe")
   120	fmt.Fprintf(os.Stderr, "running %s from PATH\n", name)
   121	os.Exit(1) // fail in case we are running this accidentally (like in "go mod edit")
   122}

View as plain text