aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_readonly.txt
blob: f2c77de806294fbfe2bb9c7ee89d373dc43819eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
env GO111MODULE=on
[short] skip

# -mod=readonly must not resolve missing modules nor update go.mod
env GOFLAGS=-mod=readonly
go mod edit -fmt
cp go.mod go.mod.empty
! go list all
stderr '^x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly'
! stderr '\(\)' # If we don't have a reason for -mod=readonly, don't log an empty one.
cmp go.mod go.mod.empty

# -mod=readonly should be set by default.
env GOFLAGS=
! go list all
stderr '^x.go:2:8: no required module provides package rsc\.io/quote; try ''go mod tidy'' to add it$'
cmp go.mod go.mod.empty

env GOFLAGS=-mod=readonly

# update go.mod - go get allowed
go get rsc.io/quote
grep rsc.io/quote go.mod

# update go.mod - go mod tidy allowed
cp go.mod.empty go.mod
go mod tidy
cp go.mod go.mod.tidy

# -mod=readonly must succeed once go.mod is up-to-date...
go list all

# ... even if it needs downloads
go clean -modcache
go list all

# -mod=readonly must not cause 'go list -m' to fail.
# (golang.org/issue/36478)
go list -m all
! stderr 'cannot query module'

# -mod=readonly should reject inconsistent go.mod files
# (ones that would be rewritten).
go get -d rsc.io/sampler@v1.2.0
go mod edit -require rsc.io/quote@v1.5.2
cp go.mod go.mod.inconsistent
! go list
stderr 'go: updates to go.mod needed, disabled by -mod=readonly'
cmp go.mod go.mod.inconsistent

# We get a different message when -mod=readonly is used by default.
env GOFLAGS=
! go list
stderr '^go: updates to go.mod needed; try ''go mod tidy'' first$'

# However, it should not reject files missing a 'go' directive,
# since that was not always required.
cp go.mod.nogo go.mod
go list all
cmp go.mod go.mod.nogo

# Nor should it reject files with redundant (not incorrect)
# requirements.
cp go.mod.redundant go.mod
go list all
cmp go.mod go.mod.redundant

cp go.mod.indirect go.mod
go list all
cmp go.mod go.mod.indirect


# If we identify a missing package as a dependency of some other package in the
# main module, we should suggest 'go mod tidy' instead of resolving it.

cp go.mod.untidy go.mod
! go list all
stderr '^x.go:2:8: no required module provides package rsc.io/quote; try ''go mod tidy'' to add it$'

! go list -deps .
stderr '^x.go:2:8: no required module provides package rsc.io/quote; try ''go mod tidy'' to add it$'

# However, if we didn't see an import from the main module, we should suggest
# 'go get -d' instead, because we don't know whether 'go mod tidy' would add it.
! go list rsc.io/quote
stderr '^no required module provides package rsc.io/quote; try ''go get -d rsc.io/quote'' to add it$'


-- go.mod --
module m

go 1.20

-- x.go --
package x
import _ "rsc.io/quote"
-- go.mod.nogo --
module m

require (
	rsc.io/quote v1.5.2
	rsc.io/testonly v1.0.0 // indirect
)
-- go.mod.redundant --
module m

go 1.20

require (
	rsc.io/quote v1.5.2
	rsc.io/sampler v1.3.0 // indirect
	rsc.io/testonly v1.0.0 // indirect
)
-- go.mod.indirect --
module m

go 1.20

require (
	rsc.io/quote v1.5.2 // indirect
	rsc.io/sampler v1.3.0 // indirect
	rsc.io/testonly v1.0.0 // indirect
)
-- go.mod.untidy --
module m

go 1.20

require (
	rsc.io/sampler v1.3.0 // indirect
)