| 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/[email protected] |
| 10 |
stdout '^[email protected]$' |
| 11 |
|
| 12 |
|
| 13 |
# 'go run pkg@version' reports an error if modules are disabled. |
| 14 |
env GO111MODULE=off |
| 15 |
! go run example.com/cmd/[email protected] |
| 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/[email protected]: 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/[email protected]: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/cmd$' |
| 26 |
go run example.com/cmd/[email protected] |
| 27 |
stdout '^[email protected]$' |
| 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/[email protected] |
| 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/[email protected] |
| 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/[email protected] |
| 48 |
! go run example.com/cmd/[email protected] |
| 49 |
cmp stderr replace-err |
| 50 |
|
| 51 |
go mod download example.com/[email protected] |
| 52 |
! go run example.com/cmd/[email protected] |
| 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/[email protected] |
| 59 |
! go run $GOPATH/pkg/mod/rsc.io/[email protected] |
| 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/[email protected] |
| 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/[email protected] |
| 67 |
! go run -mod=readonly $GOPATH/pkg/mod/rsc.io/[email protected] |
| 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/[email protected] |
| 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/[email protected] example.com/[email protected] |
| 77 |
stdout '^[email protected]$' |
| 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/[email protected] |
| 83 |
stdout '^[email protected]$' |
| 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/[email protected]$' |
| 89 |
stdout '^[email protected]$' |
| 90 |
go run example.com/deprecated/a/cmd/[email protected] |
| 91 |
stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/[email protected]$' |
| 92 |
stdout '^[email protected]$' |
| 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/[email protected] |
| 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/[email protected] (in example.com/[email protected]): |
| 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/[email protected] (in example.com/[email protected]): |
| 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. |