mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
doc: Add tests
This commit is contained in:
parent
424a56a206
commit
97b661963b
3 changed files with 48 additions and 12 deletions
|
@ -13,9 +13,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var _ = fmt.Println
|
||||
var _ = os.Stderr
|
||||
|
||||
func translate(in string) string {
|
||||
return strings.Replace(in, "-", "\\-", -1)
|
||||
}
|
||||
|
@ -153,7 +150,7 @@ func TestGenManTree(t *testing.T) {
|
|||
header := &GenManHeader{Section: "2"}
|
||||
tmpdir, err := ioutil.TempDir("", "test-gen-man-tree")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create tempdir: %s", err.Error())
|
||||
t.Fatalf("Failed to create tmpdir: %s", err.Error())
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@ package doc
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var _ = fmt.Println
|
||||
var _ = os.Stderr
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func TestGenMdDoc(t *testing.T) {
|
||||
c := initializeWithRootCmd()
|
||||
|
@ -86,3 +86,22 @@ func TestGenMdNoTag(t *testing.T) {
|
|||
checkStringOmits(t, found, unexpected)
|
||||
|
||||
}
|
||||
|
||||
func TestGenMdTree(t *testing.T) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "do [OPTIONS] arg1 arg2",
|
||||
}
|
||||
tmpdir, err := ioutil.TempDir("", "test-gen-md-tree")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create tmpdir: %s", err.Error())
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
if err := GenMarkdownTree(cmd, tmpdir); err != nil {
|
||||
t.Fatalf("GenMarkdownTree failed: %s", err.Error())
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(tmpdir, "do.md")); err != nil {
|
||||
t.Fatalf("Expected file 'do.md' to exist")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package doc
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var _ = fmt.Println
|
||||
var _ = os.Stderr
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func TestGenYamlDoc(t *testing.T) {
|
||||
c := initializeWithRootCmd()
|
||||
|
@ -86,3 +86,23 @@ func TestGenYamlNoTag(t *testing.T) {
|
|||
checkStringOmits(t, found, unexpected)
|
||||
|
||||
}
|
||||
|
||||
func TestGenYamlTree(t *testing.T) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "do [OPTIONS] arg1 arg2",
|
||||
}
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "test-gen-yaml-tree")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create tmpdir: %s", err.Error())
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
if err := GenYamlTree(cmd, tmpdir); err != nil {
|
||||
t.Fatalf("GenYamlTree failed: %s", err.Error())
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(tmpdir, "do.yaml")); err != nil {
|
||||
t.Fatalf("Expected file 'do.yaml' to exist")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue