| 1 |
env GO111MODULE=on |
| 2 |
env GOFLAGS=-mod=mod |
| 3 |
[short] skip |
| 4 |
|
| 5 |
# golang.org/issue/30166: 'go mod tidy' should not crash if a replaced module is |
| 6 |
# involved in a cycle. |
| 7 |
cd cycle |
| 8 |
env GOTRACEBACK=off |
| 9 |
go mod tidy |
| 10 |
cd .. |
| 11 |
|
| 12 |
# From inside the module, 'go list -m all' should NOT include transitive |
| 13 |
# requirements of modules that have been replaced. |
| 14 |
go list -m all |
| 15 |
stdout 'rsc.io/quote/v3 v3.0.0' |
| 16 |
! stdout 'rsc.io/sampler' |
| 17 |
! stdout 'golang.org/x/text' |
| 18 |
|
| 19 |
# From outside the module, 'go list -m all' should include them. |
| 20 |
cd outside |
| 21 |
go list -m all |
| 22 |
stdout 'rsc.io/quote/v3 v3.0.0' |
| 23 |
stdout 'rsc.io/sampler v1.3.0' |
| 24 |
stdout 'golang.org/x/text' |
| 25 |
cd .. |
| 26 |
|
| 27 |
# 'go list all' should add indirect requirements to satisfy the packages |
| 28 |
# imported from replacement modules. |
| 29 |
! grep 'rsc.io/sampler' go.mod |
| 30 |
! grep 'golang.org/x/text' go.mod |
| 31 |
go list all |
| 32 |
grep 'rsc.io/sampler' go.mod |
| 33 |
grep 'golang.org/x/text' go.mod |
| 34 |
|
| 35 |
# 'go get' and 'go mod tidy' should follow the requirements of the replacements, |
| 36 |
# not the originals, even if that results in a set of versions that are |
| 37 |
# misleading or redundant without those replacements. |
| 38 |
go get rsc.io/[email protected] |
| 39 |
go mod tidy |
| 40 |
go list -m all |
| 41 |
stdout 'rsc.io/quote/v3 v3.0.0' |
| 42 |
stdout 'rsc.io/sampler v1.2.0' |
| 43 |
stdout 'golang.org/x/text' |
| 44 |
|
| 45 |
# The requirements seen from outside may be higher (or lower) |
| 46 |
# than those seen from within the module. |
| 47 |
grep 'rsc.io/sampler v1.2.0' go.mod |
| 48 |
cd outside |
| 49 |
go list -m all |
| 50 |
stdout 'rsc.io/sampler v1.3.0' |
| 51 |
cd .. |
| 52 |
|
| 53 |
# The same module can't be used as two different paths. |
| 54 |
cd multiple-paths |
| 55 |
! go mod tidy |
| 56 |
stderr 'rsc.io/quote/[email protected] used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)' |
| 57 |
|
| 58 |
-- go.mod -- |
| 59 |
module example.com/tidy |
| 60 |
|
| 61 |
require rsc.io/quote/v3 v3.0.0 |
| 62 |
replace rsc.io/quote/v3 => ./not-rsc.io/quote/v3 |
| 63 |
|
| 64 |
-- imports.go -- |
| 65 |
package tidy |
| 66 |
|
| 67 |
import _ "rsc.io/quote/v3" |
| 68 |
|
| 69 |
-- outside/go.mod -- |
| 70 |
module example.com/tidy/outside |
| 71 |
|
| 72 |
require example.com/tidy v0.0.0 |
| 73 |
replace example.com/tidy => ./.. |
| 74 |
|
| 75 |
-- not-rsc.io/quote/v3/go.mod -- |
| 76 |
module not-rsc.io/quote/v3 |
| 77 |
|
| 78 |
// No requirements specified! |
| 79 |
|
| 80 |
-- not-rsc.io/quote/v3/quote.go -- |
| 81 |
package quote |
| 82 |
|
| 83 |
import ( |
| 84 |
_ "rsc.io/sampler" |
| 85 |
_ "golang.org/x/text/language" |
| 86 |
) |
| 87 |
|
| 88 |
-- cycle/go.mod -- |
| 89 |
module golang.org/issue/30166 |
| 90 |
|
| 91 |
require ( |
| 92 |
golang.org/issue/30166/a v0.0.0 |
| 93 |
golang.org/issue/30166/b v0.0.0 |
| 94 |
) |
| 95 |
|
| 96 |
replace ( |
| 97 |
golang.org/issue/30166/a => ./a |
| 98 |
golang.org/issue/30166/b => ./b |
| 99 |
) |
| 100 |
-- cycle/cycle.go -- |
| 101 |
package cycle |
| 102 |
|
| 103 |
import ( |
| 104 |
_ "golang.org/issue/30166/a" |
| 105 |
_ "golang.org/issue/30166/b" |
| 106 |
) |
| 107 |
-- cycle/a/a.go -- |
| 108 |
package a |
| 109 |
-- cycle/a/go.mod -- |
| 110 |
module golang.org/issue/30166/a |
| 111 |
|
| 112 |
require golang.org/issue/30166/b v0.0.0 |
| 113 |
-- cycle/b/b.go -- |
| 114 |
package b |
| 115 |
-- cycle/b/go.mod -- |
| 116 |
module golang.org/issue/30166/b |
| 117 |
|
| 118 |
require golang.org/issue/30166/a v0.0.0 |
| 119 |
-- multiple-paths/main.go -- |
| 120 |
package main |
| 121 |
|
| 122 |
import ( |
| 123 |
"fmt" |
| 124 |
"rsc.io/quote/v3" |
| 125 |
) |
| 126 |
|
| 127 |
func main() { |
| 128 |
fmt.Println(quote.GoV3()) |
| 129 |
} |
| 130 |
-- multiple-paths/go.mod -- |
| 131 |
module quoter |
| 132 |
|
| 133 |
require ( |
| 134 |
rsc.io/quote/v3 v3.0.0 |
| 135 |
not-rsc.io/quote/v3 v3.0.0 |
| 136 |
) |
| 137 |
|
| 138 |
replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0 |
| 139 |
-- multiple-paths/use.go -- |
| 140 |
package quoter |
| 141 |
|
| 142 |
import ( |
| 143 |
_ "not-rsc.io/quote/v3" |
| 144 |
_ "rsc.io/quote/v3" |
| 145 |
) |