...

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

Documentation: cmd/go/testdata/script

     1cp go.mod go.mod.orig
     2
     3
     4# 'go get' on a package already provided by the build list should update
     5# the module already in the build list, not fail with an ambiguous import error.
     6
     7go get example.net/split/nested@patch
     8go list -m all
     9stdout '^example.net/split v0.2.1 '
    10! stdout '^example.net/split/nested'
    11
    12# We should get the same behavior if we use a pattern that matches only that package.
    13
    14cp go.mod.orig go.mod
    15
    16go get example.net/split/nested/...@patch
    17go list -m all
    18stdout '^example.net/split v0.2.1 '
    19! stdout '^example.net/split/nested'
    20
    21
    22# If we request a version for which the package only exists in one particular module,
    23# we should add that one particular module but not resolve import ambiguities.
    24#
    25# In particular, if the module that previously provided the package has a
    26# matching version, but does not itself match the pattern and contains no
    27# matching packages, we should not change its version. (We should *not* downgrade
    28# module example.net/split to v0.1.0, despite the fact that
    29# example.net/split v0.2.0 currently provides the package with the requested path.)
    30#
    31# TODO(#27899): Maybe we should resolve the ambiguities by upgrading.
    32
    33cp go.mod.orig go.mod
    34
    35! go get example.net/split/nested@v0.1.0
    36stderr '^go: example.net/split/nested: ambiguous import: found package example.net/split/nested in multiple modules:\n\texample.net/split v0.2.0 \(.*split.2[/\\]nested\)\n\texample.net/split/nested v0.1.0 \(.*nested.1\)$'
    37
    38# A wildcard that matches packages in some module at its selected version
    39# but not at the requested version should fail.
    40#
    41# We can't set the module to the selected version, because that version doesn't
    42# even match the query: if we ran the same query twice, we wouldn't consider the
    43# module to match the wildcard during the second call, so why should we consider
    44# it to match during the first one?  ('go get' should be idempotent, and if we
    45# did that then it would not be.)
    46#
    47# But we also can't leave it where it is: the user requested that we set everything
    48# matching the pattern to the given version, and right now we have packages
    49# that match the pattern but *not* the version.
    50#
    51# That only leaves two options: we can set the module to an arbitrary version
    52# (perhaps 'latest' or 'none'), or we can report an error and the let the user
    53# disambiguate. We would rather not choose arbitrarily, so we do the latter.
    54#
    55# TODO(#27899): Should we instead upgrade or downgrade to an arbitrary version?
    56
    57! go get example.net/split/nested/...@v0.1.0
    58stderr '^go: example.net/split/nested/\.\.\.@v0.1.0 matches packages in example.net/split@v0.2.0 but not example.net/split@v0.1.0: specify a different version for module example.net/split$'
    59
    60cmp go.mod go.mod.orig
    61
    62
    63# If another argument resolves the ambiguity, we should be ok again.
    64
    65go get example.net/split@none example.net/split/nested@v0.1.0
    66go list -m all
    67! stdout '^example.net/split '
    68stdout '^example.net/split/nested v0.1.0 '
    69
    70cp go.mod.orig go.mod
    71
    72go get example.net/split@v0.3.0 example.net/split/nested@v0.1.0
    73go list -m all
    74stdout '^example.net/split v0.3.0 '
    75stdout '^example.net/split/nested v0.1.0 '
    76
    77
    78# If a pattern applies to modules and to packages, we should set all matching
    79# modules to the version indicated by the pattern, and also resolve packages
    80# to match the pattern if possible.
    81
    82cp go.mod.orig go.mod
    83go get example.net/split/nested@v0.0.0
    84
    85go get example.net/...@v0.1.0
    86go list -m all
    87stdout '^example.net/split v0.1.0 '
    88stdout '^example.net/split/nested v0.1.0 '
    89
    90go get example.net/...
    91go list -m all
    92stdout '^example.net/split v0.3.0 '
    93stdout '^example.net/split/nested v0.2.0 '
    94
    95
    96# @none applies to all matching module paths,
    97# regardless of whether they contain any packages.
    98
    99go get example.net/...@none
   100go list -m all
   101! stdout '^example.net'
   102
   103# Starting from no dependencies, a wildcard can resolve to an empty module with
   104# the same prefix even if it contains no packages.
   105
   106go get example.net/...@none
   107go get example.net/split/...@v0.1.0
   108go list -m all
   109stdout '^example.net/split v0.1.0 '
   110
   111
   112-- go.mod --
   113module m
   114
   115go 1.16
   116
   117require example.net/split v0.2.0
   118
   119replace (
   120	example.net/split v0.1.0 => ./split.1
   121	example.net/split v0.2.0 => ./split.2
   122	example.net/split v0.2.1 => ./split.2
   123	example.net/split v0.3.0 => ./split.3
   124	example.net/split/nested v0.0.0 => ./nested.0
   125	example.net/split/nested v0.1.0 => ./nested.1
   126	example.net/split/nested v0.2.0 => ./nested.2
   127)
   128-- split.1/go.mod --
   129module example.net/split
   130
   131go 1.16
   132-- split.2/go.mod --
   133module example.net/split
   134
   135go 1.16
   136-- split.2/nested/nested.go --
   137package nested
   138-- split.3/go.mod --
   139module example.net/split
   140
   141go 1.16
   142-- nested.0/go.mod --
   143module example.net/split/nested
   144
   145go 1.16
   146-- nested.1/go.mod --
   147module example.net/split/nested
   148
   149go 1.16
   150-- nested.1/nested.go --
   151package nested
   152-- nested.2/go.mod --
   153module example.net/split/nested
   154
   155go 1.16
   156-- nested.2/nested.go --
   157package nested

View as plain text