...

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

Documentation: cmd/go/testdata/script

     1cp go.mod.orig go.mod
     2
     3# If we list a package in an implicit dependency imported from the main module,
     4# we should get an error because the dependency should have an explicit
     5# requirement.
     6go list -m indirect-with-pkg
     7stdout '^indirect-with-pkg v1.0.0 => ./indirect-with-pkg$'
     8! go list ./use-indirect
     9stderr '^package m/use-indirect imports indirect-with-pkg from implicitly required module; to add missing requirements, run:\n\tgo get indirect-with-pkg@v1.0.0$'
    10
    11# We can promote the implicit requirement by getting the importing package.
    12# NOTE: the hint recommends getting the imported package (tested below) since
    13# it's more obvious and doesn't require -d. However, that adds an '// indirect'
    14# comment on the requirement.
    15go get m/use-indirect
    16cmp go.mod go.mod.use
    17cp go.mod.orig go.mod
    18
    19# We can also promote implicit requirements using 'go get' on them, or their
    20# packages. This gives us "// indirect" requirements, since 'go get' doesn't
    21# know they're needed by the main module. See #43131 for the rationale.
    22# The hint above recommends this because it's more obvious usage and doesn't
    23# require the -d flag.
    24go get indirect-with-pkg indirect-without-pkg
    25cmp go.mod go.mod.indirect
    26
    27-- go.mod.orig --
    28module m
    29
    30go 1.16
    31
    32require direct v1.0.0
    33
    34replace (
    35	direct v1.0.0 => ./direct
    36	indirect-with-pkg v1.0.0 => ./indirect-with-pkg
    37	indirect-without-pkg v1.0.0 => ./indirect-without-pkg
    38)
    39-- go.mod.use --
    40module m
    41
    42go 1.16
    43
    44require (
    45	direct v1.0.0
    46	indirect-with-pkg v1.0.0
    47)
    48
    49replace (
    50	direct v1.0.0 => ./direct
    51	indirect-with-pkg v1.0.0 => ./indirect-with-pkg
    52	indirect-without-pkg v1.0.0 => ./indirect-without-pkg
    53)
    54-- go.mod.indirect --
    55module m
    56
    57go 1.16
    58
    59require (
    60	direct v1.0.0
    61	indirect-with-pkg v1.0.0 // indirect
    62	indirect-without-pkg v1.0.0 // indirect
    63)
    64
    65replace (
    66	direct v1.0.0 => ./direct
    67	indirect-with-pkg v1.0.0 => ./indirect-with-pkg
    68	indirect-without-pkg v1.0.0 => ./indirect-without-pkg
    69)
    70-- use-indirect/use-indirect.go --
    71package use
    72
    73import _ "indirect-with-pkg"
    74-- direct/go.mod --
    75module direct
    76
    77go 1.16
    78
    79require (
    80	indirect-with-pkg v1.0.0
    81	indirect-without-pkg v1.0.0
    82)
    83-- indirect-with-pkg/go.mod --
    84module indirect-with-pkg
    85
    86go 1.16
    87-- indirect-with-pkg/p.go --
    88package p
    89-- indirect-without-pkg/go.mod --
    90module indirect-without-pkg
    91
    92go 1.16

View as plain text