aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_readonly.txt
blob: ac581264f1f7ebac285ceb4186ec49fd1dab82f8 (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
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 implicitly if the go.mod file is read-only
chmod 0400 go.mod
env GOFLAGS=
! go list all
stderr '^x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly\n\t\(go.mod file is read-only\.\)$'

chmod 0600 go.mod
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 mod edit -require rsc.io/sampler@v1.2.0
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

# 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

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

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

-- 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
)