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

Function TestEmptyPositionalArgs

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

Source from the content-addressed store, hash-verified

6104}
6105
6106func TestEmptyPositionalArgs(t *testing.T) {
6107 testCases := []struct {
6108 Name string
6109 Args []string
6110 Expected []string
6111 }{
6112 {
6113 Name: "empty arg between values",
6114 Args: []string{"app", "hello", "", "world"},
6115 Expected: []string{"hello", "", "world"},
6116 },
6117 {
6118 Name: "empty arg at start",
6119 Args: []string{"app", "", "hello"},
6120 Expected: []string{"", "hello"},
6121 },
6122 {
6123 Name: "whitespace-only arg",
6124 Args: []string{"app", "hello", " ", "world"},
6125 Expected: []string{"hello", " ", "world"},
6126 },
6127 }
6128
6129 for _, tc := range testCases {
6130 t.Run(tc.Name, func(t *testing.T) {
6131 var args []string
6132
6133 cmd := &Command{
6134 Action: func(_ context.Context, cmd *Command) error {
6135 args = cmd.Args().Slice()
6136 return nil
6137 },
6138 }
6139
6140 err := cmd.Run(buildTestContext(t), tc.Args)
6141 assert.NoError(t, err)
6142 assert.Equal(t, tc.Expected, args)
6143 })
6144 }
6145}
6146
6147// Regression for #2234: an empty positional arg following a flag used to be
6148// dropped along with every arg after it.

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected