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

     1  # go doc should find module documentation
     2  
     3  env GO111MODULE=on
     4  env GOFLAGS=-mod=mod
     5  [short] skip
     6  
     7  # Check when module x is inside GOPATH/src.
     8  go doc y
     9  stdout 'Package y is.*alphabet'
    10  stdout 'import "x/y"'
    11  go doc -short y.Yell
    12  stdout '^func Yell\(\) string$'
    13  ! stdout 'Yell returns the final letter'
    14  go doc -short y.Letter
    15  stdout '^const Letter = "z"$'
    16  go doc -short y.Alphabet
    17  stdout '^type Alphabet struct\{\}$'
    18  go doc x/y
    19  stdout 'Package y is.*alphabet'
    20  ! go doc quote.Hello
    21  stderr 'doc: symbol quote is not a type' # because quote is not in local cache
    22  go list rsc.io/quote # now it is
    23  go doc quote.Hello
    24  stdout 'Hello returns a greeting'
    25  go doc quote
    26  stdout 'Package quote collects pithy sayings.'
    27  
    28  # Double-check when module x is outside GOPATH/src.
    29  env GOPATH=$WORK/emptygopath
    30  go doc x/y
    31  stdout 'Package y is.*alphabet'
    32  go doc y
    33  stdout '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.
    39  env GOPATH=$WORK/gopath2
    40  go doc x/y
    41  ! stdout 'Package y is.*GOPATH'
    42  stdout 'Package y is.*alphabet'
    43  go doc rsc.io/quote
    44  ! stdout 'Package quote is located in a GOPATH workspace.'
    45  stdout '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
    49  stderr '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  
    57  cd $GOROOT/src
    58  env GOFLAGS=
    59  env GOWORK=off
    60  go doc cryptobyte
    61  stdout '// import "golang.org/x/crypto/cryptobyte"'
    62  
    63  cd $GOROOT/src/cmd/go
    64  go doc modfile
    65  stdout '// 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.
    70  cd $GOPATH
    71  go doc vendor/golang.org/x/crypto/cryptobyte
    72  stdout '// import "vendor/golang.org/x/crypto/cryptobyte"'
    73  
    74  go doc cmd/vendor/golang.org/x/mod/modfile
    75  stdout '// import "cmd/vendor/golang.org/x/mod/modfile"'
    76  
    77  # Not in a module and not in GOPATH
    78  cd $WORK
    79  go env GOMOD
    80  stdout '(/dev/null|NUL)'
    81  
    82  go doc encoding/json
    83  stdout '// import "encoding/json"'
    84  
    85  go doc json
    86  stdout '// import "encoding/json"'
    87  
    88  -- go.mod --
    89  module x
    90  require rsc.io/quote v1.5.2
    91  
    92  -- y/y.go --
    93  // Package y is the next to last package of the alphabet.
    94  package y
    95  
    96  // Yell returns the final letter of the alphabet.
    97  func Yell() string { return "z" }
    98  
    99  const Letter = "z"
   100  
   101  type Alphabet struct{}
   102  
   103  -- x.go --
   104  package x
   105  
   106  -- $WORK/gopath2/src/x/y/y.go --
   107  // Package y is located in a GOPATH workspace.
   108  package y
   109  -- $WORK/gopath2/src/rsc.io/quote/quote.go --
   110  // Package quote is located in a GOPATH workspace.
   111  package quote
   112  
   113  // Hello is located in a GOPATH workspace.
   114  func Hello() string { return "" }
   115  

View as plain text