Skip to content

Commit 6e96c39

Browse files
committed
test: add basic tests for godoclint
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent c5a49bb commit 6e96c39

13 files changed

+593
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//golangcitest:args -Egodoclint
2+
3+
// bad godoc // want `package godoc should start with "Package testdata "`
4+
package testdata
5+
6+
// This is a special stdlib import because the package itself has issues that
7+
// godoclint can, but must not, detect.
8+
import "go/ast"
9+
10+
// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)`
11+
type FooType struct{}
12+
13+
// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)`
14+
type FooAlias = ast.Comment
15+
16+
// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)`
17+
const FooConst = 1
18+
19+
// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)`
20+
var FooVar = 1
21+
22+
// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)`
23+
func FooFunc() {}
24+
25+
// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)`
26+
func (FooType) FooFunc() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:expected_exitcode 0
3+
4+
// Package testdata has good godoc.
5+
package testdata
6+
7+
// This is a special stdlib import because the package itself has issues that
8+
// godoclint can, but must not, detect.
9+
import "go/ast"
10+
11+
// FooType is a type.
12+
type FooType struct{}
13+
14+
// FooAlias is an alias.
15+
type FooAlias = ast.Comment
16+
17+
// FooConst is a constant.
18+
const FooConst = 1
19+
20+
// FooVar is a variable.
21+
var FooVar = 1
22+
23+
// FooFunc is a function.
24+
func FooFunc() {}
25+
26+
// FooFunc is a method.
27+
func (FooType) FooFunc() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
//golangcitest:expected_exitcode 0
4+
5+
// Since this file is excluded in the config, godoclint should not report any
6+
// issues (i.e.exit code 0).
7+
8+
// bad godoc
9+
package testdata
10+
11+
// This is a special stdlib import because the package itself has issues that
12+
// godoclint can, but must not, detect.
13+
import "go/ast"
14+
15+
// bad godoc
16+
type FooAlias = ast.Comment
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
//golangcitest:expected_exitcode 0
4+
5+
// Since this file is excluded in the config, godoclint should not report any
6+
// issues (i.e.exit code 0).
7+
8+
// bad godoc
9+
package testdata
10+
11+
// This is a special stdlib import because the package itself has issues that
12+
// godoclint can, but must not, detect.
13+
import "go/ast"
14+
15+
// bad godoc
16+
type FooAlias = ast.Comment
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
4+
// Asserting rule "pkg-doc"
5+
6+
// bad godoc // want `package godoc should start with "PACKAGE testdata "`
7+
package testdata
8+
9+
// This is a special stdlib import because the package itself has issues that
10+
// godoclint can, but must not, detect.
11+
import "go/ast"
12+
13+
// Asserting rule "start-with-name"
14+
15+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
16+
type FooType struct{}
17+
18+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
19+
type FooAlias = ast.Comment
20+
21+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
22+
const FooConst = 1
23+
24+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
25+
var FooVar = 1
26+
27+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
28+
func FooFunc() {}
29+
30+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
31+
func (FooType) FooFunc() {}
32+
33+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
34+
type fooType struct{}
35+
36+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
37+
type fooAlias = ast.Comment
38+
39+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
40+
const fooConst = 1
41+
42+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
43+
var fooVar = 1
44+
45+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
46+
func fooFunc() {}
47+
48+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
49+
func (FooType) fooFunc() {}
50+
51+
// Asserting rule "require-doc"
52+
53+
// The //foo:bar directives mark the trailing comment as a directive so they're
54+
// not parsed as a normal trailing comment group.
55+
56+
type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)`
57+
58+
type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)`
59+
60+
const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)`
61+
62+
var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)`
63+
64+
func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)`
65+
66+
func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)`
67+
68+
type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)`
69+
70+
type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)`
71+
72+
const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)`
73+
74+
var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)`
75+
76+
func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)`
77+
78+
func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)`
79+
80+
// Asserting rule "no-unused-link"
81+
82+
// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)`
83+
//
84+
// [used]: https://example.com
85+
//
86+
// [unused]: https://example.com
87+
const constWithUnusedLink = 1
88+
89+
// Asserting rule "max-len"
90+
91+
// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)`
92+
const constWithTooLongGodoc = 1
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
4+
// Asserting rule "pkg-doc"
5+
6+
// bad godoc // want `package godoc should start with "PACKAGE testdata_test "`
7+
package testdata_test
8+
9+
// This is a special stdlib import because the package itself has issues that
10+
// godoclint can, but must not, detect.
11+
import "go/ast"
12+
13+
// Asserting rule "start-with-name"
14+
15+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
16+
type FooType struct{}
17+
18+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
19+
type FooAlias = ast.Comment
20+
21+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
22+
const FooConst = 1
23+
24+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
25+
var FooVar = 1
26+
27+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
28+
func FooFunc() {}
29+
30+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
31+
func (FooType) FooFunc() {}
32+
33+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
34+
type fooType struct{}
35+
36+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
37+
type fooAlias = ast.Comment
38+
39+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
40+
const fooConst = 1
41+
42+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
43+
var fooVar = 1
44+
45+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
46+
func fooFunc() {}
47+
48+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
49+
func (FooType) fooFunc() {}
50+
51+
// Asserting rule "require-doc"
52+
53+
// The //foo:bar directives mark the trailing comment as a directive so they're
54+
// not parsed as a normal trailing comment group.
55+
56+
type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)`
57+
58+
type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)`
59+
60+
const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)`
61+
62+
var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)`
63+
64+
func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)`
65+
66+
func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)`
67+
68+
type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)`
69+
70+
type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)`
71+
72+
const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)`
73+
74+
var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)`
75+
76+
func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)`
77+
78+
func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)`
79+
80+
// Asserting rule "no-unused-link"
81+
82+
// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)`
83+
//
84+
// [used]: https://example.com
85+
//
86+
// [unused]: https://example.com
87+
const constWithUnusedLink = 1
88+
89+
// Asserting rule "max-len"
90+
91+
// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)`
92+
const constWithTooLongGodoc = 1
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
4+
// Asserting rule "pkg-doc"
5+
6+
// bad godoc // want `package godoc should start with "PACKAGE testdata "`
7+
package testdata
8+
9+
// This is a special stdlib import because the package itself has issues that
10+
// godoclint can, but must not, detect.
11+
import "go/ast"
12+
13+
// Asserting rule "start-with-name"
14+
15+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
16+
type FooType struct{}
17+
18+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
19+
type FooAlias = ast.Comment
20+
21+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
22+
const FooConst = 1
23+
24+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
25+
var FooVar = 1
26+
27+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
28+
func FooFunc() {}
29+
30+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
31+
func (FooType) FooFunc() {}
32+
33+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
34+
type fooType struct{}
35+
36+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
37+
type fooAlias = ast.Comment
38+
39+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
40+
const fooConst = 1
41+
42+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
43+
var fooVar = 1
44+
45+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
46+
func fooFunc() {}
47+
48+
// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)`
49+
func (FooType) fooFunc() {}
50+
51+
// Asserting rule "require-doc"
52+
53+
// The //foo:bar directives mark the trailing comment as a directive so they're
54+
// not parsed as a normal trailing comment group.
55+
56+
type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)`
57+
58+
type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)`
59+
60+
const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)`
61+
62+
var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)`
63+
64+
func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)`
65+
66+
func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)`
67+
68+
type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)`
69+
70+
type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)`
71+
72+
const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)`
73+
74+
var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)`
75+
76+
func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)`
77+
78+
func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)`
79+
80+
// Asserting rule "no-unused-link"
81+
82+
// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)`
83+
//
84+
// [used]: https://example.com
85+
//
86+
// [unused]: https://example.com
87+
const constWithUnusedLink = 1
88+
89+
// Asserting rule "max-len"
90+
91+
// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)`
92+
const constWithTooLongGodoc = 1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
4+
package testdata_test // want `package should have a godoc`
5+
6+
// This is a special stdlib import because the package itself has issues that
7+
// godoclint can, but must not, detect.
8+
import _ "go/ast"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//golangcitest:args -Egodoclint
2+
//golangcitest:config_path testdata/godoclint.yml
3+
4+
package testdata // want `package should have a godoc`
5+
6+
// This is a special stdlib import because the package itself has issues that
7+
// godoclint can, but must not, detect.
8+
import _ "go/ast"

0 commit comments

Comments
 (0)