| 1 |
env GO111MODULE=on |
| 2 |
[short] skip |
| 3 |
|
| 4 |
# -mod=readonly must not resolve missing modules nor update go.mod |
| 5 |
env GOFLAGS=-mod=readonly |
| 6 |
go mod edit -fmt |
| 7 |
cp go.mod go.mod.empty |
| 8 |
! go list all |
| 9 |
stderr '^x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly' |
| 10 |
! stderr '\(\)' # If we don't have a reason for -mod=readonly, don't log an empty one. |
| 11 |
cmp go.mod go.mod.empty |
| 12 |
|
| 13 |
# -mod=readonly should be set by default. |
| 14 |
env GOFLAGS= |
| 15 |
! go list all |
| 16 |
stderr '^x.go:2:8: no required module provides package rsc\.io/quote; to add it:\n\tgo get rsc\.io/quote$' |
| 17 |
cmp go.mod go.mod.empty |
| 18 |
|
| 19 |
env GOFLAGS=-mod=readonly |
| 20 |
|
| 21 |
# update go.mod - go get allowed |
| 22 |
go get rsc.io/quote |
| 23 |
grep rsc.io/quote go.mod |
| 24 |
|
| 25 |
# update go.mod - go mod tidy allowed |
| 26 |
cp go.mod.empty go.mod |
| 27 |
go mod tidy |
| 28 |
cp go.mod go.mod.tidy |
| 29 |
|
| 30 |
# -mod=readonly must succeed once go.mod is up-to-date... |
| 31 |
go list all |
| 32 |
|
| 33 |
# ... even if it needs downloads |
| 34 |
go clean -modcache |
| 35 |
go list all |
| 36 |
|
| 37 |
# -mod=readonly must not cause 'go list -m' to fail. |
| 38 |
# (golang.org/issue/36478) |
| 39 |
go list -m all |
| 40 |
! stderr 'cannot query module' |
| 41 |
|
| 42 |
# -mod=readonly should reject inconsistent go.mod files |
| 43 |
# (ones that would be rewritten). |
| 44 |
go get rsc.io/[email protected] |
| 45 |
go mod edit -require rsc.io/[email protected] |
| 46 |
cp go.mod go.mod.inconsistent |
| 47 |
! go list |
| 48 |
stderr 'go: updates to go.mod needed, disabled by -mod=readonly' |
| 49 |
cmp go.mod go.mod.inconsistent |
| 50 |
|
| 51 |
# We get a different message when -mod=readonly is used by default. |
| 52 |
env GOFLAGS= |
| 53 |
! go list |
| 54 |
stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy' |
| 55 |
|
| 56 |
# However, it should not reject files missing a 'go' directive, |
| 57 |
# since that was not always required. |
| 58 |
cp go.mod.nogo go.mod |
| 59 |
go list all |
| 60 |
cmp go.mod go.mod.nogo |
| 61 |
|
| 62 |
# Nor should it reject files with redundant (not incorrect) |
| 63 |
# requirements. |
| 64 |
cp go.mod.redundant go.mod |
| 65 |
go list all |
| 66 |
cmp go.mod go.mod.redundant |
| 67 |
|
| 68 |
cp go.mod.indirect go.mod |
| 69 |
go list all |
| 70 |
cmp go.mod go.mod.indirect |
| 71 |
|
| 72 |
|
| 73 |
# If we identify a missing package as a dependency of some other package in the |
| 74 |
# main module, we should suggest 'go mod tidy' instead of resolving it. |
| 75 |
|
| 76 |
cp go.mod.untidy go.mod |
| 77 |
! go list all |
| 78 |
stderr '^x.go:2:8: no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$' |
| 79 |
|
| 80 |
! go list -deps . |
| 81 |
stderr '^x.go:2:8: no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$' |
| 82 |
|
| 83 |
# However, if we didn't see an import from the main module, we should suggest |
| 84 |
# 'go get' instead, because we don't know whether 'go mod tidy' would add it. |
| 85 |
! go list rsc.io/quote |
| 86 |
stderr '^no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$' |
| 87 |
|
| 88 |
|
| 89 |
-- go.mod -- |
| 90 |
module m |
| 91 |
|
| 92 |
go 1.16 |
| 93 |
|
| 94 |
-- x.go -- |
| 95 |
package x |
| 96 |
import _ "rsc.io/quote" |
| 97 |
-- go.mod.nogo -- |
| 98 |
module m |
| 99 |
|
| 100 |
require ( |
| 101 |
rsc.io/quote v1.5.2 |
| 102 |
rsc.io/testonly v1.0.0 // indirect |
| 103 |
) |
| 104 |
-- go.mod.redundant -- |
| 105 |
module m |
| 106 |
|
| 107 |
go 1.16 |
| 108 |
|
| 109 |
require ( |
| 110 |
rsc.io/quote v1.5.2 |
| 111 |
rsc.io/sampler v1.3.0 // indirect |
| 112 |
rsc.io/testonly v1.0.0 // indirect |
| 113 |
) |
| 114 |
-- go.mod.indirect -- |
| 115 |
module m |
| 116 |
|
| 117 |
go 1.16 |
| 118 |
|
| 119 |
require ( |
| 120 |
rsc.io/quote v1.5.2 // indirect |
| 121 |
rsc.io/sampler v1.3.0 // indirect |
| 122 |
rsc.io/testonly v1.0.0 // indirect |
| 123 |
) |
| 124 |
-- go.mod.untidy -- |
| 125 |
module m |
| 126 |
|
| 127 |
go 1.16 |
| 128 |
|
| 129 |
require ( |
| 130 |
rsc.io/sampler v1.3.0 // indirect |
| 131 |
) |