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

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

View as plain text