changeset 17253:e3870f594d8b

assert.m: Fix recursive calls. * scripts/testfun/assert.m: Initialize call_depth to -1 and always increment call_depth at start of function and decrement call_depth at end of function. Properly indent err.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Wed, 14 Aug 2013 16:45:50 -0500
parents dac81d4b8ce1
children 7fb4461997aa
files scripts/testfun/assert.m
diffstat 1 files changed, 11 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/testfun/assert.m	Wed Aug 14 12:05:51 2013 -0700
+++ b/scripts/testfun/assert.m	Wed Aug 14 16:45:50 2013 -0500
@@ -60,13 +60,12 @@
     print_usage ();
   endif
 
-  persistent call_depth = 0;
+  persistent call_depth = -1;
   persistent errmsg;
 
-  if (call_depth > 0)
-    call_depth++;
-  else
-    call_depth = 0;
+  call_depth++;
+
+  if (call_depth == 0)
     errmsg = "";
   end
 
@@ -133,10 +132,10 @@
             assert (cond{i}, expected{i}, tol);
           endfor
         catch
-        err.index{end+1} = "{}";
-        err.observed{end+1} = "O";
-        err.expected{end+1} = "E";
-        err.reason{end+1} = "Cell configuration error";
+          err.index{end+1} = "{}";
+          err.observed{end+1} = "O";
+          err.expected{end+1} = "E";
+          err.reason{end+1} = "Cell configuration error";
         end_try_catch
       endif
 
@@ -355,13 +354,13 @@
 
   endif
 
-  if (call_depth == 0)
+  call_depth--;
+
+  if (call_depth == -1)
     ## Last time through.  If there were any errors on any pass, raise a flag.
     if (! isempty (errmsg))
       error (errmsg);
     endif
-  else
-    call_depth--;
   endif
 
 endfunction