(t *testing.T)
| 204 | } |
| 205 | |
| 206 | func TestExecuteContextC(t *testing.T) { |
| 207 | ctx := context.TODO() |
| 208 | |
| 209 | ctxRun := func(cmd *Command, args []string) { |
| 210 | if cmd.Context() != ctx { |
| 211 | t.Errorf("Command %q must have context when called with ExecuteContext", cmd.Use) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | rootCmd := &Command{Use: "root", Run: ctxRun, PreRun: ctxRun} |
| 216 | childCmd := &Command{Use: "child", Run: ctxRun, PreRun: ctxRun} |
| 217 | granchildCmd := &Command{Use: "grandchild", Run: ctxRun, PreRun: ctxRun} |
| 218 | |
| 219 | childCmd.AddCommand(granchildCmd) |
| 220 | rootCmd.AddCommand(childCmd) |
| 221 | |
| 222 | if _, _, err := executeCommandWithContextC(ctx, rootCmd, ""); err != nil { |
| 223 | t.Errorf("Root command must not fail: %+v", err) |
| 224 | } |
| 225 | |
| 226 | if _, _, err := executeCommandWithContextC(ctx, rootCmd, "child"); err != nil { |
| 227 | t.Errorf("Subcommand must not fail: %+v", err) |
| 228 | } |
| 229 | |
| 230 | if _, _, err := executeCommandWithContextC(ctx, rootCmd, "child", "grandchild"); err != nil { |
| 231 | t.Errorf("Command child must not fail: %+v", err) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func TestExecute_NoContext(t *testing.T) { |
| 236 | run := func(cmd *Command, args []string) { |
nothing calls this directly
no test coverage detected