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

Function TestTraverseNoParentFlags

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

Source from the content-addressed store, hash-verified

2342}
2343
2344func TestTraverseNoParentFlags(t *testing.T) {
2345 rootCmd := &Command{Use: "root", TraverseChildren: true}
2346 rootCmd.Flags().String("foo", "", "foo things")
2347
2348 childCmd := &Command{Use: "child"}
2349 childCmd.Flags().String("str", "", "")
2350 rootCmd.AddCommand(childCmd)
2351
2352 c, args, err := rootCmd.Traverse([]string{"child"})
2353 if err != nil {
2354 t.Errorf("Unexpected error: %v", err)
2355 }
2356 if len(args) != 0 {
2357 t.Errorf("Wrong args %v", args)
2358 }
2359 if c.Name() != childCmd.Name() {
2360 t.Errorf("Expected command: %q, got: %q", childCmd.Name(), c.Name())
2361 }
2362}
2363
2364func TestTraverseWithBadParentFlags(t *testing.T) {
2365 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