Skip to content

Commit 8b1606a

Browse files
authored
test(cmd): add check mode tests for embed (#110)
1 parent d595c3a commit 8b1606a

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

cmd/gomarkdoc/command_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7+
"log"
78
"os"
89
"path/filepath"
910
"strings"
@@ -292,6 +293,49 @@ func TestCommand_embed(t *testing.T) {
292293
verify(t, "./embed", "github")
293294
}
294295

296+
func TestCommand_embed_check(t *testing.T) {
297+
is := is.New(t)
298+
299+
err := os.Chdir(filepath.Join(wd, "../../testData"))
300+
is.NoErr(err)
301+
302+
os.Args = []string{
303+
"gomarkdoc", "./embed",
304+
"--embed",
305+
"--check",
306+
"-o", "{{.Dir}}/README-github-invalid.md",
307+
"--repository.url", "https://github.com/princjef/gomarkdoc",
308+
"--repository.default-branch", "master",
309+
"--repository.path", "/testData/",
310+
}
311+
cleanup(t, "embed")
312+
313+
log.SetFlags(0)
314+
315+
cmd := buildCommand()
316+
317+
err = cmd.Execute()
318+
is.True(err != nil) // Should fail
319+
320+
os.Args = []string{
321+
"gomarkdoc", "./embed",
322+
"--embed",
323+
"--check",
324+
"-o", "{{.Dir}}/README-github.md",
325+
"--repository.url", "https://github.com/princjef/gomarkdoc",
326+
"--repository.default-branch", "master",
327+
"--repository.path", "/testData/",
328+
}
329+
cleanup(t, "embed")
330+
331+
log.SetFlags(0)
332+
333+
cmd = buildCommand()
334+
335+
err = cmd.Execute()
336+
is.NoErr(err) // Should pass
337+
}
338+
295339
func TestCompare(t *testing.T) {
296340
tests := []struct {
297341
b1, b2 []byte
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
This is content before the embed
2+
3+
<!-- gomarkdoc:embed:start -->
4+
5+
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
6+
7+
# embed
8+
9+
```go
10+
import "github.com/princjef/gomarkdoc/testData/embed"
11+
```
12+
13+
Package embed tests out embedding of documentation in an existing readme. This is an extra comment that is invalid.
14+
15+
## Index
16+
17+
- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)
18+
19+
20+
<a name="EmbeddedFunc"></a>
21+
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)
22+
23+
```go
24+
func EmbeddedFunc(param int) int
25+
```
26+
27+
EmbeddedFunc is present in embedded content.
28+
29+
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
30+
31+
32+
<!-- gomarkdoc:embed:end -->
33+
34+
This is content after the embed
35+
36+
<!-- gomarkdoc:embed:start -->
37+
38+
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
39+
40+
# embed
41+
42+
```go
43+
import "github.com/princjef/gomarkdoc/testData/embed"
44+
```
45+
46+
Package embed tests out embedding of documentation in an existing readme.
47+
48+
## Index
49+
50+
- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)
51+
52+
53+
<a name="EmbeddedFunc"></a>
54+
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)
55+
56+
```go
57+
func EmbeddedFunc(param int) int
58+
```
59+
60+
EmbeddedFunc is present in embedded content.
61+
62+
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
63+
64+
65+
<!-- gomarkdoc:embed:end -->
66+
67+
This is content after the second embed
68+
69+
<!-- gomarkdoc:embed:start -->
70+
71+
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
72+
73+
# embed
74+
75+
```go
76+
import "github.com/princjef/gomarkdoc/testData/embed"
77+
```
78+
79+
Package embed tests out embedding of documentation in an existing readme.
80+
81+
## Index
82+
83+
- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)
84+
85+
86+
<a name="EmbeddedFunc"></a>
87+
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)
88+
89+
```go
90+
func EmbeddedFunc(param int) int
91+
```
92+
93+
EmbeddedFunc is present in embedded content.
94+
95+
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
96+
97+
98+
<!-- gomarkdoc:embed:end -->
99+
100+
This is content after the third embed

0 commit comments

Comments
 (0)