Commit 7f72b67b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent bf472763
...@@ -16,7 +16,6 @@ package main ...@@ -16,7 +16,6 @@ package main
import ( import (
"fmt" "fmt"
"strings" "strings"
// "reflect"
) )
// error type which is raised by raise(arg) // error type which is raised by raise(arg)
...@@ -46,9 +45,11 @@ func raisef(format string, a ...interface{}) { ...@@ -46,9 +45,11 @@ func raisef(format string, a ...interface{}) {
} }
// raise if err != nil && err.value != nil // raise if err != nil
// XXX ^^^^^^^^^^^^^^^^^^^ do we need this? // NOTE err can be != nil even if typed obj = nil:
// NOTE err can be != nil even if typed obj = nil (var obj *T; err = obj -> err != nil is true) // var obj *T;
// err = obj
// err != nil is true
func raiseif(err error) { func raiseif(err error) {
//if err != nil && !reflect.ValueOf(err).IsNil() { //if err != nil && !reflect.ValueOf(err).IsNil() {
if err != nil { if err != nil {
......
...@@ -30,12 +30,6 @@ func TestErrRaiseCatch(t *testing.T) { ...@@ -30,12 +30,6 @@ func TestErrRaiseCatch(t *testing.T) {
t.Fatal("error not caught") t.Fatal("error not caught")
} }
func do_onunwind() {
defer erronunwind(func (e *Error) *Error {
return &Error{2, e}
})
do_raise1()
}
// verify err chain has .arg(s) as expected // verify err chain has .arg(s) as expected
func verifyErrChain(t *testing.T, e *Error, argv ...interface{}) { func verifyErrChain(t *testing.T, e *Error, argv ...interface{}) {
...@@ -53,15 +47,39 @@ func verifyErrChain(t *testing.T, e *Error, argv ...interface{}) { ...@@ -53,15 +47,39 @@ func verifyErrChain(t *testing.T, e *Error, argv ...interface{}) {
} }
} }
func do_onunwind1(t *testing.T) {
defer erronunwind(func (e *Error) *Error {
t.Fatal("on unwind called without raise")
return nil
})
}
func do_onunwind2() {
defer erronunwind(func (e *Error) *Error {
return &Error{2, e}
})
do_raise1()
}
func TestErrOnUnwind(t *testing.T) { func TestErrOnUnwind(t *testing.T) {
defer errcatch(func (e *Error) { defer errcatch(func (e *Error) {
verifyErrChain(t, e, 2, 1) verifyErrChain(t, e, 2, 1)
}) })
do_onunwind() do_onunwind1(t)
do_onunwind2()
t.Fatal("error not caught") t.Fatal("error not caught")
} }
func do_addcontext() {
func do_addcontext1(t *testing.T) {
defer erraddcontext(func() interface{} {
t.Fatal("on addcontext called without raise")
return nil
})
}
func do_addcontext2() {
defer erraddcontext(func() interface{} { defer erraddcontext(func() interface{} {
return 3 return 3
}) })
...@@ -72,6 +90,7 @@ func TestErrAddContext(t *testing.T) { ...@@ -72,6 +90,7 @@ func TestErrAddContext(t *testing.T) {
defer errcatch(func (e *Error) { defer errcatch(func (e *Error) {
verifyErrChain(t, e, 3, 1) verifyErrChain(t, e, 3, 1)
}) })
do_addcontext() do_addcontext1(t)
do_addcontext2()
t.Fatal("error not caught") t.Fatal("error not caught")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment