...

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

Documentation: cmd/go/testdata/script

     1# go doc should find module documentation
     2
     3env GO111MODULE=on
     4env GOFLAGS=-mod=mod
     5[short] skip
     6
     7# Check when module x is inside GOPATH/src.
     8go doc y
     9stdout 'Package y is.*alphabet'
    10stdout 'import "x/y"'
    11go doc x/y
    12stdout 'Package y is.*alphabet'
    13! go doc quote.Hello
    14stderr 'doc: symbol quote is not a type' # because quote is not in local cache
    15go list rsc.io/quote # now it is
    16go doc quote.Hello
    17stdout 'Hello returns a greeting'
    18go doc quote
    19stdout 'Package quote collects pithy sayings.'
    20
    21# Double-check when module x is outside GOPATH/src.
    22env GOPATH=$WORK/emptygopath
    23go doc x/y
    24stdout 'Package y is.*alphabet'
    25go doc y
    26stdout 'Package y is.*alphabet'
    27
    28# Triple-check when module x is outside GOPATH/src,
    29# but other packages with same import paths are in GOPATH/src.
    30# Since go doc is running in module mode here, packages in active module
    31# should be preferred over packages in GOPATH. See golang.org/issue/28992.
    32env GOPATH=$WORK/gopath2
    33go doc x/y
    34! stdout 'Package y is.*GOPATH'
    35stdout 'Package y is.*alphabet'
    36go doc rsc.io/quote
    37! stdout 'Package quote is located in a GOPATH workspace.'
    38stdout 'Package quote collects pithy sayings.'
    39
    40# Check that a sensible error message is printed when a package is not found.
    41env GOPROXY=off
    42! go doc example.com/hello
    43stderr '^doc: cannot find module providing package example.com/hello: module lookup disabled by GOPROXY=off$'
    44
    45# When in a module with a vendor directory, doc should use the vendored copies
    46# of the packages. 'std' and 'cmd' are convenient examples of such modules.
    47#
    48# When in those modules, the "// import" comment should refer to the same import
    49# path used in source code, not to the absolute path relative to GOROOT.
    50
    51cd $GOROOT/src
    52env GOFLAGS=
    53env GOWORK=off
    54go doc cryptobyte
    55stdout '// import "golang.org/x/crypto/cryptobyte"'
    56
    57cd $GOROOT/src/cmd/go
    58go doc modfile
    59stdout '// import "golang.org/x/mod/modfile"'
    60
    61# When outside of the 'std' module, its vendored packages
    62# remain accessible using the 'vendor/' prefix, but report
    63# the correct "// import" comment as used within std.
    64cd $GOPATH
    65go doc vendor/golang.org/x/crypto/cryptobyte
    66stdout '// import "vendor/golang.org/x/crypto/cryptobyte"'
    67
    68go doc cmd/vendor/golang.org/x/mod/modfile
    69stdout '// import "cmd/vendor/golang.org/x/mod/modfile"'
    70
    71-- go.mod --
    72module x
    73require rsc.io/quote v1.5.2
    74
    75-- y/y.go --
    76// Package y is the next to last package of the alphabet.
    77package y
    78
    79-- x.go --
    80package x
    81
    82-- $WORK/gopath2/src/x/y/y.go --
    83// Package y is located in a GOPATH workspace.
    84package y
    85-- $WORK/gopath2/src/rsc.io/quote/quote.go --
    86// Package quote is located in a GOPATH workspace.
    87package quote
    88
    89// Hello is located in a GOPATH workspace.
    90func Hello() string { return "" }

View as plain text