Skip to content

Commit

Permalink
Adding unit test for suggested command names
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Dec 7, 2024
1 parent 239fddc commit 93a66d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ func TestSuggestions(t *testing.T) {
exp string
}{
{
ss("subfoo"), `error: unknown command "subfoo" for "cmd"`,
ss(`subfoo`), `error: unknown command "subfoo" for "cmd"`,
},
{
ss("on"), `error: unknown command "on" for "cmd"
ss(`on`), `error: unknown command "on" for "cmd"
Did you mean this?
one
`,
},
{
ss(`remove`), `error: unknown command "remove" for "cmd"
Did you mean this?
one
Expand All @@ -27,9 +34,6 @@ Did you mean this?
t.Run(strconv.Itoa(i), func(t *testing.T) {
var code int
c := testContext(t, &code, test.args...)
if err := c.Parse(); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
err := c.Run(context.Background())
if err == nil {
t.Fatalf("expected non-nil error")
Expand Down Expand Up @@ -116,5 +120,8 @@ func testContext(t *testing.T, code *int, args ...string) *Context {
Vars: make(Vars),
}
c.Handler = DefaultErrorHandler(c)
if err := c.Parse(); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
return c
}
1 change: 1 addition & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func testCommand(t *testing.T) *Command {
Exec(testDump(t, "four")),
Usage("four", ""),
),
Suggested("remove"),
),
Sub(
Exec(testDump(t, "five")),
Expand Down

0 comments on commit 93a66d9

Please sign in to comment.