2015-08-19 01:33:41 +03:00
|
|
|
package cobra
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fmt.Println
|
|
|
|
var _ = os.Stderr
|
|
|
|
|
|
|
|
func translate(in string) string {
|
|
|
|
return strings.Replace(in, "-", "\\-", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenManDoc(t *testing.T) {
|
|
|
|
c := initializeWithRootCmd()
|
|
|
|
// Need two commands to run the command alphabetical sort
|
|
|
|
cmdEcho.AddCommand(cmdTimes, cmdEchoSub, cmdDeprecated)
|
|
|
|
c.AddCommand(cmdPrint, cmdEcho)
|
|
|
|
cmdRootWithRun.PersistentFlags().StringVarP(&flags2a, "rootflag", "r", "two", strtwoParentHelp)
|
|
|
|
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
|
|
|
|
// We generate on a subcommand so we have both subcommands and parents
|
|
|
|
cmdEcho.GenMan("PROJECT", out)
|
|
|
|
found := out.String()
|
|
|
|
|
2015-09-08 19:32:15 +03:00
|
|
|
// Make sure parent has - in CommandPath() in SEE ALSO:
|
|
|
|
parentPath := cmdEcho.Parent().CommandPath()
|
|
|
|
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
|
|
|
|
expected := translate(dashParentPath)
|
|
|
|
expected = expected + "(1)"
|
|
|
|
checkStringContains(t, found, expected)
|
|
|
|
|
2015-08-19 01:33:41 +03:00
|
|
|
// Our description
|
2015-09-08 19:32:15 +03:00
|
|
|
expected = translate(cmdEcho.Name())
|
|
|
|
checkStringContains(t, found, expected)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
|
|
|
// Better have our example
|
|
|
|
expected = translate(cmdEcho.Name())
|
2015-09-08 19:32:15 +03:00
|
|
|
checkStringContains(t, found, expected)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
|
|
|
// A local flag
|
|
|
|
expected = "boolone"
|
2015-09-08 19:32:15 +03:00
|
|
|
checkStringContains(t, found, expected)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
|
|
|
// persistent flag on parent
|
|
|
|
expected = "rootflag"
|
2015-09-08 19:32:15 +03:00
|
|
|
checkStringContains(t, found, expected)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
|
|
|
// We better output info about our parent
|
|
|
|
expected = translate(cmdRootWithRun.Name())
|
2015-09-08 19:32:15 +03:00
|
|
|
checkStringContains(t, found, expected)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
|
|
|
// And about subcommands
|
|
|
|
expected = translate(cmdEchoSub.Name())
|
2015-09-08 19:32:15 +03:00
|
|
|
checkStringContains(t, found, expected)
|
2015-08-19 01:33:41 +03:00
|
|
|
|
|
|
|
unexpected := translate(cmdDeprecated.Name())
|
2015-09-08 19:32:15 +03:00
|
|
|
checkStringOmits(t, found, unexpected)
|
2015-08-19 01:33:41 +03:00
|
|
|
}
|