| 1 |
[!net:golang.org] skip |
| 2 |
[!git] skip |
| 3 |
|
| 4 |
env GO111MODULE=on |
| 5 |
env GOPROXY=direct |
| 6 |
env GOSUMDB=off |
| 7 |
env GOFLAGS=-mod=mod |
| 8 |
|
| 9 |
# Regression test for golang.org/issue/27173: if the user (or go.mod file) |
| 10 |
# requests a pseudo-version that does not match both the module path and commit |
| 11 |
# metadata, reject it with a helpful error message. |
| 12 |
# |
| 13 |
# TODO(bcmills): Replace the github.com/pierrec/lz4 examples with something |
| 14 |
# equivalent on vcs-test.golang.org. |
| 15 |
|
| 16 |
# An incomplete commit hash is not a valid semantic version, |
| 17 |
# but can appear in the main go.mod file anyway and should be resolved. |
| 18 |
cp go.mod.orig go.mod |
| 19 |
go mod edit -require golang.org/x/text@14c0d48ead0c |
| 20 |
cd outside |
| 21 |
! go list -m golang.org/x/text |
| 22 |
stderr 'go: [email protected] \(replaced by \./\.\.\): parsing ..[/\\]go.mod: '$WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "14c0d48ead0c" invalid: must be of the form v1.2.3' |
| 23 |
cd .. |
| 24 |
go list -m golang.org/x/text |
| 25 |
stdout 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' |
| 26 |
grep 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' go.mod |
| 27 |
|
| 28 |
# A module path below the repo root that does not contain a go.mod file is invalid. |
| 29 |
cp go.mod.orig go.mod |
| 30 |
go mod edit -require golang.org/x/text/[email protected] |
| 31 |
cd outside |
| 32 |
! go list -m golang.org/x/text |
| 33 |
stderr 'go: [email protected] requires\n\tgolang.org/x/text/[email protected]: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c' |
| 34 |
cd .. |
| 35 |
! go list -m golang.org/x/text |
| 36 |
stderr 'golang.org/x/text/[email protected]: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c' |
| 37 |
|
| 38 |
# However, arguments to 'go get' can name packages above the root. |
| 39 |
cp go.mod.orig go.mod |
| 40 |
go get golang.org/x/text/[email protected] |
| 41 |
go list -m golang.org/x/text/... |
| 42 |
stdout 'golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c' |
| 43 |
! stdout 'golang.org/x/text/unicode' |
| 44 |
|
| 45 |
# A major version that does not match the module path is invalid. |
| 46 |
cp go.mod.orig go.mod |
| 47 |
go mod edit -require golang.org/x/[email protected] |
| 48 |
cd outside |
| 49 |
! go list -m golang.org/x/text |
| 50 |
stderr 'go: [email protected] \(replaced by \./\.\.\): parsing ..[/\\]go.mod: '$WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "v2.1.1-0.20170915032832-14c0d48ead0c" invalid: should be v0 or v1, not v2' |
| 51 |
cd .. |
| 52 |
! go list -m golang.org/x/text |
| 53 |
stderr '^go.mod:5: require golang.org/x/text: version "v2.1.1-0.20170915032832-14c0d48ead0c" invalid: should be v0 or v1, not v2' |
| 54 |
|
| 55 |
# A pseudo-version with fewer than 12 digits of SHA-1 prefix is invalid. |
| 56 |
cp go.mod.orig go.mod |
| 57 |
go mod edit -require golang.org/x/[email protected] |
| 58 |
cd outside |
| 59 |
! go list -m golang.org/x/text |
| 60 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: revision is shorter than canonical \(expected 14c0d48ead0c\)' |
| 61 |
cd .. |
| 62 |
! go list -m golang.org/x/text |
| 63 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: revision is shorter than canonical \(expected 14c0d48ead0c\)' |
| 64 |
|
| 65 |
# A pseudo-version with more than 12 digits of SHA-1 prefix is invalid. |
| 66 |
cp go.mod.orig go.mod |
| 67 |
go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a |
| 68 |
cd outside |
| 69 |
! go list -m golang.org/x/text |
| 70 |
stderr 'go: [email protected] requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a: invalid pseudo-version: revision is longer than canonical \(expected 14c0d48ead0c\)' |
| 71 |
cd .. |
| 72 |
! go list -m golang.org/x/text |
| 73 |
stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a: invalid pseudo-version: revision is longer than canonical \(expected 14c0d48ead0c\)' |
| 74 |
|
| 75 |
# A pseudo-version that does not match the commit timestamp is invalid. |
| 76 |
cp go.mod.orig go.mod |
| 77 |
go mod edit -require golang.org/x/[email protected] |
| 78 |
cd outside |
| 79 |
! go list -m golang.org/x/text |
| 80 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)' |
| 81 |
cd .. |
| 82 |
! go list -m golang.org/x/text |
| 83 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)' |
| 84 |
|
| 85 |
# A 'replace' directive in the main module can replace an invalid timestamp |
| 86 |
# with a valid one. |
| 87 |
go mod edit -replace golang.org/x/[email protected]=golang.org/x/text@14c0d48ead0c |
| 88 |
cd outside |
| 89 |
! go list -m golang.org/x/text |
| 90 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)' |
| 91 |
cd .. |
| 92 |
go list -m golang.org/x/text |
| 93 |
stdout 'golang.org/x/text v0.1.1-0.20190915032832-14c0d48ead0c => golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' |
| 94 |
|
| 95 |
# A pseudo-version that is not derived from a tag is invalid. |
| 96 |
cp go.mod.orig go.mod |
| 97 |
go mod edit -require golang.org/x/[email protected] |
| 98 |
cd outside |
| 99 |
! go list -m golang.org/x/text |
| 100 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: preceding tag \(v1.999.998\) not found' |
| 101 |
cd .. |
| 102 |
! go list -m golang.org/x/text |
| 103 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: preceding tag \(v1.999.998\) not found' |
| 104 |
|
| 105 |
# A v1.0.0- pseudo-version that is not derived from a tag is invalid: |
| 106 |
# v1.0.0- implies no tag, but the correct no-tag prefix for a module path |
| 107 |
# without a major-version suffix is v0.0.0-. |
| 108 |
cp go.mod.orig go.mod |
| 109 |
go mod edit -require golang.org/x/[email protected] |
| 110 |
cd outside |
| 111 |
! go list -m golang.org/x/text |
| 112 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: major version without preceding tag must be v0, not v1' |
| 113 |
cd .. |
| 114 |
! go list -m golang.org/x/text |
| 115 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: major version without preceding tag must be v0, not v1' |
| 116 |
|
| 117 |
# A pseudo-version vX.Y.Z+1 cannot have Z+1 == 0, since that would |
| 118 |
# imply a base tag with a negative patch field. |
| 119 |
cp go.mod.orig go.mod |
| 120 |
go mod edit -require golang.org/x/[email protected] |
| 121 |
cd outside |
| 122 |
! go list -m golang.org/x/text |
| 123 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: version before v0.0.0 would have negative patch number' |
| 124 |
cd .. |
| 125 |
! go list -m golang.org/x/text |
| 126 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: version before v0.0.0 would have negative patch number' |
| 127 |
|
| 128 |
# A 'replace' directive in the main module can replace an |
| 129 |
# invalid pseudo-version base with a valid one. |
| 130 |
go mod edit -replace golang.org/x/[email protected]=golang.org/x/[email protected] |
| 131 |
cd outside |
| 132 |
! go list -m golang.org/x/text |
| 133 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: version before v0.0.0 would have negative patch number' |
| 134 |
cd .. |
| 135 |
go list -m golang.org/x/text |
| 136 |
stdout 'golang.org/x/text v0.0.0-0.20170915032832-14c0d48ead0c => golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c' |
| 137 |
|
| 138 |
# A 'replace' directive can replace an invalid 'latest' version, and |
| 139 |
# should suppress errors for that version in 'go get -u' |
| 140 |
cp go.mod.orig go.mod |
| 141 |
go mod edit -require golang.org/x/[email protected] |
| 142 |
go mod edit -replace golang.org/x/[email protected]=golang.org/x/[email protected] |
| 143 |
cd outside |
| 144 |
! go get golang.org/x/text@upgrade |
| 145 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: reading golang.org/x/text/go.mod at revision v1.999999.0: unknown revision v1.999999.0' |
| 146 |
cd .. |
| 147 |
go get golang.org/x/text@upgrade |
| 148 |
go list -m golang.org/x/text |
| 149 |
stdout 'golang.org/x/text v1.999999.0 => golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c' |
| 150 |
|
| 151 |
# A pseudo-version derived from a non-ancestor tag is invalid. |
| 152 |
cp go.mod.orig go.mod |
| 153 |
go mod edit -require golang.org/x/[email protected] |
| 154 |
cd outside |
| 155 |
! go list -m golang.org/x/text |
| 156 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: revision 14c0d48ead0c is not a descendent of preceding tag \(v0.2.0\)' |
| 157 |
cd .. |
| 158 |
! go list -m golang.org/x/text |
| 159 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: revision 14c0d48ead0c is not a descendent of preceding tag \(v0.2.0\)' |
| 160 |
|
| 161 |
# A pseudo-version derived from a canonical tag on the same revision is invalid. |
| 162 |
cp go.mod.orig go.mod |
| 163 |
go mod edit -require golang.org/x/[email protected] |
| 164 |
cd outside |
| 165 |
! go list -m golang.org/x/text |
| 166 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]: invalid pseudo-version: tag \(v0.2.0\) found on revision c4d099d611ac is already canonical, so should not be replaced with a pseudo-version derived from that tag' |
| 167 |
cd .. |
| 168 |
! go list -m golang.org/x/text |
| 169 |
stderr 'golang.org/x/[email protected]: invalid pseudo-version: tag \(v0.2.0\) found on revision c4d099d611ac is already canonical, so should not be replaced with a pseudo-version derived from that tag' |
| 170 |
|
| 171 |
# A +incompatible suffix is not allowed on a version that is actually compatible. |
| 172 |
cp go.mod.orig go.mod |
| 173 |
go mod edit -require golang.org/x/[email protected]+incompatible |
| 174 |
cd outside |
| 175 |
! go list -m golang.org/x/text |
| 176 |
stderr 'go: [email protected] requires\n\tgolang.org/x/[email protected]\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible' |
| 177 |
cd .. |
| 178 |
! go list -m golang.org/x/text |
| 179 |
stderr 'golang.org/x/[email protected]\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible' |
| 180 |
|
| 181 |
[!net:github.com] stop |
| 182 |
|
| 183 |
# The pseudo-version for a commit after a tag with a non-matching major version |
| 184 |
# should instead be based on the last matching tag. |
| 185 |
cp go.mod.orig go.mod |
| 186 |
go mod edit -require github.com/pierrec/lz4@473cd7ce01a1 |
| 187 |
go list -m github.com/pierrec/lz4 |
| 188 |
stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1' |
| 189 |
cd outside |
| 190 |
go list -m github.com/pierrec/lz4 |
| 191 |
stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1' |
| 192 |
cd .. |
| 193 |
|
| 194 |
# A +incompatible pseudo-version for a module that has an explicit go.mod file is invalid. |
| 195 |
cp go.mod.orig go.mod |
| 196 |
go mod edit -require github.com/pierrec/[email protected]+incompatible |
| 197 |
cd outside |
| 198 |
! go list -m github.com/pierrec/lz4 |
| 199 |
stderr '^go: [email protected] requires\n\tgithub.com/pierrec/[email protected]\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' |
| 200 |
cd .. |
| 201 |
! go list -m github.com/pierrec/lz4 |
| 202 |
stderr '^go: github.com/pierrec/[email protected]\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' |
| 203 |
|
| 204 |
# A +incompatible pseudo-version is valid for a revision of the module |
| 205 |
# that lacks a go.mod file. |
| 206 |
cp go.mod.orig go.mod |
| 207 |
go mod edit -require github.com/pierrec/[email protected]+incompatible |
| 208 |
cd outside |
| 209 |
go list -m github.com/pierrec/lz4 |
| 210 |
stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible' |
| 211 |
cd .. |
| 212 |
go list -m github.com/pierrec/lz4 |
| 213 |
stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible' |
| 214 |
|
| 215 |
# 'go get' for a mismatched major version without a go.mod file should resolve |
| 216 |
# to the equivalent +incompatible version, not a pseudo-version with a different |
| 217 |
# major version. |
| 218 |
cp go.mod.orig go.mod |
| 219 |
go get github.com/pierrec/[email protected] |
| 220 |
go list -m github.com/pierrec/lz4 |
| 221 |
stdout 'github.com/pierrec/lz4 v2.0.5\+incompatible' |
| 222 |
|
| 223 |
# 'go get' for a mismatched major version with a go.mod file should error out, |
| 224 |
# not resolve to a pseudo-version with a different major version. |
| 225 |
cp go.mod.orig go.mod |
| 226 |
! go get github.com/pierrec/[email protected] |
| 227 |
stderr 'go: github.com/pierrec/[email protected]: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' |
| 228 |
|
| 229 |
# An invalid +incompatible suffix for a canonical version should error out, |
| 230 |
# not resolve to a pseudo-version. |
| 231 |
# |
| 232 |
# TODO(bcmills): The "outside" view for this failure mode is missing its import stack. |
| 233 |
# Figure out why and fix it. |
| 234 |
cp go.mod.orig go.mod |
| 235 |
go mod edit -require github.com/pierrec/[email protected]+incompatible |
| 236 |
cd outside |
| 237 |
! go list -m github.com/pierrec/lz4 |
| 238 |
stderr '^go: github.com/pierrec/[email protected]\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' |
| 239 |
cd .. |
| 240 |
! go list -m github.com/pierrec/lz4 |
| 241 |
stderr '^go: github.com/pierrec/[email protected]\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' |
| 242 |
|
| 243 |
-- go.mod.orig -- |
| 244 |
module example.com |
| 245 |
|
| 246 |
go 1.13 |
| 247 |
-- outside/go.mod -- |
| 248 |
module example.com/outside |
| 249 |
|
| 250 |
go 1.13 |
| 251 |
|
| 252 |
require example.com v0.0.0 |
| 253 |
replace example.com v0.0.0 => ./.. |