...

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

Documentation: cmd/go/testdata/script

     1# This test uses the fake toolchain switch support in cmd/go/internal/toolchain.Switch
     2# to exercise all the version selection logic without needing actual toolchains.
     3# See gotoolchain_net.txt and gotoolchain_path.txt for tests of network and PATH toolchains.
     4
     5env TESTGO_VERSION=go1.500
     6env TESTGO_VERSION_SWITCH=switch
     7
     8# GOTOOLCHAIN=auto runs default toolchain without a go.mod or go.work
     9env GOTOOLCHAIN=auto
    10go version
    11stdout go1.500
    12
    13# GOTOOLCHAIN=path runs default toolchain without a go.mod or go.work
    14env GOTOOLCHAIN=path
    15go version
    16stdout go1.500
    17
    18# GOTOOLCHAIN=asdf is a syntax error
    19env GOTOOLCHAIN=asdf
    20! go version
    21stderr '^go: invalid GOTOOLCHAIN "asdf"$'
    22
    23# GOTOOLCHAIN=version is used directly.
    24env GOTOOLCHAIN=go1.600
    25go version
    26stdout go1.600
    27
    28env GOTOOLCHAIN=go1.400
    29go version
    30stdout go1.400
    31
    32# GOTOOLCHAIN=version+auto sets a minimum.
    33env GOTOOLCHAIN=go1.600+auto
    34go version
    35stdout go1.600
    36
    37env GOTOOLCHAIN=go1.400.0+auto
    38go version
    39stdout go1.400.0
    40
    41# GOTOOLCHAIN=version+path sets a minimum too.
    42env GOTOOLCHAIN=go1.600+path
    43go version
    44stdout go1.600
    45
    46env GOTOOLCHAIN=go1.400+path
    47go version
    48stdout go1.400
    49
    50# Create a go.mod file and test interactions with auto and path.
    51
    52# GOTOOLCHAIN=auto uses go line if newer than local toolchain.
    53env GOTOOLCHAIN=auto
    54go mod init m
    55go mod edit -go=1.700 -toolchain=none
    56go version
    57stdout 1.700
    58
    59go mod edit -go=1.300 -toolchain=none
    60go version
    61stdout 1.500 # local toolchain is newer
    62
    63go mod edit -go=1.700 -toolchain=go1.300
    64go version
    65stdout go1.700 # toolchain too old, ignored
    66
    67go mod edit -go=1.300 -toolchain=default
    68go version
    69stdout go1.500
    70
    71go mod edit -go=1.700 -toolchain=default
    72go version
    73stdout go1.500 # toolchain local is like GOTOOLCHAIN=local and wins
    74! go build
    75stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; go.mod sets toolchain default\)'
    76
    77# GOTOOLCHAIN=path does the same.
    78env GOTOOLCHAIN=path
    79go mod edit -go=1.700 -toolchain=none
    80go version
    81stdout 1.700
    82
    83go mod edit -go=1.300 -toolchain=none
    84go version
    85stdout 1.500 # local toolchain is newer
    86
    87go mod edit -go=1.700 -toolchain=go1.300
    88go version
    89stdout go1.700 # toolchain too old, ignored
    90
    91go mod edit -go=1.300 -toolchain=default
    92go version
    93stdout go1.500
    94
    95go mod edit -go=1.700 -toolchain=default
    96go version
    97stdout go1.500 # toolchain default applies even if older than go line
    98! go build
    99stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; GOTOOLCHAIN=path; go.mod sets toolchain default\)'
   100
   101# GOTOOLCHAIN=min+auto with toolchain default uses min, not local
   102
   103env GOTOOLCHAIN=go1.400+auto
   104go mod edit -go=1.300 -toolchain=default
   105go version
   106stdout 1.400 # not 1.500 local toolchain
   107
   108env GOTOOLCHAIN=go1.600+auto
   109go mod edit -go=1.300 -toolchain=default
   110go version
   111stdout 1.600 # not 1.500 local toolchain
   112
   113# GOTOOLCHAIN names can have -suffix
   114env GOTOOLCHAIN=go1.800-bigcorp
   115go version
   116stdout go1.800-bigcorp
   117
   118env GOTOOLCHAIN=auto
   119go mod edit -go=1.999 -toolchain=go1.800-bigcorp
   120go version
   121stdout go1.999
   122
   123go mod edit -go=1.777 -toolchain=go1.800-bigcorp
   124go version
   125stdout go1.800-bigcorp
   126
   127# go.work takes priority over go.mod
   128go mod edit -go=1.700 -toolchain=go1.999-wrong
   129go work init
   130go work edit -go=1.400 -toolchain=go1.600-right
   131go version
   132stdout go1.600-right
   133
   134go work edit -go=1.400 -toolchain=default
   135go version
   136stdout go1.500
   137
   138# go.work misconfiguration does not break go work edit
   139# ('go 1.600 / toolchain local' forces use of 1.500 which can't normally load that go.work; allow work edit to fix it.)
   140go work edit -go=1.600 -toolchain=default
   141go version
   142stdout go1.500
   143
   144go work edit -toolchain=none
   145go version
   146stdout go1.600
   147
   148rm go.work
   149
   150# go.mod misconfiguration does not break go mod edit
   151go mod edit -go=1.600 -toolchain=default
   152go version
   153stdout go1.500
   154
   155go mod edit -toolchain=none
   156go version
   157stdout go1.600
   158
   159# toolchain built with a custom version should know how it compares to others
   160
   161env TESTGO_VERSION=go1.500-bigcorp
   162go mod edit -go=1.499 -toolchain=none
   163go version
   164stdout go1.500-bigcorp
   165
   166go mod edit -go=1.499 -toolchain=go1.499
   167go version
   168stdout go1.500-bigcorp
   169
   170go mod edit -go=1.500 -toolchain=none
   171go version
   172stdout go1.500-bigcorp
   173
   174go mod edit -go=1.500 -toolchain=go1.500
   175go version
   176stdout go1.500-bigcorp
   177
   178go mod edit -go=1.501 -toolchain=none
   179go version
   180stdout go1.501
   181
   182	# If toolchain > go, we must upgrade to the indicated toolchain (not just the go version).
   183go mod edit -go=1.499 -toolchain=go1.501
   184go version
   185stdout go1.501
   186
   187env TESTGO_VERSION='go1.500 (bigcorp)'
   188go mod edit -go=1.499 -toolchain=none
   189go version
   190stdout 'go1.500 \(bigcorp\)'
   191
   192go mod edit -go=1.500 -toolchain=none
   193go version
   194stdout 'go1.500 \(bigcorp\)'
   195
   196go mod edit -go=1.501 -toolchain=none
   197go version
   198stdout go1.501
   199
   200# go install m@v and go run m@v should ignore go.mod and use m@v
   201env TESTGO_VERSION=go1.2.3
   202go mod edit -go=1.999 -toolchain=go1.998
   203
   204! go install rsc.io/fortune/nonexist@v0.0.1
   205stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   206stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist'
   207
   208! go run rsc.io/fortune/nonexist@v0.0.1
   209stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   210stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist'
   211
   212# go install should handle unknown flags to find m@v
   213! go install -unknownflag rsc.io/fortune/nonexist@v0.0.1
   214stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   215stderr '^flag provided but not defined: -unknownflag'
   216
   217! go install -unknownflag arg rsc.io/fortune/nonexist@v0.0.1
   218stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   219stderr '^flag provided but not defined: -unknownflag'
   220
   221# go run cannot handle unknown boolean flags
   222! go run -unknownflag rsc.io/fortune/nonexist@v0.0.1
   223! stderr switching
   224stderr '^flag provided but not defined: -unknownflag'
   225
   226! go run -unknownflag oops rsc.io/fortune/nonexist@v0.0.1
   227! stderr switching
   228stderr '^flag provided but not defined: -unknownflag'
   229
   230# go run can handle unknown flag with argument.
   231! go run -unknown=flag rsc.io/fortune/nonexist@v0.0.1
   232stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   233stderr '^flag provided but not defined: -unknown'
   234
   235# go install m@v should handle queries
   236! go install rsc.io/fortune/nonexist@v0.0
   237stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   238stderr '^go: rsc.io/fortune/nonexist@v0.0: module rsc.io/fortune@v0.0 found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist'
   239
   240# go run m@v should handle queries
   241! go install rsc.io/fortune/nonexist@v0
   242stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$'
   243stderr '^go: rsc.io/fortune/nonexist@v0: module rsc.io/fortune@v0 found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist'
   244
   245# go install m@v should use local toolchain if not upgrading
   246! go install rsc.io/fortune/nonexist@v1
   247! stderr go1.22.9
   248! stderr switching
   249stderr '^go: downloading rsc.io/fortune v1.0.0$'
   250stderr '^go: rsc.io/fortune/nonexist@v1: module rsc.io/fortune@v1 found \(v1.0.0\), but does not contain package rsc.io/fortune/nonexist'
   251
   252# go run m@v should use local toolchain if not upgrading
   253! go run rsc.io/fortune/nonexist@v1
   254! stderr go1.22.9
   255! stderr switching
   256stderr '^go: rsc.io/fortune/nonexist@v1: module rsc.io/fortune@v1 found \(v1.0.0\), but does not contain package rsc.io/fortune/nonexist'

View as plain text