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

Function TestCommand_VisibleCommands

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

Source from the content-addressed store, hash-verified

1198}
1199
1200func TestCommand_VisibleCommands(t *testing.T) {
1201 cmd := &Command{
1202 Commands: []*Command{
1203 {
1204 Name: "frob",
1205 Action: func(context.Context, *Command) error { return nil },
1206 },
1207 {
1208 Name: "frib",
1209 Hidden: true,
1210 Action: func(context.Context, *Command) error { return nil },
1211 },
1212 },
1213 }
1214
1215 cmd.setupDefaults([]string{"test"})
1216 expected := []*Command{
1217 cmd.Commands[0],
1218 }
1219 actual := cmd.VisibleCommands()
1220 assert.Len(t, actual, len(expected))
1221 for i, actualCommand := range actual {
1222 expectedCommand := expected[i]
1223
1224 if expectedCommand.Action != nil {
1225 // comparing func addresses is OK!
1226 assert.Equal(t, fmt.Sprintf("%p", expectedCommand.Action), fmt.Sprintf("%p", actualCommand.Action))
1227 }
1228
1229 func() {
1230 // nil out funcs, as they cannot be compared
1231 // (https://github.com/golang/go/issues/8554)
1232 expectedAction := expectedCommand.Action
1233 actualAction := actualCommand.Action
1234 defer func() {
1235 expectedCommand.Action = expectedAction
1236 actualCommand.Action = actualAction
1237 }()
1238 expectedCommand.Action = nil
1239 actualCommand.Action = nil
1240
1241 assert.Equal(t, expectedCommand, actualCommand)
1242 }()
1243 }
1244}
1245
1246func TestCommand_UseShortOptionHandling(t *testing.T) {
1247 var one, two bool

Callers

nothing calls this directly

Calls 3

setupDefaultsMethod · 0.95
VisibleCommandsMethod · 0.95
LenMethod · 0.65

Tested by

no test coverage detected