(t *testing.T)
| 175 | } |
| 176 | |
| 177 | func TestExecuteContext(t *testing.T) { |
| 178 | ctx := context.TODO() |
| 179 | |
| 180 | ctxRun := func(cmd *Command, args []string) { |
| 181 | if cmd.Context() != ctx { |
| 182 | t.Errorf("Command %q must have context when called with ExecuteContext", cmd.Use) |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | rootCmd := &Command{Use: "root", Run: ctxRun, PreRun: ctxRun} |
| 187 | childCmd := &Command{Use: "child", Run: ctxRun, PreRun: ctxRun} |
| 188 | granchildCmd := &Command{Use: "grandchild", Run: ctxRun, PreRun: ctxRun} |
| 189 | |
| 190 | childCmd.AddCommand(granchildCmd) |
| 191 | rootCmd.AddCommand(childCmd) |
| 192 | |
| 193 | if _, err := executeCommandWithContext(ctx, rootCmd, ""); err != nil { |
| 194 | t.Errorf("Root command must not fail: %+v", err) |
| 195 | } |
| 196 | |
| 197 | if _, err := executeCommandWithContext(ctx, rootCmd, "child"); err != nil { |
| 198 | t.Errorf("Subcommand must not fail: %+v", err) |
| 199 | } |
| 200 | |
| 201 | if _, err := executeCommandWithContext(ctx, rootCmd, "child", "grandchild"); err != nil { |
| 202 | t.Errorf("Command child must not fail: %+v", err) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | func TestExecuteContextC(t *testing.T) { |
| 207 | ctx := context.TODO() |
nothing calls this directly
no test coverage detected