Index: tests/nsf-cmd.test =================================================================== diff -u -ra775d31c0b4770cc7eddc1b4c015bc0dea1fddd2 -re367957430bf9246069791785619a5503e166d33 --- tests/nsf-cmd.test (.../nsf-cmd.test) (revision a775d31c0b4770cc7eddc1b4c015bc0dea1fddd2) +++ tests/nsf-cmd.test (.../nsf-cmd.test) (revision e367957430bf9246069791785619a5503e166d33) @@ -277,7 +277,34 @@ } +# +# test error transparency of "-debug" option +# +nx::test case nsf-debug-error { + nsf::proc foo {} { + set exception [catch {bar} errorMsg options] + if {$exception} { + puts stderr O=$options + puts stderr <<$::errorInfo>> + set result [list $exception $errorMsg [string length $::errorInfo] $::errorCode] + } else { + set result "" + } + return $result + } + nsf::proc bar {} {return -code error -errorcode MyException "exception"} + ? {foo} {1 exception 35 MyException} + + # + # redefine bar with debug flag + # + nsf::proc -debug bar {} {return -code error -errorcode MyException "exception"} + + ? {foo} {1 exception 35 MyException} +} + + # # test virtual arg resolution + filtering # @@ -384,6 +411,83 @@ } # +# recursive debug calls +# +nx::test case nsf-debug-recursive { + set ::count 0 + + set oldCall [nsf::cmd::info definition ::nsf::debug::call] + nsf::proc -debug ::nsf::debug::call args { + incr ::count + #puts "MYDEBUG $args" + } + nsf::proc -debug foo {} {return 1} + + ? {foo} "1" + ? {set ::count} 1 + + # restore original definition of ::nsf::debug::call + eval $oldCall +} + +# +# recursive log calls +# +nx::test case nsf-log-recursive { + + # + # First the case, where the log function calls another Tcl function + # (which might be debugged) + # + set oldCall [nsf::cmd::info definition ::nsf::log] + nsf::proc ::nsf::log args { + incr ::count + #puts "::nsf::log <$args> ... before foo" + foo + #puts "::nsf::log <$args> ... after foo" + return + } + nsf::proc foo {} {return 1} + nsf::proc bar {} {nsf::log notice hello} + + # + # "foo" calls no nsf::log, but "bar" calls it once + # + set ::count 0 + ? {foo} "1" + ? {set ::count} 0 + + set ::count 0 + ? {bar} "" + ? {set ::count} 1 + + # + # now we add the debug flag to foo, therefore "foo" will call + # "nsf::log", which might become a infinite recursion loop. + # + nsf::proc -debug foo {} {return 1} + + # + # "foo" is has now "-debug" set, therefore it calls the log function + # + set ::count 0 + ? {foo} "1" + ? {set ::count} 2 + + # + # "bar" calls "log", which in turn calls a debugged function + # + set ::count 0 + ? {bar} "" + ? {set ::count} 3 + + # restore original definition of ::nsf::log + eval $oldCall + +} + + +# # Local variables: # mode: tcl # tcl-indent-level: 2