-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_test.go
42 lines (37 loc) · 951 Bytes
/
stack_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
// Copyright (c) 2020, Roel Schut. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package errors
import (
stderrors "errors"
"fmt"
"testing"
"github.com/go-pogo/errors/internal"
"github.com/stretchr/testify/assert"
)
func TestWithStack(t *testing.T) {
t.Run("with nil", func(t *testing.T) {
assert.Nil(t, WithStack(nil))
})
t.Run("with Msg", func(t *testing.T) {
assert.PanicsWithValue(t, panicUseNewInstead, func() {
_ = WithStack(Msg("panic!"))
})
})
t.Run("with std error", func(t *testing.T) {
err := stderrors.New("some err")
have := WithStack(err)
assert.ErrorIs(t, have, err)
if !internal.TraceStack {
return
}
if !assert.Len(t, have.StackTrace().Frames(), 1) {
fmt.Printf("\n%+v\n", have)
}
})
t.Run("with error", func(t *testing.T) {
err := New("some err")
have := WithStack(err)
assert.Same(t, err, have)
})
}