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: missing go.sum entry; to add it:\n\tgo mod download example.com/cmd$'
    25  go run example.com/cmd/a@v1.0.0
    26  stdout '^a@v1.0.0$'
    27  cmp go.mod go.mod.orig
    28  cd ..
    29  
    30  
    31  # 'go install pkg@version' works on a module that doesn't have a go.mod file
    32  # and with a module whose go.mod file has missing requirements.
    33  # With a proxy, the two cases are indistinguishable.
    34  go run rsc.io/fortune@v1.0.0
    35  stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$'
    36  stderr '^Hello, world.$'
    37  
    38  
    39  # 'go run pkg@version' should report an error if pkg is not a main package.
    40  ! go run example.com/cmd/err@v1.0.0
    41  stderr '^package example.com/cmd/err is not a main package$'
    42  
    43  
    44  # 'go run pkg@version' should report errors if the module contains
    45  # replace or exclude directives.
    46  go mod download example.com/cmd@v1.0.0-replace
    47  ! go run example.com/cmd/a@v1.0.0-replace
    48  cmp stderr replace-err
    49  
    50  go mod download example.com/cmd@v1.0.0-exclude
    51  ! go run example.com/cmd/a@v1.0.0-exclude
    52  cmp stderr exclude-err
    53  
    54  
    55  # 'go run dir@version' works like a normal 'go run' command if
    56  # dir is a relative or absolute path.
    57  go mod download rsc.io/fortune@v1.0.0
    58  ! go run $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    59  stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    60  ! go run ../pkg/mod/rsc.io/fortune@v1.0.0
    61  stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    62  mkdir tmp
    63  cd tmp
    64  go mod init tmp
    65  go mod edit -require=rsc.io/fortune@v1.0.0
    66  ! go run -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    67  stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    68  ! go run -mod=readonly ../../pkg/mod/rsc.io/fortune@v1.0.0
    69  stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    70  cd ..
    71  rm tmp
    72  
    73  
    74  # 'go run' does not interpret @version arguments after the first.
    75  go run example.com/cmd/a@v1.0.0 example.com/doesnotexist@v1.0.0
    76  stdout '^a@v1.0.0$'
    77  
    78  
    79  # 'go run pkg@version' succeeds when -mod=readonly is set explicitly.
    80  # Verifies #43278.
    81  go run -mod=readonly example.com/cmd/a@v1.0.0
    82  stdout '^a@v1.0.0$'
    83  
    84  -- m/go.mod --
    85  module m
    86  
    87  go 1.16
    88  
    89  require example.com/cmd v1.1.0-doesnotexist
    90  -- x/x.go --
    91  package main
    92  
    93  func main() {}
    94  -- replace-err --
    95  go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace):
    96  	The go.mod file for the module providing named packages contains one or
    97  	more replace directives. It must not contain directives that would cause
    98  	it to be interpreted differently than if it were the main module.
    99  -- exclude-err --
   100  go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude):
   101  	The go.mod file for the module providing named packages contains one or
   102  	more exclude directives. It must not contain directives that would cause
   103  	it to be interpreted differently than if it were the main module.
   104  

View as plain text