...

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

Documentation: cmd/go/testdata/script

     1cp go.mod go.mod.orig
     2
     3
     4# If a dependency cannot be resolved, 'go mod tidy' fails with an error message
     5# explaining the problem and does not update the go.mod file.
     6# TODO(bcmills): Ideally, with less redundancy than these error messages!
     7
     8! go mod tidy
     9
    10stderr '^go: example.com/untidy imports\n\texample.net/directnotfound: cannot find module providing package example.net/directnotfound: module example.net/directnotfound: reading http://.*: 404 Not Found$'
    11
    12stderr '^go: example.com/untidy imports\n\texample.net/m imports\n\texample.net/indirectnotfound: cannot find module providing package example.net/indirectnotfound: module example.net/indirectnotfound: reading http://.*: 404 Not Found$'
    13
    14stderr '^go: example.com/untidy tested by\n\texample.com/untidy.test imports\n\texample.net/directtestnotfound: cannot find module providing package example.net/directtestnotfound: module example.net/directtestnotfound: reading http://.*: 404 Not Found$'
    15
    16stderr '^go: example.com/untidy imports\n\texample.net/m tested by\n\texample.net/m.test imports\n\texample.net/indirecttestnotfound: cannot find module providing package example.net/indirecttestnotfound: module example.net/indirecttestnotfound: reading http://.*: 404 Not Found$'
    17
    18cmp go.mod.orig go.mod
    19
    20
    21# If a dependency cannot be resolved, 'go mod vendor' fails with an error message
    22# explaining the problem, does not update the go.mod file, and does not create
    23# the vendor directory.
    24
    25! go mod vendor
    26
    27stderr '^go: example.com/untidy imports\n\texample.net/directnotfound: no required module provides package example.net/directnotfound; to add it:\n\tgo get example.net/directnotfound$'
    28
    29stderr '^go: example.com/untidy imports\n\texample.net/m: module example.net/m provides package example.net/m and is replaced but not required; to add it:\n\tgo get example.net/m@v0.1.0$'
    30
    31stderr '^go: example.com/untidy tested by\n\texample.com/untidy.test imports\n\texample.net/directtestnotfound: no required module provides package example.net/directtestnotfound; to add it:\n\tgo get example.net/directtestnotfound$'
    32
    33! stderr 'indirecttestnotfound'  # Vendor prunes test dependencies.
    34
    35cmp go.mod.orig go.mod
    36! exists vendor
    37
    38
    39# 'go mod tidy' still logs the errors, but succeeds and updates go.mod.
    40
    41go mod tidy -e
    42stderr -count=4 'cannot find module providing package'
    43cmp go.mod.final go.mod
    44
    45
    46# 'go mod vendor -e' still logs the errors, but creates a vendor directory
    47# and exits with status 0.
    48# 'go mod vendor -e' does not update go.mod and will not vendor packages that
    49# would require changing go.mod, for example, by adding a requirement.
    50cp go.mod.orig go.mod
    51go mod vendor -e
    52stderr -count=2 'no required module provides package'
    53stderr '^go: example.com/untidy imports\n\texample.net/m: module example.net/m provides package example.net/m and is replaced but not required; to add it:\n\tgo get example.net/m@v0.1.0$'
    54exists vendor/modules.txt
    55! exists vendor/example.net
    56
    57go mod edit -require example.net/m@v0.1.0
    58go mod vendor -e
    59stderr -count=3 'no required module provides package'
    60exists vendor/modules.txt
    61exists vendor/example.net/m/m.go
    62
    63-- go.mod --
    64module example.com/untidy
    65go 1.16
    66replace example.net/m v0.1.0 => ./m
    67-- go.mod.final --
    68module example.com/untidy
    69
    70go 1.16
    71
    72replace example.net/m v0.1.0 => ./m
    73
    74require example.net/m v0.1.0
    75-- untidy.go --
    76package untidy
    77
    78import (
    79	_ "example.net/m"
    80	_ "example.net/directnotfound"
    81)
    82-- untidy_test.go --
    83package untidy_test
    84
    85import _ "example.net/directtestnotfound"
    86-- m/go.mod --
    87module example.net/m
    88go 1.16
    89-- m/m.go --
    90package m
    91
    92import _ "example.net/indirectnotfound"
    93-- m/m_test.go --
    94package m_test
    95
    96import _ "example.net/indirecttestnotfound"

View as plain text