diff --git a/doc/cmd_test.go b/doc/cmd_test.go index d29c577d..fa42b96e 100644 --- a/doc/cmd_test.go +++ b/doc/cmd_test.go @@ -28,6 +28,7 @@ func init() { echoCmd.AddCommand(timesCmd, echoSubCmd, deprecatedCmd) rootCmd.AddCommand(printCmd, echoCmd) + rootCmd.AddCommand(helpDoc) } var rootCmd = &cobra.Command{ @@ -73,6 +74,19 @@ var printCmd = &cobra.Command{ Long: `an absolutely utterly useless command for testing.`, } +var helpText = `Long text describing the subject. + +And more and more text. +And more and more text. + +` + +var helpDoc = &cobra.Command{ + Use: "subject", + Short: "Help on subject", + Long: helpText, +} + func checkStringContains(t *testing.T, got, expected string) { if !strings.Contains(got, expected) { t.Errorf("Expected to contain: \n %v\nGot:\n %v\n", expected, got) diff --git a/doc/md_docs_test.go b/doc/md_docs_test.go index c060f32f..dc5a8d98 100644 --- a/doc/md_docs_test.go +++ b/doc/md_docs_test.go @@ -81,6 +81,35 @@ func TestGenMdTree(t *testing.T) { } } +func TestGenTreeWithAdditionalHelpTopics(t *testing.T) { + tmpdir, err := ioutil.TempDir("", "test-gen-md-tree") + if err != nil { + t.Fatalf("Failed to create tmpdir: %v", err) + } + defer os.RemoveAll(tmpdir) + + if err := GenMarkdownTree(rootCmd, tmpdir); err != nil { + t.Fatal(err) + } + + filesToTest := []string{"root.md", "root_print.md", "root_subject.md"} + for _, f := range filesToTest { + if _, err := os.Stat(filepath.Join(tmpdir, f)); err != nil { + t.Fatalf("Expected file '%s' to exist", f) + } + } +} + +func TestGenMdWithAdditionalHelpTopics(t *testing.T) { + buf := new(bytes.Buffer) + if err := GenMarkdown(rootCmd, buf); err != nil { + t.Fatal(err) + } + + output := buf.String() + checkStringContains(t, output, "Help on subject") +} + func BenchmarkGenMarkdownToFile(b *testing.B) { file, err := ioutil.TempFile("", "") if err != nil {