github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/mod_doc.txt (about)

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