|
| 1 | +# For this module, Go 1.17 prunes out a (transitive and otherwise-irrelevant) |
| 2 | +# requirement on a retracted higher version of a dependency. |
| 3 | +# However, when Go 1.16 reads the same requirements from the go.mod file, |
| 4 | +# it does not prune out that requirement, and selects the retracted version. |
| 5 | +# |
| 6 | +# The Go 1.16 module graph looks like: |
| 7 | +# |
| 8 | +# m ---- lazy v0.1.0 ---- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible |
| 9 | +# | | |
| 10 | +# + -------+------------- incompatible v1.0.0 |
| 11 | +# |
| 12 | +# The Go 1.17 module graph is the same except that the dependencies of |
| 13 | +# requireincompatible are pruned out (because the module that requires |
| 14 | +# it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to |
| 15 | +# the main module). |
| 16 | + |
| 17 | +cp go.mod go.mod.orig |
| 18 | + |
| 19 | +go mod graph |
| 20 | +cp stdout graph-1.17.txt |
| 21 | +stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' |
| 22 | +stdout '^example\.net/lazy@v0\.1\.0 example\.com/retract/incompatible@v1\.0\.0$' |
| 23 | +! stdout 'example\.com/retract/incompatible@v2\.0\.0\+incompatible' |
| 24 | + |
| 25 | +go mod graph -go=1.17 |
| 26 | +cmp stdout graph-1.17.txt |
| 27 | + |
| 28 | +cmp go.mod go.mod.orig |
| 29 | + |
| 30 | + |
| 31 | +# Setting -go=1.16 should report the graph as viewed by Go 1.16, |
| 32 | +# but should not edit the go.mod file. |
| 33 | + |
| 34 | +go mod graph -go=1.16 |
| 35 | +cp stdout graph-1.16.txt |
| 36 | +stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' |
| 37 | +stdout '^example\.net/lazy@v0\.1\.0 example.com/retract/incompatible@v1\.0\.0$' |
| 38 | +stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$' |
| 39 | + |
| 40 | +cmp go.mod go.mod.orig |
| 41 | + |
| 42 | + |
| 43 | +# If we actually update the go.mod file to the requested go version, |
| 44 | +# we should get the same selected versions, but the roots of the graph |
| 45 | +# may be updated. |
| 46 | +# |
| 47 | +# TODO(#45551): The roots should not be updated. |
| 48 | + |
| 49 | +go mod edit -go=1.16 |
| 50 | +go mod graph |
| 51 | +! stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' |
| 52 | +stdout '^example\.net/lazy@v0.1.0 example.com/retract/incompatible@v1\.0\.0$' |
| 53 | +stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$' |
| 54 | + # TODO(#45551): cmp stdout graph-1.16.txt |
| 55 | + |
| 56 | + |
| 57 | +# Unsupported go versions should be rejected, since we don't know |
| 58 | +# what versions they would report. |
| 59 | +! go mod graph -go=1.99999999999 |
| 60 | +stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\]\nRun ''go help mod graph'' for details.$' |
| 61 | + |
| 62 | + |
| 63 | +-- go.mod -- |
| 64 | +// Module m indirectly imports a package from |
| 65 | +// example.com/retract/incompatible. Its selected version of |
| 66 | +// that module is lower under Go 1.17 semantics than under Go 1.16. |
| 67 | +module example.com/m |
| 68 | + |
| 69 | +go 1.17 |
| 70 | + |
| 71 | +replace ( |
| 72 | + example.net/lazy v0.1.0 => ./lazy |
| 73 | + example.net/requireincompatible v0.1.0 => ./requireincompatible |
| 74 | +) |
| 75 | + |
| 76 | +require ( |
| 77 | + example.com/retract/incompatible v1.0.0 // indirect |
| 78 | + example.net/lazy v0.1.0 |
| 79 | +) |
| 80 | +-- lazy/go.mod -- |
| 81 | +// Module lazy requires example.com/retract/incompatible v1.0.0. |
| 82 | +// |
| 83 | +// When viewed from the outside it also has a transitive dependency |
| 84 | +// on v2.0.0+incompatible, but in lazy mode that transitive dependency |
| 85 | +// is pruned out. |
| 86 | +module example.net/lazy |
| 87 | + |
| 88 | +go 1.17 |
| 89 | + |
| 90 | +exclude example.com/retract/incompatible v2.0.0+incompatible |
| 91 | + |
| 92 | +require ( |
| 93 | + example.com/retract/incompatible v1.0.0 |
| 94 | + example.net/requireincompatible v0.1.0 |
| 95 | +) |
| 96 | +-- requireincompatible/go.mod -- |
| 97 | +module example.net/requireincompatible |
| 98 | + |
| 99 | +go 1.15 |
| 100 | + |
| 101 | +require example.com/retract/incompatible v2.0.0+incompatible |
0 commit comments