...

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-- m/go.mod --
    86module m
    87
    88go 1.16
    89
    90require example.com/cmd v1.1.0-doesnotexist
    91-- x/x.go --
    92package main
    93
    94func main() {}
    95-- replace-err --
    96go: 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 --
   101go: 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.

View as plain text