1 env GO111MODULE=on
2 [short] skip
3
4 cp go.mod go.mod.orig
5
6 # Make sure the test builds without replacement.
7 go build -mod=mod -o a1.exe .
8 exec ./a1.exe
9 stdout 'Don''t communicate by sharing memory'
10
11 # Modules can be replaced by local packages.
12 cp go.mod.orig go.mod
13 go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3
14 go build -o a2.exe .
15 exec ./a2.exe
16 stdout 'Concurrency is not parallelism.'
17
18 # The module path of the replacement doesn't need to match.
19 # (For example, it could be a long-running fork with its own import path.)
20 cp go.mod.orig go.mod
21 go mod edit -replace=rsc.io/quote/v3=./local/not-rsc.io/quote/v3
22 go build -o a3.exe .
23 exec ./a3.exe
24 stdout 'Clear is better than clever.'
25
26 # However, the same module can't be used as two different paths.
27 cp go.mod.orig go.mod
28 go mod edit -replace=not-rsc.io/quote/v3@v3.0.0=rsc.io/quote/v3@v3.0.0 -require=not-rsc.io/quote/v3@v3.0.0
29 ! go build -o a4.exe .
30 stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
31
32 # Modules that do not (yet) exist upstream can be replaced too.
33 cp go.mod.orig go.mod
34 go mod edit -replace=not-rsc.io/quote/v3@v3.1.0=./local/rsc.io/quote/v3
35 go build -mod=mod -o a5.exe ./usenewmodule
36 ! stderr 'finding not-rsc.io/quote/v3'
37 grep 'not-rsc.io/quote/v3 v3.1.0' go.mod
38 exec ./a5.exe
39 stdout 'Concurrency is not parallelism.'
40
41 # Error messages for modules not found in replacements should
42 # indicate the replacement module.
43 cp go.mod.orig go.mod
44 go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3
45 ! go get rsc.io/quote/v3/missing-package
46 stderr 'module rsc.io/quote/v3@upgrade found \(v3.0.0, replaced by ./local/rsc.io/quote/v3\), but does not contain package'
47
48 # The reported Dir and GoMod for a replaced module should be accurate.
49 cp go.mod.orig go.mod
50 go mod edit -replace=rsc.io/quote/v3=not-rsc.io/quote@v0.1.0-nomod
51 go mod download rsc.io/quote/v3
52 go list -m -f '{{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{with .Replace}} => {{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' rsc.io/quote/v3
53 stdout '^rsc.io/quote/v3 v3.0.0 '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod => not-rsc.io/quote v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod$'
54
55 -- go.mod --
56 module quoter
57
58 require rsc.io/quote/v3 v3.0.0
59
60 -- main.go --
61 package main
62
63 import (
64 "fmt"
65 "rsc.io/quote/v3"
66 )
67
68 func main() {
69 fmt.Println(quote.GoV3())
70 }
71
72 -- usenewmodule/main.go --
73 package main
74
75 import (
76 "fmt"
77 "not-rsc.io/quote/v3"
78 )
79
80 func main() {
81 fmt.Println(quote.GoV3())
82 }
83
84 -- local/rsc.io/quote/v3/go.mod --
85 module rsc.io/quote/v3
86
87 require rsc.io/sampler v1.3.0
88
89 -- local/rsc.io/quote/v3/quote.go --
90 // Copyright 2018 The Go Authors. All rights reserved.
91 // Use of this source code is governed by a BSD-style
92 // license that can be found in the LICENSE file.
93
94 // Package quote collects pithy sayings.
95 package quote
96
97 import "rsc.io/sampler"
98
99 // Hello returns a greeting.
100 func HelloV3() string {
101 return sampler.Hello()
102 }
103
104 // Glass returns a useful phrase for world travelers.
105 func GlassV3() string {
106 // See http://www.oocities.org/nodotus/hbglass.html.
107 return "I can eat glass and it doesn't hurt me."
108 }
109
110 // Go returns a REPLACED Go proverb.
111 func GoV3() string {
112 return "Concurrency is not parallelism."
113 }
114
115 // Opt returns a optimization truth.
116 func OptV3() string {
117 // Wisdom from ken.
118 return "If a program is too slow, it must have a loop."
119 }
120
121 -- local/not-rsc.io/quote/v3/go.mod --
122 module not-rsc.io/quote/v3
123
124 -- local/not-rsc.io/quote/v3/quote.go --
125 package quote
126
127 func GoV3() string {
128 return "Clear is better than clever."
129 }
130
View as plain text