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

     1  # https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by
     2  # default preserve enough checksums for the module to be used by Go 1.16.
     3  #
     4  # We don't have a copy of Go 1.16 handy, but we can simulate it by editing the
     5  # 'go' version in the go.mod file to 1.16, without actually updating the
     6  # requirements to match.
     7  
     8  [short] skip
     9  
    10  env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}'
    11  
    12  # For this module, the dependency providing package
    13  # example.net/ambiguous/nested/pkg is unambiguous in Go 1.17 (because only one
    14  # root of the module graph contains the package), whereas it is ambiguous in
    15  # Go 1.16 (because two different modules contain plausible packages and Go 1.16
    16  # does not privilege roots above other dependencies).
    17  #
    18  # However, the overall build list is identical for both versions.
    19  
    20  cp go.mod go.mod.orig
    21  
    22  ! go mod tidy
    23  
    24  stderr '^example\.com/m imports\n\texample\.net/indirect imports\n\texample\.net/ambiguous/nested/pkg loaded from example\.net/ambiguous/nested@v0\.1\.0,\n\tbut go 1.16 would fail to locate it:\n\tambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0.1.0 \(.*\)\n\texample\.net/ambiguous/nested v0.1.0 \(.*\)\n\n'
    25  
    26  stderr '\n\nTo proceed despite packages unresolved in go 1\.16:\n\tgo mod tidy -e\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
    27  
    28  cmp go.mod go.mod.orig
    29  
    30  
    31  # If we run 'go mod tidy -e', we should still save enough checksums to run
    32  # 'go list -m all' reproducibly with go 1.16, even though we can't list
    33  # the specific package.
    34  
    35  go mod tidy -e
    36  ! stderr '\n\tgo mod tidy'
    37  cmp go.mod go.mod.orig
    38  
    39  go list -m all
    40  cmp stdout all-m.txt
    41  
    42  go list -f $MODFMT example.net/ambiguous/nested/pkg
    43  stdout '^example.net/ambiguous/nested v0\.1\.0$'
    44  ! stderr .
    45  
    46  go mod edit -go=1.16
    47  go list -m all
    48  cmp stdout all-m.txt
    49  
    50  ! go list -f $MODFMT example.net/ambiguous/nested/pkg
    51  stderr '^ambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0\.1\.0 \(.*\)\n\texample\.net/ambiguous/nested v0\.1\.0 \(.*\)\n'
    52  
    53  
    54  # On the other hand, if we use -compat=1.17, 1.16 can't even load
    55  # the build list (due to missing checksums).
    56  
    57  cp go.mod.orig go.mod
    58  go mod tidy -compat=1.17
    59  ! stderr .
    60  go list -m all
    61  cmp stdout all-m.txt
    62  
    63  go mod edit -go=1.16
    64  ! go list -m all
    65  stderr '^go: example\.net/indirect@v0\.1\.0 requires\n\texample\.net/ambiguous@v0\.1\.0: missing go\.sum entry; to add it:\n\tgo mod download example\.net/ambiguous\n'
    66  
    67  
    68  -- go.mod --
    69  module example.com/m
    70  
    71  go 1.17
    72  
    73  replace example.net/indirect v0.1.0 => ./indirect
    74  
    75  require example.net/indirect v0.1.0
    76  
    77  require example.net/ambiguous/nested v0.1.0 // indirect
    78  -- all-m.txt --
    79  example.com/m
    80  example.net/ambiguous v0.1.0
    81  example.net/ambiguous/nested v0.1.0
    82  example.net/indirect v0.1.0 => ./indirect
    83  -- m.go --
    84  package m
    85  
    86  import _ "example.net/indirect"
    87  
    88  -- indirect/go.mod --
    89  module example.net/indirect
    90  
    91  go 1.17
    92  
    93  require example.net/ambiguous v0.1.0
    94  -- indirect/indirect.go --
    95  package indirect
    96  
    97  import _ "example.net/ambiguous/nested/pkg"
    98  

View as plain text