...

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 -short y.Yell
    12stdout '^func Yell\(\) string$'
    13! stdout 'Yell returns the final letter'
    14go doc -short y.Letter
    15stdout '^const Letter = "z"$'
    16go doc -short y.Alphabet
    17stdout '^type Alphabet struct\{\}$'
    18go doc x/y
    19stdout 'Package y is.*alphabet'
    20! go doc quote.Hello
    21stderr 'doc: symbol quote is not a type' # because quote is not in local cache
    22go list rsc.io/quote # now it is
    23go doc quote.Hello
    24stdout 'Hello returns a greeting'
    25go doc quote
    26stdout 'Package quote collects pithy sayings.'
    27
    28# Double-check when module x is outside GOPATH/src.
    29env GOPATH=$WORK/emptygopath
    30go doc x/y
    31stdout 'Package y is.*alphabet'
    32go doc y
    33stdout 'Package y is.*alphabet'
    34
    35# Triple-check when module x is outside GOPATH/src,
    36# but other packages with same import paths are in GOPATH/src.
    37# Since go doc is running in module mode here, packages in active module
    38# should be preferred over packages in GOPATH. See golang.org/issue/28992.
    39env GOPATH=$WORK/gopath2
    40go doc x/y
    41! stdout 'Package y is.*GOPATH'
    42stdout 'Package y is.*alphabet'
    43go doc rsc.io/quote
    44! stdout 'Package quote is located in a GOPATH workspace.'
    45stdout 'Package quote collects pithy sayings.'
    46
    47# Check that a sensible error message is printed when a package is not found.
    48! go doc example.com/hello
    49stderr 'doc: no required module provides package example.com/hello; to add it:\n\s+go get example.com/hello'
    50
    51# When in a module with a vendor directory, doc should use the vendored copies
    52# of the packages. 'std' and 'cmd' are convenient examples of such modules.
    53#
    54# When in those modules, the "// import" comment should refer to the same import
    55# path used in source code, not to the absolute path relative to GOROOT.
    56
    57cd $GOROOT/src
    58env GOFLAGS=
    59env GOWORK=off
    60go doc cryptobyte
    61stdout '// import "golang.org/x/crypto/cryptobyte"'
    62
    63cd $GOROOT/src/cmd/go
    64go doc modfile
    65stdout '// import "golang.org/x/mod/modfile"'
    66
    67# When outside of the 'std' module, its vendored packages
    68# remain accessible using the 'vendor/' prefix, but report
    69# the correct "// import" comment as used within std.
    70cd $GOPATH
    71go doc vendor/golang.org/x/crypto/cryptobyte
    72stdout '// import "vendor/golang.org/x/crypto/cryptobyte"'
    73
    74go doc cmd/vendor/golang.org/x/mod/modfile
    75stdout '// import "cmd/vendor/golang.org/x/mod/modfile"'
    76
    77# Not in a module and not in GOPATH
    78cd $WORK
    79go env GOMOD
    80stdout '(/dev/null|NUL)'
    81
    82go doc encoding/json
    83stdout '// import "encoding/json"'
    84
    85go doc json
    86stdout '// import "encoding/json"'
    87
    88-- go.mod --
    89module x
    90require rsc.io/quote v1.5.2
    91
    92-- y/y.go --
    93// Package y is the next to last package of the alphabet.
    94package y
    95
    96// Yell returns the final letter of the alphabet.
    97func Yell() string { return "z" }
    98
    99const Letter = "z"
   100
   101type Alphabet struct{}
   102
   103-- x.go --
   104package x
   105
   106-- $WORK/gopath2/src/x/y/y.go --
   107// Package y is located in a GOPATH workspace.
   108package y
   109-- $WORK/gopath2/src/rsc.io/quote/quote.go --
   110// Package quote is located in a GOPATH workspace.
   111package quote
   112
   113// Hello is located in a GOPATH workspace.
   114func Hello() string { return "" }

View as plain text