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

Function TestEmptyPositionalArgsAfterFlag

command_test.go:6149–6192  ·  view source on GitHub ↗

Regression for #2234: an empty positional arg following a flag used to be dropped along with every arg after it.

(t *testing.T)

Source from the content-addressed store, hash-verified

6147// Regression for #2234: an empty positional arg following a flag used to be
6148// dropped along with every arg after it.
6149func TestEmptyPositionalArgsAfterFlag(t *testing.T) {
6150 testCases := []struct {
6151 Name string
6152 Args []string
6153 ExpectedArgs []string
6154 ExpectedFlag string
6155 }{
6156 {
6157 Name: "empty arg after equals-form flag",
6158 Args: []string{"app", "-f=something", "", "arg2", "arg3"},
6159 ExpectedArgs: []string{"", "arg2", "arg3"},
6160 ExpectedFlag: "something",
6161 },
6162 {
6163 Name: "empty arg after space-form flag",
6164 Args: []string{"app", "-f", "something", "", "arg2"},
6165 ExpectedArgs: []string{"", "arg2"},
6166 ExpectedFlag: "something",
6167 },
6168 }
6169
6170 for _, tc := range testCases {
6171 t.Run(tc.Name, func(t *testing.T) {
6172 var args []string
6173 var flagVal string
6174
6175 cmd := &Command{
6176 Flags: []Flag{
6177 &StringFlag{Name: "f"},
6178 },
6179 Action: func(_ context.Context, cmd *Command) error {
6180 args = cmd.Args().Slice()
6181 flagVal = cmd.String("f")
6182 return nil
6183 },
6184 }
6185
6186 err := cmd.Run(buildTestContext(t), tc.Args)
6187 assert.NoError(t, err)
6188 assert.Equal(t, tc.ExpectedArgs, args)
6189 assert.Equal(t, tc.ExpectedFlag, flagVal)
6190 })
6191 }
6192}
6193
6194func TestFlagEqualsEmptyValue(t *testing.T) {
6195 t.Run("--flag= sets empty string", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

RunMethod · 0.95
ArgsMethod · 0.95
StringMethod · 0.95
buildTestContextFunction · 0.85
SliceMethod · 0.65

Tested by

no test coverage detected