Skip to content

Commit

Permalink
test(cmd): add check mode tests for embed (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
princjef committed Aug 19, 2023
1 parent d595c3a commit 8b1606a
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cmd/gomarkdoc/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -292,6 +293,49 @@ func TestCommand_embed(t *testing.T) {
verify(t, "./embed", "github")
}

func TestCommand_embed_check(t *testing.T) {
is := is.New(t)

err := os.Chdir(filepath.Join(wd, "../../testData"))
is.NoErr(err)

os.Args = []string{
"gomarkdoc", "./embed",
"--embed",
"--check",
"-o", "{{.Dir}}/README-github-invalid.md",
"--repository.url", "https://github.com/princjef/gomarkdoc",
"--repository.default-branch", "master",
"--repository.path", "/testData/",
}
cleanup(t, "embed")

log.SetFlags(0)

cmd := buildCommand()

err = cmd.Execute()
is.True(err != nil) // Should fail

os.Args = []string{
"gomarkdoc", "./embed",
"--embed",
"--check",
"-o", "{{.Dir}}/README-github.md",
"--repository.url", "https://github.com/princjef/gomarkdoc",
"--repository.default-branch", "master",
"--repository.path", "/testData/",
}
cleanup(t, "embed")

log.SetFlags(0)

cmd = buildCommand()

err = cmd.Execute()
is.NoErr(err) // Should pass
}

func TestCompare(t *testing.T) {
tests := []struct {
b1, b2 []byte
Expand Down
100 changes: 100 additions & 0 deletions testData/embed/README-github-invalid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
This is content before the embed

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# embed

```go
import "github.com/princjef/gomarkdoc/testData/embed"
```

Package embed tests out embedding of documentation in an existing readme. This is an extra comment that is invalid.

## Index

- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)


<a name="EmbeddedFunc"></a>
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)

```go
func EmbeddedFunc(param int) int
```

EmbeddedFunc is present in embedded content.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->

This is content after the embed

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# embed

```go
import "github.com/princjef/gomarkdoc/testData/embed"
```

Package embed tests out embedding of documentation in an existing readme.

## Index

- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)


<a name="EmbeddedFunc"></a>
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)

```go
func EmbeddedFunc(param int) int
```

EmbeddedFunc is present in embedded content.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->

This is content after the second embed

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# embed

```go
import "github.com/princjef/gomarkdoc/testData/embed"
```

Package embed tests out embedding of documentation in an existing readme.

## Index

- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>)


<a name="EmbeddedFunc"></a>
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)

```go
func EmbeddedFunc(param int) int
```

EmbeddedFunc is present in embedded content.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->

This is content after the third embed

0 comments on commit 8b1606a

Please sign in to comment.