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

     1  # This test checks the behavior of 'go run' with a 'cmd@version' argument.
     2  # Most of 'go run' is covered in other tests.
     3  # mod_install_pkg_version covers most of the package loading functionality.
     4  # This test focuses on 'go run' behavior specific to this mode.
     5  [short] skip
     6  
     7  # 'go run pkg@version' works outside a module.
     8  env GO111MODULE=auto
     9  go run example.com/cmd/a@v1.0.0
    10  stdout '^a@v1.0.0$'
    11  
    12  
    13  # 'go run pkg@version' reports an error if modules are disabled.
    14  env GO111MODULE=off
    15  ! go run example.com/cmd/a@v1.0.0
    16  stderr '^go: modules disabled by GO111MODULE=off; see ''go help modules''$'
    17  env GO111MODULE=on
    18  
    19  
    20  # 'go run pkg@version' ignores go.mod in the current directory.
    21  cd m
    22  cp go.mod go.mod.orig
    23  ! go list -m all
    24  stderr '^go: example.com/cmd@v1.1.0-doesnotexist: reading http.*/mod/example\.com/cmd/@v/v1.1.0-doesnotexist.info: 404 Not Found\n\tserver response: 404 page not found$'
    25  stderr '^go: example.com/cmd@v1.1.0-doesnotexist: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/cmd$'
    26  go run example.com/cmd/a@v1.0.0
    27  stdout '^a@v1.0.0$'
    28  cmp go.mod go.mod.orig
    29  cd ..
    30  
    31  
    32  # 'go install pkg@version' works on a module that doesn't have a go.mod file
    33  # and with a module whose go.mod file has missing requirements.
    34  # With a proxy, the two cases are indistinguishable.
    35  go run rsc.io/fortune@v1.0.0
    36  stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$'
    37  stderr '^Hello, world.$'
    38  
    39  
    40  # 'go run pkg@version' should report an error if pkg is not a main package.
    41  ! go run example.com/cmd/err@v1.0.0
    42  stderr '^package example.com/cmd/err is not a main package$'
    43  
    44  
    45  # 'go run pkg@version' should report errors if the module contains
    46  # replace or exclude directives.
    47  go mod download example.com/cmd@v1.0.0-replace
    48  ! go run example.com/cmd/a@v1.0.0-replace
    49  cmp stderr replace-err
    50  
    51  go mod download example.com/cmd@v1.0.0-exclude
    52  ! go run example.com/cmd/a@v1.0.0-exclude
    53  cmp stderr exclude-err
    54  
    55  
    56  # 'go run dir@version' works like a normal 'go run' command if
    57  # dir is a relative or absolute path.
    58  go mod download rsc.io/fortune@v1.0.0
    59  ! go run $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    60  stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    61  ! go run ../pkg/mod/rsc.io/fortune@v1.0.0
    62  stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    63  mkdir tmp
    64  cd tmp
    65  go mod init tmp
    66  go mod edit -require=rsc.io/fortune@v1.0.0
    67  ! go run -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    68  stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    69  ! go run -mod=readonly ../../pkg/mod/rsc.io/fortune@v1.0.0
    70  stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    71  cd ..
    72  rm tmp
    73  
    74  
    75  # 'go run' does not interpret @version arguments after the first.
    76  go run example.com/cmd/a@v1.0.0 example.com/doesnotexist@v1.0.0
    77  stdout '^a@v1.0.0$'
    78  
    79  
    80  # 'go run pkg@version' succeeds when -mod=readonly is set explicitly.
    81  # Verifies #43278.
    82  go run -mod=readonly example.com/cmd/a@v1.0.0
    83  stdout '^a@v1.0.0$'
    84  
    85  -- m/go.mod --
    86  module m
    87  
    88  go 1.16
    89  
    90  require example.com/cmd v1.1.0-doesnotexist
    91  -- x/x.go --
    92  package main
    93  
    94  func main() {}
    95  -- replace-err --
    96  go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace):
    97  	The go.mod file for the module providing named packages contains one or
    98  	more replace directives. It must not contain directives that would cause
    99  	it to be interpreted differently than if it were the main module.
   100  -- exclude-err --
   101  go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude):
   102  	The go.mod file for the module providing named packages contains one or
   103  	more exclude directives. It must not contain directives that would cause
   104  	it to be interpreted differently than if it were the main module.
   105  

View as plain text