-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
54 lines (42 loc) · 1.39 KB
/
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
46
47
48
49
50
51
52
53
54
package cli
import (
"errors"
"testing"
"gotest.tools/v3/assert"
)
func Test_ErrorWithHelp(t *testing.T) {
t.Run("non nil error", func(t *testing.T) {
rootErr := errors.New("boom")
helpErr := NewErrorWithHelp(rootErr)
assert.Check(t, rootErr.Error() == helpErr.Error())
assert.ErrorIs(t, helpErr, rootErr)
showHelpErr := new(ShowHelpError)
assert.Assert(t, errors.As(helpErr, showHelpErr))
assert.Check(t, (*showHelpErr).ShowHelp())
})
t.Run("nil error", func(t *testing.T) {
helpErr := NewErrorWithHelp(nil)
assert.Check(t, helpErr.Error() == "")
showHelpErr := new(ShowHelpError)
assert.Assert(t, errors.As(helpErr, showHelpErr))
assert.Check(t, (*showHelpErr).ShowHelp())
})
}
func Test_ErrorWithExitStatus(t *testing.T) {
t.Run("non nil error", func(t *testing.T) {
rootErr := errors.New("boom")
helpErr := NewErrorWithExitStatus(rootErr, 42)
assert.Check(t, rootErr.Error() == helpErr.Error())
assert.ErrorIs(t, helpErr, rootErr)
showHelpErr := new(ExitStatusError)
assert.Assert(t, errors.As(helpErr, showHelpErr))
assert.Check(t, (*showHelpErr).ExitStatus() == uint8(42))
})
t.Run("nil error", func(t *testing.T) {
helpErr := NewErrorWithExitStatus(nil, 42)
assert.Check(t, helpErr.Error() == "")
showHelpErr := new(ExitStatusError)
assert.Assert(t, errors.As(helpErr, showHelpErr))
assert.Check(t, (*showHelpErr).ExitStatus() == uint8(42))
})
}