...

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

Documentation: cmd/go/testdata/script

     1# This test examines the behavior of 'go get …@patch'
     2# See also mod_upgrade_patch.txt (focused on "-u=patch" specifically)
     3# and mod_get_patchmod.txt (focused on module/package ambiguities).
     4
     5cp go.mod go.mod.orig
     6
     7# example.net/b@patch refers to the patch for the version of b that was selected
     8# at the start of 'go get', not the version after applying other changes.
     9
    10! go get example.net/a@v0.2.0 example.net/b@patch
    11stderr '^go: example.net/a@v0.2.0 requires example.net/b@v0.2.0, not example.net/b@patch \(v0.1.1\)$'
    12cmp go.mod go.mod.orig
    13
    14
    15# -u=patch changes the default version for other arguments to '@patch',
    16# but they continue to be resolved against the originally-selected version,
    17# not the updated one.
    18#
    19# TODO(#42360): Reconsider the change in defaults.
    20
    21! go get -u=patch example.net/a@v0.2.0 example.net/b
    22stderr '^go: example.net/a@v0.2.0 requires example.net/b@v0.2.0, not example.net/b@patch \(v0.1.1\)$'
    23cmp go.mod go.mod.orig
    24
    25
    26# -u=patch refers to the patches for the selected versions of dependencies *after*
    27# applying other version changes, not the versions that were selected at the start.
    28# However, it should not patch versions determined by explicit arguments.
    29
    30go get -u=patch example.net/a@v0.2.0
    31go list -m all
    32stdout '^example.net/a v0.2.0 '
    33stdout '^example.net/b v0.2.1 '
    34
    35
    36# "-u=patch all" should be equivalent to "all@patch", and should fail if the
    37# patched versions result in a higher-than-patch upgrade.
    38
    39cp go.mod.orig go.mod
    40! go get -u=patch all
    41stderr '^go: example.net/a@v0.1.1 \(matching all@patch\) requires example.net/b@v0.2.0, not example.net/b@v0.1.1 \(matching all@patch\)$'
    42cmp go.mod go.mod.orig
    43
    44
    45# On the other hand, "-u=patch ./..." should patch-upgrade dependencies until
    46# they reach a fixed point, even if that results in higher-than-patch upgrades.
    47
    48go get -u=patch ./...
    49go list -m all
    50stdout '^example.net/a v0.1.1 '
    51stdout '^example.net/b v0.2.1 '
    52
    53
    54-- go.mod --
    55module example
    56
    57go 1.16
    58
    59require (
    60	example.net/a v0.1.0
    61	example.net/b v0.1.0  // indirect
    62)
    63
    64replace (
    65	example.net/a v0.1.0 => ./a10
    66	example.net/a v0.1.1 => ./a11
    67	example.net/a v0.2.0 => ./a20
    68	example.net/a v0.2.1 => ./a21
    69	example.net/b v0.1.0 => ./b
    70	example.net/b v0.1.1 => ./b
    71	example.net/b v0.2.0 => ./b
    72	example.net/b v0.2.1 => ./b
    73	example.net/b v0.3.0 => ./b
    74	example.net/b v0.3.1 => ./b
    75)
    76-- example.go --
    77package example
    78
    79import _ "example.net/a"
    80
    81-- a10/go.mod --
    82module example.net/a
    83
    84go 1.16
    85
    86require example.net/b v0.1.0
    87-- a10/a.go --
    88package a
    89
    90import _ "example.net/b"
    91
    92-- a11/go.mod --
    93module example.net/a
    94
    95go 1.16
    96
    97require example.net/b v0.2.0  // upgraded
    98-- a11/a.go --
    99package a
   100
   101import _ "example.net/b"
   102
   103-- a20/go.mod --
   104module example.net/a
   105
   106go 1.16
   107
   108require example.net/b v0.2.0
   109-- a20/a.go --
   110package a
   111
   112import _ "example.net/b"
   113
   114-- a21/go.mod --
   115module example.net/a
   116
   117go 1.16
   118
   119require example.net/b v0.2.0  // not upgraded
   120-- a21/a.go --
   121package a
   122
   123import _ "example.net/b"
   124
   125-- b/go.mod --
   126module example.net/b
   127
   128go 1.16
   129-- b/b.go --
   130package b

View as plain text