...

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

Documentation: cmd/go/testdata/script

     1# Regression test for https://go.dev/issue/56494:
     2# 'go get' in module mode was failing to prune out dependencies
     3# through modules whose versions are too low to be selected.
     4
     5# Initially, modules "a", "b", and "c" are unrelated.
     6#
     7# The package import graph at v1 of everything looks like:
     8#
     9# m --- a
    10# |
    11# + --- b
    12# |
    13# + --- c
    14#
    15# At v2, package "a" adds imports of "b" and "c"
    16# (and a requirement on "c" v2):
    17#
    18# a --- b
    19# |
    20# + --- c
    21#
    22# And "b" adds an import of "a/sub" (in module "a"):
    23#
    24# b --- a/sub
    25#
    26# At v3, "a" no longer imports (nor requires) "c":
    27#
    28# a --- b
    29
    30# So upgrading to a3 adds a dependency on b2,
    31# b2 adds a dependency on a2 (for "a/sub"),
    32# and a2 (but not a3) would add a dependency on c2.
    33# Since a2 is lower than a3 it cannot possibly be selected when
    34# upgrading to a3: normally a2 is pruned out of a3's module graph,
    35# so 'go get' should prune it out too, and c should remain at c1
    36# without error.
    37
    38go get a@v0.3.0
    39
    40go list -m c
    41stdout '^c v0.1.0 '
    42
    43-- go.mod --
    44module m
    45
    46go 1.19
    47
    48require (
    49	a v0.1.0
    50	b v0.1.0
    51	c v0.1.0
    52)
    53
    54replace (
    55	a v0.1.0 => ./a1
    56	a v0.2.0 => ./a2
    57	a v0.3.0 => ./a3
    58	b v0.1.0 => ./b1
    59	b v0.2.0 => ./b2
    60	c v0.1.0 => ./c1
    61	c v0.2.0 => ./c2
    62)
    63-- m.go --
    64package m
    65
    66import (
    67	_ "a"
    68	_ "b"
    69	_ "c"
    70)
    71-- a1/go.mod --
    72module a
    73
    74go 1.19
    75-- a1/a.go --
    76package a
    77-- a2/go.mod --
    78module a
    79
    80go 1.19
    81
    82require (
    83	b v0.1.0
    84	c v0.2.0
    85)
    86-- a2/a.go --
    87package a
    88
    89import (
    90	_ "b"
    91	_ "c"
    92)
    93-- a2/sub/sub.go --
    94package sub
    95-- a3/go.mod --
    96module a
    97
    98go 1.19
    99
   100require b v0.2.0
   101-- a3/a.go --
   102package a
   103
   104import _ "b"
   105-- a3/sub/sub.go --
   106package sub
   107-- b1/go.mod --
   108module b
   109
   110go 1.19
   111-- b1/b.go --
   112package b
   113-- b2/go.mod --
   114module b
   115
   116go 1.19
   117
   118require a v0.2.0
   119-- b2/b.go --
   120package b
   121
   122import "a/sub"
   123-- c1/go.mod --
   124module c
   125
   126go 1.19
   127-- c1/c.go --
   128package c
   129-- c2/go.mod --
   130module c
   131
   132go 1.19
   133-- c2/c.go --
   134package c

View as plain text