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 '^go: 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  # Make sure that -diff behaves the same as tidy.
    31  [exec:patch] cp go.mod.orig go.mod
    32  [exec:patch] ! exists go.sum
    33  [exec:patch] ! go mod tidy -diff
    34  [exec:patch] ! stdout .
    35  [exec:patch] stderr '^go: 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'
    36  [exec:patch] 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'
    37  
    38  
    39  # If we run 'go mod tidy -e', we should still save enough checksums to run
    40  # 'go list -m all' reproducibly with go 1.16, even though we can't list
    41  # the specific package.
    42  
    43  go mod tidy -e
    44  ! stderr '\n\tgo mod tidy'
    45  cmp go.mod go.mod.orig
    46  
    47  # Make sure that -diff behaves the same as tidy.
    48  [exec:patch] mv go.mod go.mod.tidyResult
    49  [exec:patch] mv go.sum go.sum.tidyResult
    50  [exec:patch] cp go.mod.orig go.mod
    51  [exec:patch] ! go mod tidy -e -diff
    52  [exec:patch] ! stderr '\n\tgo mod tidy'
    53  [exec:patch] cp stdout diff.patch
    54  [exec:patch] exec patch -p1 -i diff.patch
    55  [exec:patch] go mod tidy -e -diff
    56  [exec:patch] ! stdout .
    57  [exec:patch] cmp go.mod go.mod.tidyResult
    58  [exec:patch] cmp go.sum go.sum.tidyResult
    59  
    60  go list -m all
    61  cmp stdout all-m.txt
    62  
    63  go list -f $MODFMT example.net/ambiguous/nested/pkg
    64  stdout '^example.net/ambiguous/nested v0\.1\.0$'
    65  ! stderr .
    66  
    67  go mod edit -go=1.16
    68  go list -m all
    69  cmp stdout all-m.txt
    70  
    71  ! go list -f $MODFMT example.net/ambiguous/nested/pkg
    72  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'
    73  
    74  
    75  # On the other hand, if we use -compat=1.17, 1.16 can't even load
    76  # the build list (due to missing checksums).
    77  
    78  cp go.mod.orig go.mod
    79  go mod tidy -compat=1.17
    80  ! stderr .
    81  go list -m all
    82  cmp stdout all-m.txt
    83  
    84  # Make sure that -diff behaves the same as tidy.
    85  [exec:patch] mv go.mod go.mod.tidyResult
    86  [exec:patch] mv go.sum go.sum.tidyResult
    87  [exec:patch] cp go.mod.orig go.mod
    88  [exec:patch] ! go mod tidy -compat=1.17 -diff
    89  [exec:patch] ! stderr .
    90  [exec:patch] cp stdout diff.patch
    91  [exec:patch] exec patch -p1 -i diff.patch
    92  [exec:patch] go mod tidy -compat=1.17 -diff
    93  [exec:patch] ! stdout .
    94  [exec:patch] cmp go.mod go.mod.tidyResult
    95  [exec:patch] cmp go.sum go.sum.tidyResult
    96  
    97  go mod edit -go=1.16
    98  ! go list -m all
    99  stderr '^go: example\.net/indirect@v0\.1\.0 requires\n\texample\.net/ambiguous@v0\.1\.0: missing go\.sum entry for go\.mod file; to add it:\n\tgo mod download example\.net/ambiguous\n'
   100  
   101  
   102  -- go.mod --
   103  module example.com/m
   104  
   105  go 1.17
   106  
   107  replace example.net/indirect v0.1.0 => ./indirect
   108  
   109  require example.net/indirect v0.1.0
   110  
   111  require example.net/ambiguous/nested v0.1.0 // indirect
   112  -- all-m.txt --
   113  example.com/m
   114  example.net/ambiguous v0.1.0
   115  example.net/ambiguous/nested v0.1.0
   116  example.net/indirect v0.1.0 => ./indirect
   117  -- m.go --
   118  package m
   119  
   120  import _ "example.net/indirect"
   121  
   122  -- indirect/go.mod --
   123  module example.net/indirect
   124  
   125  go 1.17
   126  
   127  require example.net/ambiguous v0.1.0
   128  -- indirect/indirect.go --
   129  package indirect
   130  
   131  import _ "example.net/ambiguous/nested/pkg"
   132  

View as plain text