From 97b661963b026ff6d2d9cbb022876ab6057f9e73 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Fri, 24 Mar 2017 22:40:39 +0500 Subject: [PATCH] doc: Add tests --- doc/man_docs_test.go | 5 +---- doc/md_docs_test.go | 27 +++++++++++++++++++++++---- doc/yaml_docs_test.go | 28 ++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/doc/man_docs_test.go b/doc/man_docs_test.go index 26b8fcc6..9b272917 100644 --- a/doc/man_docs_test.go +++ b/doc/man_docs_test.go @@ -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) diff --git a/doc/md_docs_test.go b/doc/md_docs_test.go index 86ee0293..f4f3bc14 100644 --- a/doc/md_docs_test.go +++ b/doc/md_docs_test.go @@ -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") + } +} diff --git a/doc/yaml_docs_test.go b/doc/yaml_docs_test.go index a41499e1..fb969da2 100644 --- a/doc/yaml_docs_test.go +++ b/doc/yaml_docs_test.go @@ -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") + } +}