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

     1  # Regression test for https://go.dev/issue/64282.
     2  #
     3  # 'go install' and 'go run' with pkg@version arguments should make
     4  # a best effort to parse flags relevant to downloading modules
     5  # (currently only -modcacherw) before actually downloading the module
     6  # to identify which toolchain version to use.
     7  #
     8  # However, the best-effort flag parsing should not interfere with
     9  # actual flag parsing if we don't switch toolchains. In particular,
    10  # unrecognized flags should still be diagnosed after the module for
    11  # the requested package has been downloaded and checked for toolchain
    12  # upgrades.
    13  
    14  
    15  ! go install -cake=delicious -modcacherw example.com/printversion@v0.1.0
    16  stderr '^flag provided but not defined: -cake$'
    17  	# Because the -modcacherw flag was set, we should be able to modify the contents
    18  	# of a directory within the module cache.
    19  cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go
    20  go clean -modcache
    21  
    22  
    23  ! go install -unknownflag -tags -modcacherw example.com/printversion@v0.1.0
    24  stderr '^flag provided but not defined: -unknownflag$'
    25  cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go
    26  go clean -modcache
    27  
    28  
    29  # Also try it with a 'go install' that succeeds.
    30  # (But skip in short mode, because linking a binary is expensive.)
    31  [!short] go install -modcacherw example.com/printversion@v0.1.0
    32  [!short] cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go
    33  [!short] go clean -modcache
    34  
    35  
    36  # The flag should also be applied if given in GOFLAGS
    37  # instead of on the command line.
    38  env GOFLAGS=-modcacherw
    39  ! go install -cake=delicious example.com/printversion@v0.1.0
    40  stderr '^flag provided but not defined: -cake$'
    41  cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go
    42  
    43  
    44  -- $WORK/extraneous.txt --
    45  This is not a Go source file.
    46  

View as plain text