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  
    86  # 'go run pkg@version' should show a deprecation message if the module is deprecated.
    87  go run example.com/deprecated/a/cmd/a@latest
    88  stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
    89  stdout '^a@v1.9.0$'
    90  go run example.com/deprecated/a/cmd/a@v1.0.0
    91  stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
    92  stdout '^a@v1.0.0$'
    93  
    94  # 'go run pkg@version' does not show a deprecation message if the module is no longer
    95  # deprecated in its latest version, even if the module is deprecated in its current version.
    96  go run example.com/undeprecated/cmd/a@v1.0.0
    97  ! stderr 'module.*is deprecated'
    98  
    99  -- m/go.mod --
   100  module m
   101  
   102  go 1.16
   103  
   104  require example.com/cmd v1.1.0-doesnotexist
   105  -- x/x.go --
   106  package main
   107  
   108  func main() {}
   109  -- replace-err --
   110  go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace):
   111  	The go.mod file for the module providing named packages contains one or
   112  	more replace directives. It must not contain directives that would cause
   113  	it to be interpreted differently than if it were the main module.
   114  -- exclude-err --
   115  go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude):
   116  	The go.mod file for the module providing named packages contains one or
   117  	more exclude directives. It must not contain directives that would cause
   118  	it to be interpreted differently than if it were the main module.
   119  

View as plain text