* test: Add test coverage for 16 files (40.3% -> 45.5%) Add comprehensive tests for previously untested packages: - internal/agent/state_test.go - internal/cmd/errors_test.go - internal/crew/types_test.go - internal/doctor/errors_test.go - internal/dog/types_test.go - internal/mail/bd_test.go - internal/opencode/plugin_test.go - internal/rig/overlay_test.go - internal/runtime/runtime_test.go - internal/session/town_test.go - internal/style/style_test.go - internal/ui/markdown_test.go - internal/ui/terminal_test.go - internal/wisp/io_test.go - internal/wisp/types_test.go - internal/witness/types_test.go style_test.go uses func(...string) to match lipgloss variadic Render signature. * fix(lint): remove unused error return from buildCVSummary buildCVSummary always returned nil for its error value, causing golangci-lint to fail with "result 1 (error) is always nil". The function handles errors internally by returning partial data, so the error return was misleading. Removed it and updated caller.
94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestSilentExitError_Error(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
code int
|
|
want string
|
|
}{
|
|
{"zero code", 0, "exit 0"},
|
|
{"success code", 1, "exit 1"},
|
|
{"error code", 2, "exit 2"},
|
|
{"custom code", 42, "exit 42"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
e := &SilentExitError{Code: tt.code}
|
|
got := e.Error()
|
|
if got != tt.want {
|
|
t.Errorf("SilentExitError.Error() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewSilentExit(t *testing.T) {
|
|
tests := []struct {
|
|
code int
|
|
}{
|
|
{0},
|
|
{1},
|
|
{2},
|
|
{127},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(fmt.Sprintf("code_%d", tt.code), func(t *testing.T) {
|
|
err := NewSilentExit(tt.code)
|
|
if err == nil {
|
|
t.Fatal("NewSilentExit should return non-nil")
|
|
}
|
|
if err.Code != tt.code {
|
|
t.Errorf("NewSilentExit(%d).Code = %d, want %d", tt.code, err.Code, tt.code)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIsSilentExit(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
err error
|
|
wantCode int
|
|
wantIsSilent bool
|
|
}{
|
|
{"nil error", nil, 0, false},
|
|
{"silent exit code 0", NewSilentExit(0), 0, true},
|
|
{"silent exit code 1", NewSilentExit(1), 1, true},
|
|
{"silent exit code 2", NewSilentExit(2), 2, true},
|
|
{"other error", errors.New("some error"), 0, false},
|
|
// Note: wrapped errors require errors.As fix - see PR #462
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
code, isSilent := IsSilentExit(tt.err)
|
|
if isSilent != tt.wantIsSilent {
|
|
t.Errorf("IsSilentExit(%v) isSilent = %v, want %v", tt.err, isSilent, tt.wantIsSilent)
|
|
}
|
|
if code != tt.wantCode {
|
|
t.Errorf("IsSilentExit(%v) code = %d, want %d", tt.err, code, tt.wantCode)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSilentExitError_Is(t *testing.T) {
|
|
// Test that SilentExitError works with errors.Is
|
|
err := NewSilentExit(1)
|
|
var target *SilentExitError
|
|
if !errors.As(err, &target) {
|
|
t.Error("errors.As should find SilentExitError")
|
|
}
|
|
if target.Code != 1 {
|
|
t.Errorf("errors.As extracted code = %d, want 1", target.Code)
|
|
}
|
|
}
|