doc: Add tests

This commit is contained in:
Albert Nigmatzianov 2017-03-24 22:40:39 +05:00
parent 424a56a206
commit 97b661963b
3 changed files with 48 additions and 12 deletions

View file

@ -13,9 +13,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var _ = fmt.Println
var _ = os.Stderr
func translate(in string) string { func translate(in string) string {
return strings.Replace(in, "-", "\\-", -1) return strings.Replace(in, "-", "\\-", -1)
} }
@ -153,7 +150,7 @@ func TestGenManTree(t *testing.T) {
header := &GenManHeader{Section: "2"} header := &GenManHeader{Section: "2"}
tmpdir, err := ioutil.TempDir("", "test-gen-man-tree") tmpdir, err := ioutil.TempDir("", "test-gen-man-tree")
if err != nil { 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) defer os.RemoveAll(tmpdir)

View file

@ -2,14 +2,14 @@ package doc
import ( import (
"bytes" "bytes"
"fmt" "io/ioutil"
"os" "os"
"path/filepath"
"strings" "strings"
"testing" "testing"
)
var _ = fmt.Println "github.com/spf13/cobra"
var _ = os.Stderr )
func TestGenMdDoc(t *testing.T) { func TestGenMdDoc(t *testing.T) {
c := initializeWithRootCmd() c := initializeWithRootCmd()
@ -86,3 +86,22 @@ func TestGenMdNoTag(t *testing.T) {
checkStringOmits(t, found, unexpected) 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")
}
}

View file

@ -2,14 +2,14 @@ package doc
import ( import (
"bytes" "bytes"
"fmt" "io/ioutil"
"os" "os"
"path/filepath"
"strings" "strings"
"testing" "testing"
)
var _ = fmt.Println "github.com/spf13/cobra"
var _ = os.Stderr )
func TestGenYamlDoc(t *testing.T) { func TestGenYamlDoc(t *testing.T) {
c := initializeWithRootCmd() c := initializeWithRootCmd()
@ -86,3 +86,23 @@ func TestGenYamlNoTag(t *testing.T) {
checkStringOmits(t, found, unexpected) 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")
}
}