MCPcopy
hub / github.com/spf13/cobra / TestTraverseWithBadChildFlag

Function TestTraverseWithBadChildFlag

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

Source from the content-addressed store, hash-verified

2380}
2381
2382func TestTraverseWithBadChildFlag(t *testing.T) {
2383 rootCmd := &Command{Use: "root", TraverseChildren: true}
2384 rootCmd.Flags().String("str", "", "")
2385
2386 childCmd := &Command{Use: "child"}
2387 rootCmd.AddCommand(childCmd)
2388
2389 // Expect no error because the last commands args shouldn't be parsed in
2390 // Traverse.
2391 c, args, err := rootCmd.Traverse([]string{"child", "--str"})
2392 if err != nil {
2393 t.Errorf("Unexpected error: %v", err)
2394 }
2395 if len(args) != 1 && args[0] != "--str" {
2396 t.Errorf("Wrong args: %v", args)
2397 }
2398 if c.Name() != childCmd.Name() {
2399 t.Errorf("Expected command %q, got: %q", childCmd.Name(), c.Name())
2400 }
2401}
2402
2403func TestTraverseWithTwoSubcommands(t *testing.T) {
2404 rootCmd := &Command{Use: "root", TraverseChildren: true}

Callers

nothing calls this directly

Calls 5

FlagsMethod · 0.95
AddCommandMethod · 0.95
TraverseMethod · 0.95
NameMethod · 0.95
StringMethod · 0.80

Tested by

no test coverage detected