Skip to content

Commit b732158

Browse files
committed
new test for out.Handle
removing no need panic call: fix if test asserter isn't given, we use TestFull to get call stack
1 parent 76832c3 commit b732158

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

assert/assert.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ func PushTester(t testing.TB, a ...defInd) function {
9999
} else if Default()&AsserterUnitTesting == 0 {
100100
// if this is forgotten or tests don't have proper place to set it
101101
// it's good to keep the API as simple as possible
102-
SetDefault(Test)
103-
// TODO: parallel testing is something we should test.
102+
SetDefault(TestFull)
104103
}
105104
testers.Tx(func(m testersMap) {
106105
rid := goid()

try/out.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func (o *Result) Handle(a ...any) *Result {
112112
o.Err = fmt.Errorf(f+wrapStr(), append(a[1:], o.Err)...)
113113
case ErrFn:
114114
o.Err = f(o.Err)
115-
panic(o.Err)
116115
case error:
117116
if len(a) == 2 {
118117
hfn, haveHandlerFn := a[1].(ErrFn)

try/out_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ func TestResult2_Logf(t *testing.T) {
107107
test.RequireEqual(t, num2, 2)
108108
}
109109

110+
func TestResult_Handle(t *testing.T) {
111+
// try out f() |err| handle to show how to stop propagate error
112+
callFn := func(mode int) (err error) {
113+
defer err2.Handle(&err)
114+
115+
try.Out(fmt.Errorf("test error")).Handle(func(err error) error {
116+
if mode == 0 {
117+
return err
118+
}
119+
return nil // no error to throw
120+
})
121+
return nil
122+
}
123+
err := callFn(1)
124+
test.Requiref(t, err == nil, "no error when Out.Handle sets it nil")
125+
126+
err = callFn(0)
127+
test.Requiref(t, err != nil, "want error when Out.Handle sets it the same")
128+
}
129+
110130
func ExampleResult1_Handle() {
111131
// try out f() |err| handle to show power of error handling language, EHL
112132
callRead := func(in io.Reader, b []byte) (eof bool, n int) {

0 commit comments

Comments
 (0)