...

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

Documentation: cmd/go/testdata/script

     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.
     8env GO111MODULE=auto
     9go run example.com/cmd/a@v1.0.0
    10stdout '^a@v1.0.0$'
    11
    12
    13# 'go run pkg@version' reports an error if modules are disabled.
    14env GO111MODULE=off
    15! go run example.com/cmd/a@v1.0.0
    16stderr '^go: modules disabled by GO111MODULE=off; see ''go help modules''$'
    17env GO111MODULE=on
    18
    19
    20# 'go run pkg@version' ignores go.mod in the current directory.
    21cd m
    22cp go.mod go.mod.orig
    23! go list -m all
    24stderr '^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$'
    25stderr '^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$'
    26go run example.com/cmd/a@v1.0.0
    27stdout '^a@v1.0.0$'
    28cmp go.mod go.mod.orig
    29cd ..
    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.
    35go run rsc.io/fortune@v1.0.0
    36stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$'
    37stderr '^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
    42stderr '^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.
    47go mod download example.com/cmd@v1.0.0-replace
    48! go run example.com/cmd/a@v1.0.0-replace
    49cmp stderr replace-err
    50
    51go mod download example.com/cmd@v1.0.0-exclude
    52! go run example.com/cmd/a@v1.0.0-exclude
    53cmp 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.
    58go mod download rsc.io/fortune@v1.0.0
    59! go run $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    60stderr '^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
    62stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    63mkdir tmp
    64cd tmp
    65go mod init tmp
    66go mod edit -require=rsc.io/fortune@v1.0.0
    67! go run -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    68stderr '^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
    70stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    71cd ..
    72rm tmp
    73
    74
    75# 'go run' does not interpret @version arguments after the first.
    76go run example.com/cmd/a@v1.0.0 example.com/doesnotexist@v1.0.0
    77stdout '^a@v1.0.0$'
    78
    79
    80# 'go run pkg@version' succeeds when -mod=readonly is set explicitly.
    81# Verifies #43278.
    82go run -mod=readonly example.com/cmd/a@v1.0.0
    83stdout '^a@v1.0.0$'
    84
    85
    86# 'go run pkg@version' should show a deprecation message if the module is deprecated.
    87go run example.com/deprecated/a/cmd/a@latest
    88stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
    89stdout '^a@v1.9.0$'
    90go run example.com/deprecated/a/cmd/a@v1.0.0
    91stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
    92stdout '^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.
    96go run example.com/undeprecated/cmd/a@v1.0.0
    97! stderr 'module.*is deprecated'
    98
    99-- m/go.mod --
   100module m
   101
   102go 1.16
   103
   104require example.com/cmd v1.1.0-doesnotexist
   105-- x/x.go --
   106package main
   107
   108func main() {}
   109-- replace-err --
   110go: 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 --
   115go: 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.

View as plain text