test(cli): pin ExitCode mapping (usage=2, runtime=1, nil=0)

Closes the one nit from the regression audit: the exit-code wiring was correct
and covered end-to-end by the smoke test, but not pinned by a unit test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
itrytoohard 2026-06-01 02:38:25 +05:30
parent a9e83011f1
commit e6661e3f3b
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package cli
import (
"errors"
"fmt"
"testing"
)
func TestExitCode(t *testing.T) {
cases := []struct {
name string
err error
want int
}{
{"nil is success", nil, 0},
{"runtime error is 1", errors.New("boom"), 1},
{"usage error is 2", usageError{errors.New("bad flag")}, 2},
{"wrapped usage error is still 2", fmt.Errorf("ctx: %w", usageError{errors.New("x")}), 2},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := ExitCode(tc.err); got != tc.want {
t.Errorf("ExitCode(%v) = %d, want %d", tc.err, got, tc.want)
}
})
}
}