...

Text file src/cmd/go/testdata/script/mod_graph_version.txt

Documentation: cmd/go/testdata/script

     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
    17cp go.mod go.mod.orig
    18
    19go mod graph
    20cp stdout graph-1.17.txt
    21stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$'
    22stdout '^example\.net/lazy@v0\.1\.0 example\.com/retract/incompatible@v1\.0\.0$'
    23! stdout 'example\.com/retract/incompatible@v2\.0\.0\+incompatible'
    24
    25go mod graph -go=1.17
    26cmp stdout graph-1.17.txt
    27
    28cmp 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
    34go mod graph -go=1.16
    35cp stdout graph-1.16.txt
    36stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$'
    37stdout '^example\.net/lazy@v0\.1\.0 example.com/retract/incompatible@v1\.0\.0$'
    38stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$'
    39
    40cmp 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
    49go mod edit -go=1.16
    50go mod graph
    51! stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$'
    52stdout '^example\.net/lazy@v0.1.0 example.com/retract/incompatible@v1\.0\.0$'
    53stdout '^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
    60stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\] \[-x\]\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.
    67module example.com/m
    68
    69go 1.17
    70
    71replace (
    72	example.net/lazy v0.1.0 => ./lazy
    73	example.net/requireincompatible v0.1.0 => ./requireincompatible
    74)
    75
    76require (
    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.
    86module example.net/lazy
    87
    88go 1.17
    89
    90exclude example.com/retract/incompatible v2.0.0+incompatible
    91
    92require (
    93	example.com/retract/incompatible v1.0.0
    94	example.net/requireincompatible v0.1.0
    95)
    96-- requireincompatible/go.mod --
    97module example.net/requireincompatible
    98
    99go 1.15
   100
   101require example.com/retract/incompatible v2.0.0+incompatible

View as plain text