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

Function Test_Help_Custom_Flags

help_test.go:196–223  ·  help_test.go::Test_Help_Custom_Flags
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func Test_Help_Custom_Flags(t *testing.T) {
197 oldFlag := HelpFlag
198 defer func() {
199 HelpFlag = oldFlag
200 }()
201
202 HelpFlag = &BoolFlag{
203 Name: "help",
204 Aliases: []string{"x"},
205 Usage: "show help",
206 }
207
208 out := &bytes.Buffer{}
209
210 cmd := &Command{
211 Flags: []Flag{
212 &BoolFlag{Name: "foo", Aliases: []string{"h"}},
213 },
214 Action: func(_ context.Context, cmd *Command) error {
215 assert.True(t, cmd.Bool("h"), "custom help flag not set")
216 return nil
217 },
218 Writer: out,
219 }
220
221 _ = cmd.Run(buildTestContext(t), []string{"test", "-h"})
222 require.Len(t, out.String(), 0)
223}
224
225func Test_Help_Nil_Flags(t *testing.T) {
226 oldFlag := HelpFlag

Callers

nothing calls this directly

Calls 5

BoolMethod · 0.95
RunMethod · 0.95
buildTestContextFunction · 0.85
LenMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected