...

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

Documentation: cmd/go/testdata/script

     1# https://golang.org/issue/45979: after 'go get' on a package,
     2# that package should be importable without error.
     3
     4
     5# We start out with an unresolved dependency.
     6# 'go list' suggests that we run 'go get' on that dependency.
     7
     8! go list -deps .
     9stderr '^m.go:3:8: no required module provides package rsc\.io/quote; to add it:\n\tgo get rsc.io/quote$'
    10
    11
    12# When we run the suggested 'go get' command, the new dependency can be used
    13# immediately.
    14#
    15# 'go get' marks the new dependency as 'indirect', because it doesn't scan
    16# enough source code to know whether it is direct, and it is easier and less
    17# invasive to remove an incorrect indirect mark (e.g. using 'go get') than to
    18# add one that is missing ('go mod tidy' or 'go mod vendor').
    19
    20go get rsc.io/quote
    21grep 'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod
    22! grep 'rsc.io/quote v\d+\.\d+\.\d+$' go.mod
    23
    24go list -deps .
    25! stderr .
    26[!short] go build .
    27[!short] ! stderr .
    28
    29
    30# 'go get .' (or 'go mod tidy') removes the indirect mark.
    31
    32go get .
    33grep 'rsc.io/quote v\d+\.\d+\.\d+$' go.mod
    34! grep 'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod
    35
    36
    37-- go.mod --
    38module example.com/m
    39
    40go 1.17
    41-- m.go --
    42package m
    43
    44import _ "rsc.io/quote"

View as plain text