-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdoc_test.go
More file actions
102 lines (89 loc) · 1.46 KB
/
doc_test.go
File metadata and controls
102 lines (89 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"bytes"
"os"
"testing"
)
type (
testTbl struct {
lookFor string
outExpected string
errExpected string
errStr string
}
)
func dotest(t *testing.T, test testTbl) {
testdir := "/src/github.com/NeowayLabs/nash/cmd/nashdoc/testcases/"
nashpath := os.Getenv("GOPATH") + testdir
os.Setenv("NASHPATH", nashpath)
var (
stdout, stderr bytes.Buffer
)
err := doc(&stdout, &stderr, []string{test.lookFor})
if err != nil {
if test.errStr != "" {
if err.Error() != test.errStr {
t.Fatalf("Expected error '%s', but got '%s'",
test.errStr, err.Error())
}
} else {
t.Fatal(err)
}
}
gotOut := string(stdout.Bytes())
gotErr := string(stderr.Bytes())
if test.outExpected != gotOut {
t.Fatalf("Stdout differs: '%s' != '%s'", test.outExpected, gotOut)
}
if test.errExpected != gotErr {
t.Fatalf("Stderr differs: '%s' != '%s'", test.errExpected, gotErr)
}
}
func TestDoc(t *testing.T) {
for _, test := range []testTbl{
{
"somepkg.somefn",
`fn somefn(a, b, c, d)
somefn is a testcase function
multiples comments
etc
etc
`, ``, "",
},
// Test empty pkg and func
{
"",
"",
"Usage: nashdoc.test <package>.<fn name or wildcard>\n",
"",
},
// test non existent package
{
"blahbleh.bli",
"",
"",
"",
},
{
"a.a",
`fn a()
`, ``, "",
},
{
"a.b",
`fn b(a)
bleh
`,
``, "",
},
{
"a.c",
`fn c(a, b)
carrr
`,
``, "",
},
} {
dotest(t, test)
}
}