...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2[short] skip
     3
     4# Initially, we are at v1.0.0 for all dependencies.
     5go get
     6cp go.mod go.mod.orig
     7go list -m all
     8stdout '^patch.example.com/direct v1.0.0'
     9stdout '^patch.example.com/indirect v1.0.0'
    10! stdout '^patch.example.com/depofdirectpatch'
    11
    12# @patch should be rejected for modules not already in the build list.
    13! go get patch.example.com/depofdirectpatch@patch
    14stderr '^go: can''t query version "patch" of module patch.example.com/depofdirectpatch: no existing version is required$'
    15cmp go.mod.orig go.mod
    16
    17# get -u=patch, with no arguments, should patch-update all dependencies
    18# of the package in the current directory, pulling in transitive dependencies
    19# and also patching those.
    20cp go.mod.orig go.mod
    21go get -u=patch
    22go list -m all
    23stdout '^patch.example.com/direct v1.0.1'
    24stdout '^patch.example.com/indirect v1.0.1'
    25stdout '^patch.example.com/depofdirectpatch v1.0.0'
    26
    27# 'get all@patch' should patch the modules that provide packages in 'all'.
    28cp go.mod.orig go.mod
    29go get all@patch
    30go list -m all
    31stdout '^patch.example.com/direct v1.0.1'
    32stdout '^patch.example.com/indirect v1.0.1'
    33stdout '^patch.example.com/depofdirectpatch v1.0.0'
    34
    35# ...but 'all@patch' should fail if any of the affected modules do not already
    36# have a selected version.
    37cp go.mod.orig go.mod
    38go mod edit -droprequire=patch.example.com/direct
    39cp go.mod go.mod.dropped
    40! go get all@patch
    41stderr '^go: all@patch: can''t query version "patch" of module patch.example.com/direct: no existing version is required$'
    42cmp go.mod.dropped go.mod
    43
    44# Requesting the direct dependency with -u=patch but without an explicit version
    45# should patch-update it and its dependencies.
    46cp go.mod.orig go.mod
    47go get -u=patch patch.example.com/direct
    48go list -m all
    49stdout '^patch.example.com/direct v1.0.1'
    50stdout '^patch.example.com/indirect v1.0.1'
    51stdout '^patch.example.com/depofdirectpatch v1.0.0'
    52
    53# Requesting only the indirect dependency should not update the direct one.
    54cp go.mod.orig go.mod
    55go get -u=patch patch.example.com/indirect
    56go list -m all
    57stdout '^patch.example.com/direct v1.0.0'
    58stdout '^patch.example.com/indirect v1.0.1'
    59! stdout '^patch.example.com/depofdirectpatch'
    60
    61# @patch should apply only to the specific module,
    62# but the result must reflect its upgraded requirements.
    63cp go.mod.orig go.mod
    64go get patch.example.com/direct@patch
    65go list -m all
    66stdout '^patch.example.com/direct v1.0.1'
    67stdout '^patch.example.com/indirect v1.0.0'
    68stdout '^patch.example.com/depofdirectpatch v1.0.0'
    69
    70# An explicit @patch should override a general -u.
    71cp go.mod.orig go.mod
    72go get -u patch.example.com/direct@patch
    73go list -m all
    74stdout '^patch.example.com/direct v1.0.1'
    75stdout '^patch.example.com/indirect v1.1.0'
    76stdout '^patch.example.com/depofdirectpatch v1.0.0'
    77
    78# An explicit @latest should override a general -u=patch.
    79cp go.mod.orig go.mod
    80go get -u=patch patch.example.com/direct@latest
    81go list -m all
    82stdout '^patch.example.com/direct v1.1.0'
    83stdout '^patch.example.com/indirect v1.0.1'
    84! stdout '^patch.example.com/depofdirectpatch'
    85
    86# Standard library packages cannot be upgraded explicitly.
    87cp go.mod.orig go.mod
    88! go get cmd/vet@patch
    89stderr 'go: can''t request explicit version "patch" of standard library package cmd/vet$'
    90
    91# However, standard-library packages without explicit versions are fine.
    92go get -u=patch cmd/go
    93
    94# We can upgrade to a new version of a module with no root package.
    95go get example.com/noroot@v1.0.0
    96go list -m all
    97stdout '^example.com/noroot v1.0.0$'
    98go get example.com/noroot@patch
    99go list -m all
   100stdout '^example.com/noroot v1.0.1$'
   101
   102
   103-- go.mod --
   104module x
   105
   106require patch.example.com/direct v1.0.0
   107
   108-- main.go --
   109package x
   110import _ "patch.example.com/direct"

View as plain text