-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
45 lines (36 loc) · 935 Bytes
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cmdy
import (
"errors"
"fmt"
"testing"
"github.com/ArtProcessors/cmdy/internal/assert"
)
func TestFormatErrorQuiet(t *testing.T) {
tt := assert.WrapTB(t)
msg, code := FormatError(QuietExit(0))
tt.MustEqual("", msg)
tt.MustEqual(0, code)
msg, code = FormatError(QuietExit(1))
tt.MustEqual("", msg)
tt.MustEqual(1, code)
}
func TestFormatError(t *testing.T) {
tt := assert.WrapTB(t)
err := ErrWithCode(3, errors.New("boom"))
msg, code := FormatError(err)
tt.MustEqual("boom", msg)
tt.MustEqual(3, code)
}
func TestFormatErrorWithWrappedUsageError(t *testing.T) {
tt := assert.WrapTB(t)
err := UsageError(ErrWithCode(3, errors.New("boom")))
msg, code := FormatError(err)
tt.MustEqual("error: boom", msg)
tt.MustEqual(ExitUsage, code)
}
func TestUsageErrorCanUnwrap(t *testing.T) {
tt := assert.WrapTB(t)
err := fmt.Errorf("YEPPO")
uerr := UsageError(err)
tt.MustEqual(err, errors.Unwrap(uerr))
}