func TestNewNoHysteresis(t *testing.T) { exp := fmt.Errorf("my bad %d", 42) err := errstack.New(exp) if err == nil { t.Fatalf("expected a non-nil error. got=%#v\n", err) } errs := err.(*errstack.Error) n := len(errs.Stack) err = newerr(err) if err == nil { t.Fatalf("expected a non-nil error. got=%#v\n", err) } errs = err.(*errstack.Error) if n != len(errs.Stack) { t.Fatalf("hysteresis detected:\nold-stack=%d\nnew-stack=%d\n", n, len(errs.Stack), ) } err = newerr(errs.Err) errs = err.(*errstack.Error) if n == len(errs.Stack) { t.Fatalf("hysteresis error:\nold-stack=%d\nnew-stack=%d\n%v\n", n, len(errs.Stack), errs, ) } }
func TestNew(t *testing.T) { exp := fmt.Errorf("my bad %d", 42) err := errstack.New(exp) if err == nil { t.Fatalf("expected a non-nil error. got=%#v\n", err) } if err, ok := err.(*errstack.Error); !ok { t.Fatalf("expected an *errstack.Error. got=%T\n", err) } else { if !reflect.DeepEqual(err.Err, exp) { t.Fatalf("expected err.Err=%v.\ngot=%v\n", exp, err.Err) } } }
// Error returns the original error with the associated stack trace. func Error(err error) error { return errstack.New(err) }
// adds another stack-frame func newerr(err error) error { return errstack.New(err) }
func TestNewNil(t *testing.T) { err := errstack.New(nil) if err != nil { t.Fatalf("expected a nil error. got=%#v\n", err) } }