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 x/y
    12  stdout 'Package y is.*alphabet'
    13  ! go doc quote.Hello
    14  stderr 'doc: symbol quote is not a type' # because quote is not in local cache
    15  go list rsc.io/quote # now it is
    16  go doc quote.Hello
    17  stdout 'Hello returns a greeting'
    18  go doc quote
    19  stdout 'Package quote collects pithy sayings.'
    20  
    21  # Double-check when module x is outside GOPATH/src.
    22  env GOPATH=$WORK/emptygopath
    23  go doc x/y
    24  stdout 'Package y is.*alphabet'
    25  go doc y
    26  stdout '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.
    32  env GOPATH=$WORK/gopath2
    33  go doc x/y
    34  ! stdout 'Package y is.*GOPATH'
    35  stdout 'Package y is.*alphabet'
    36  go doc rsc.io/quote
    37  ! stdout 'Package quote is located in a GOPATH workspace.'
    38  stdout 'Package quote collects pithy sayings.'
    39  
    40  # Check that a sensible error message is printed when a package is not found.
    41  env GOPROXY=off
    42  ! go doc example.com/hello
    43  stderr '^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  
    51  cd $GOROOT/src
    52  env GOFLAGS=
    53  go doc cryptobyte
    54  stdout '// import "golang.org/x/crypto/cryptobyte"'
    55  
    56  cd $GOROOT/src/cmd/go
    57  go doc modfile
    58  stdout '// import "golang.org/x/mod/modfile"'
    59  
    60  # When outside of the 'std' module, its vendored packages
    61  # remain accessible using the 'vendor/' prefix, but report
    62  # the correct "// import" comment as used within std.
    63  cd $GOPATH
    64  go doc vendor/golang.org/x/crypto/cryptobyte
    65  stdout '// import "vendor/golang.org/x/crypto/cryptobyte"'
    66  
    67  go doc cmd/vendor/golang.org/x/mod/modfile
    68  stdout '// import "cmd/vendor/golang.org/x/mod/modfile"'
    69  
    70  -- go.mod --
    71  module x
    72  require rsc.io/quote v1.5.2
    73  
    74  -- y/y.go --
    75  // Package y is the next to last package of the alphabet.
    76  package y
    77  
    78  -- x.go --
    79  package x
    80  
    81  -- $WORK/gopath2/src/x/y/y.go --
    82  // Package y is located in a GOPATH workspace.
    83  package y
    84  -- $WORK/gopath2/src/rsc.io/quote/quote.go --
    85  // Package quote is located in a GOPATH workspace.
    86  package quote
    87  
    88  // Hello is located in a GOPATH workspace.
    89  func Hello() string { return "" }
    90  

View as plain text