(t *testing.T)
| 75 | } |
| 76 | |
| 77 | func TestUnknownFlagTokens(t *testing.T) { |
| 78 | _, drive, _ := newGroupTree() |
| 79 | // Give a subcommand a flag so a misplaced-but-known flag (the user omitted |
| 80 | // the subcommand) is distinguished from a genuinely unknown one. |
| 81 | for _, c := range drive.Commands() { |
| 82 | if c.Name() == "+search" { |
| 83 | c.Flags().String("query", "", "") |
| 84 | } |
| 85 | } |
| 86 | cases := []struct { |
| 87 | name string |
| 88 | rawArgs []string |
| 89 | want []string |
| 90 | }{ |
| 91 | {"genuinely unknown long flag", []string{"drive", "--badflag"}, []string{"--badflag"}}, |
| 92 | {"flag known on a subcommand (misplaced)", []string{"drive", "--query", "x"}, nil}, |
| 93 | {"no flags at all", []string{"drive"}, nil}, |
| 94 | {"tokens after -- are positional", []string{"drive", "--", "--badflag"}, nil}, |
| 95 | {"unknown shorthand", []string{"drive", "-Z"}, []string{"-Z"}}, |
| 96 | } |
| 97 | for _, tc := range cases { |
| 98 | t.Run(tc.name, func(t *testing.T) { |
| 99 | got := unknownFlagTokens(drive, tc.rawArgs) |
| 100 | if len(got) != len(tc.want) { |
| 101 | t.Fatalf("unknownFlagTokens(%v) = %v, want %v", tc.rawArgs, got, tc.want) |
| 102 | } |
| 103 | for i := range got { |
| 104 | if got[i] != tc.want[i] { |
| 105 | t.Errorf("token[%d] = %q, want %q", i, got[i], tc.want[i]) |
| 106 | } |
| 107 | } |
| 108 | }) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | func TestUnknownSubcommandRunE_FlagBeforeSubcommandIsStructured(t *testing.T) { |
| 113 | _, drive, _ := newGroupTree() |
nothing calls this directly
no test coverage detected