...
1# Check that with -mod=readonly, when we load a package in a module that is
2# replaced but not required, we emit an error with the command to add the
3# requirement.
4# Verifies golang.org/issue/41416, golang.org/issue/41577.
5cp go.mod go.mod.orig
6
7# Replace all versions of a module without requiring it.
8# With -mod=mod, we'd add a requirement for a "zero" pseudo-version, but we
9# can't in readonly mode, since its go.mod may alter the build list.
10go mod edit -replace rsc.io/quote=./quote
11! go list rsc.io/quote
12stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote$'
13go get rsc.io/quote
14cmp go.mod go.mod.latest
15go list rsc.io/quote
16cp go.mod.orig go.mod
17
18# Same test with a specific version.
19go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote
20! go list rsc.io/quote
21stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.0.0-doesnotexist$'
22go get rsc.io/quote@v1.0.0-doesnotexist
23cmp go.mod go.mod.specific
24go list rsc.io/quote
25cp go.mod.orig go.mod
26
27# If there are multiple versions, the highest is suggested.
28go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote
29go mod edit -replace rsc.io/quote@v1.1.0-doesnotexist=./quote
30! go list rsc.io/quote
31stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.1.0-doesnotexist$'
32
33-- go.mod --
34module m
35
36go 1.16
37-- go.mod.latest --
38module m
39
40go 1.16
41
42replace rsc.io/quote => ./quote
43
44require rsc.io/quote v1.5.2 // indirect
45-- go.mod.specific --
46module m
47
48go 1.16
49
50replace rsc.io/quote v1.0.0-doesnotexist => ./quote
51
52require rsc.io/quote v1.0.0-doesnotexist // indirect
53-- use.go --
54package use
55
56import _ "rsc.io/quote"
57-- quote/go.mod --
58module rsc.io/quote
59
60go 1.16
61-- quote/quote.go --
62package quote
View as plain text