(t *testing.T)
| 2011 | } |
| 2012 | |
| 2013 | func TestCommand_IncorrectUsageOnRequiredFlagsViaRun(t *testing.T) { |
| 2014 | t.Run("root command missing required flag", func(t *testing.T) { |
| 2015 | r := require.New(t) |
| 2016 | var buf bytes.Buffer |
| 2017 | var errBuf bytes.Buffer |
| 2018 | |
| 2019 | cmd := &Command{ |
| 2020 | Writer: &buf, |
| 2021 | ErrWriter: &errBuf, |
| 2022 | Flags: []Flag{ |
| 2023 | &StringFlag{Name: "requiredFlag", Required: true}, |
| 2024 | }, |
| 2025 | } |
| 2026 | |
| 2027 | _ = cmd.Run(buildTestContext(t), []string{"command"}) |
| 2028 | r.Contains(errBuf.String(), "Incorrect Usage") |
| 2029 | r.Contains(buf.String(), "NAME:") |
| 2030 | r.Contains(buf.String(), "command") |
| 2031 | }) |
| 2032 | |
| 2033 | t.Run("subcommand missing required flag", func(t *testing.T) { |
| 2034 | r := require.New(t) |
| 2035 | var buf bytes.Buffer |
| 2036 | var errBuf bytes.Buffer |
| 2037 | |
| 2038 | cmd := &Command{ |
| 2039 | Writer: &buf, |
| 2040 | ErrWriter: &errBuf, |
| 2041 | Commands: []*Command{ |
| 2042 | { |
| 2043 | Name: "sub", |
| 2044 | Flags: []Flag{ |
| 2045 | &StringFlag{Name: "requiredFlag", Required: true}, |
| 2046 | }, |
| 2047 | Action: func(ctx context.Context, cmd *Command) error { |
| 2048 | return nil |
| 2049 | }, |
| 2050 | }, |
| 2051 | }, |
| 2052 | } |
| 2053 | |
| 2054 | _ = cmd.Run(buildTestContext(t), []string{"command", "sub"}) |
| 2055 | r.Contains(errBuf.String(), "Incorrect Usage") |
| 2056 | r.Contains(buf.String(), "NAME:") |
| 2057 | r.Contains(buf.String(), "sub") |
| 2058 | }) |
| 2059 | } |
| 2060 | |
| 2061 | func TestCommand_IncorrectUsageOnMutuallyExclusiveFlagsViaRun(t *testing.T) { |
| 2062 | t.Run("root command with mutex violation", func(t *testing.T) { |
nothing calls this directly
no test coverage detected