예제 #1
0
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,
		)
	}

}
예제 #2
0
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)
		}
	}
}
예제 #3
0
파일: error.go 프로젝트: andradeandrey/fwk
// Error returns the original error with the associated stack trace.
func Error(err error) error {
	return errstack.New(err)
}
예제 #4
0
// adds another stack-frame
func newerr(err error) error {
	return errstack.New(err)
}
예제 #5
0
func TestNewNil(t *testing.T) {
	err := errstack.New(nil)
	if err != nil {
		t.Fatalf("expected a nil error. got=%#v\n", err)
	}
}