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 env GOWORK=off
54 go doc cryptobyte
55 stdout '// import "golang.org/x/crypto/cryptobyte"'
56
57 cd $GOROOT/src/cmd/go
58 go doc modfile
59 stdout '// 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.
64 cd $GOPATH
65 go doc vendor/golang.org/x/crypto/cryptobyte
66 stdout '// import "vendor/golang.org/x/crypto/cryptobyte"'
67
68 go doc cmd/vendor/golang.org/x/mod/modfile
69 stdout '// import "cmd/vendor/golang.org/x/mod/modfile"'
70
71 -- go.mod --
72 module x
73 require rsc.io/quote v1.5.2
74
75 -- y/y.go --
76 // Package y is the next to last package of the alphabet.
77 package y
78
79 -- x.go --
80 package x
81
82 -- $WORK/gopath2/src/x/y/y.go --
83 // Package y is located in a GOPATH workspace.
84 package y
85 -- $WORK/gopath2/src/rsc.io/quote/quote.go --
86 // Package quote is located in a GOPATH workspace.
87 package quote
88
89 // Hello is located in a GOPATH workspace.
90 func Hello() string { return "" }
91
View as plain text