MCPcopy
hub / github.com/urfave/cli / TestCommand_IncorrectUsageOnMutuallyExclusiveFlagsViaRun

Function TestCommand_IncorrectUsageOnMutuallyExclusiveFlagsViaRun

command_test.go:2061–2117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2059}
2060
2061func TestCommand_IncorrectUsageOnMutuallyExclusiveFlagsViaRun(t *testing.T) {
2062 t.Run("root command with mutex violation", func(t *testing.T) {
2063 r := require.New(t)
2064 var buf bytes.Buffer
2065 var errBuf bytes.Buffer
2066
2067 cmd := &Command{
2068 Writer: &buf,
2069 ErrWriter: &errBuf,
2070 MutuallyExclusiveFlags: []MutuallyExclusiveFlags{
2071 {
2072 Flags: [][]Flag{
2073 {&StringFlag{Name: "foo1"}},
2074 {&StringFlag{Name: "foo2"}},
2075 },
2076 },
2077 },
2078 }
2079
2080 _ = cmd.Run(buildTestContext(t), []string{"command", "--foo1", "v1", "--foo2", "v2"})
2081 r.Contains(errBuf.String(), "Incorrect Usage")
2082 r.Contains(buf.String(), "NAME:")
2083 r.Contains(buf.String(), "command")
2084 })
2085
2086 t.Run("subcommand with mutex violation", func(t *testing.T) {
2087 r := require.New(t)
2088 var buf bytes.Buffer
2089 var errBuf bytes.Buffer
2090
2091 cmd := &Command{
2092 Writer: &buf,
2093 ErrWriter: &errBuf,
2094 Action: func(ctx context.Context, cmd *Command) error {
2095 return nil
2096 },
2097 Commands: []*Command{
2098 {
2099 Name: "sub",
2100 MutuallyExclusiveFlags: []MutuallyExclusiveFlags{
2101 {
2102 Flags: [][]Flag{
2103 {&StringFlag{Name: "foo1"}},
2104 {&StringFlag{Name: "foo2"}},
2105 },
2106 },
2107 },
2108 },
2109 },
2110 }
2111
2112 _ = cmd.Run(buildTestContext(t), []string{"command", "sub", "--foo1", "v1", "--foo2", "v2"})
2113 r.Contains(errBuf.String(), "Incorrect Usage")
2114 r.Contains(buf.String(), "NAME:")
2115 r.Contains(buf.String(), "sub")
2116 })
2117}
2118

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
buildTestContextFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected