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

Function Test_Version_Custom_Flags

help_test.go:243–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

241}
242
243func Test_Version_Custom_Flags(t *testing.T) {
244 oldFlag := VersionFlag
245 defer func() {
246 VersionFlag = oldFlag
247 }()
248
249 VersionFlag = &BoolFlag{
250 Name: "version",
251 Aliases: []string{"V"},
252 Usage: "show version",
253 }
254
255 out := &bytes.Buffer{}
256 cmd := &Command{
257 Flags: []Flag{
258 &BoolFlag{Name: "foo", Aliases: []string{"v"}},
259 },
260 Action: func(_ context.Context, cmd *Command) error {
261 assert.True(t, cmd.Bool("v"), "custom version flag not set")
262 return nil
263 },
264 Writer: out,
265 }
266
267 _ = cmd.Run(buildTestContext(t), []string{"test", "-v"})
268 require.Len(t, out.String(), 0)
269}
270
271func Test_helpCommand_Action_ErrorIfNoTopic(t *testing.T) {
272 cmd := &Command{}

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