aboutsummaryrefslogtreecommitdiffstats
path: root/subcmd_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'subcmd_test.go')
-rw-r--r--subcmd_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/subcmd_test.go b/subcmd_test.go
index 6841f9e..57b86c2 100644
--- a/subcmd_test.go
+++ b/subcmd_test.go
@@ -5,6 +5,7 @@ import (
"context"
"flag"
"os"
+ "os/exec"
"strings"
"testing"
@@ -250,6 +251,46 @@ func TestHelpCommand_UnknownCommand(t *testing.T) {
check.Contains(t, buf.String(), "Unknown command: unknown")
}
+func TestManHelpCommand_NoArgs(t *testing.T) {
+ var calledName string
+ var calledArgs []string
+ oldExecCommand := execCommand
+ execCommand = func(name string, args ...string) *exec.Cmd {
+ calledName = name
+ calledArgs = args
+ return exec.Command("true")
+ }
+ defer func() { execCommand = oldExecCommand }()
+ help := ManHelpCommand("myapp")
+ fs := flag.NewFlagSet("help", flag.ExitOnError)
+ fs.Parse([]string{})
+
+ status := help.Execute(context.Background(), fs)
+
+ check.Equal(t, status, ExitSuccess)
+ check.Equal(t, calledName, "man")
+ check.Equal(t, len(calledArgs), 1)
+ check.Equal(t, calledArgs[0], "myapp")
+}
+
+func TestManHelpCommand_WithSubcommand(t *testing.T) {
+ var calledArgs []string
+ oldExecCommand := execCommand
+ execCommand = func(name string, args ...string) *exec.Cmd {
+ calledArgs = args
+ return exec.Command("true")
+ }
+ defer func() { execCommand = oldExecCommand }()
+ help := ManHelpCommand("myapp")
+ fs := flag.NewFlagSet("help", flag.ExitOnError)
+ fs.Parse([]string{"build"})
+
+ status := help.Execute(context.Background(), fs)
+
+ check.Equal(t, status, ExitSuccess)
+ check.Equal(t, calledArgs[0], "myapp-build")
+}
+
func TestCommandsCommand(t *testing.T) {
var buf bytes.Buffer
r := newTestRegistry(