gogcli/internal/cmd/exit_test.go
Peter Steinberger c1ebd60210 test: expand coverage and tracking regressions (#35)
Thanks @salmonumbrella.

Co-authored-by: salmonumbrella <salmonumbrella@users.noreply.github.com>
2026-01-09 04:21:16 +01:00

32 lines
635 B
Go

package cmd
import (
"errors"
"testing"
)
func TestExitError(t *testing.T) {
err := &ExitError{Code: 2, Err: errors.New("boom")}
if err.Error() != "boom" {
t.Fatalf("unexpected error: %q", err.Error())
}
if !errors.Is(err, err.Err) {
t.Fatalf("expected unwrap")
}
}
func TestExitCode(t *testing.T) {
if ExitCode(nil) != 0 {
t.Fatalf("expected 0")
}
if ExitCode(errors.New("x")) != 1 {
t.Fatalf("expected 1")
}
if ExitCode(&ExitError{Code: -1, Err: errors.New("x")}) != 1 {
t.Fatalf("expected 1 for negative code")
}
if ExitCode(&ExitError{Code: 5, Err: errors.New("x")}) != 5 {
t.Fatalf("expected 5")
}
}