changeset 20759:2892f62fb37c

inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992). * inputname.m: Use try/catch block around evalin() in case it fails. Add more BIST tests.
author Rik <rik@octave.org>
date Wed, 25 Nov 2015 15:45:46 -0800
parents b4f5962b3373
children 15eefcabcb31
files scripts/miscellaneous/inputname.m
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/inputname.m	Wed Nov 25 15:28:46 2015 -0500
+++ b/scripts/miscellaneous/inputname.m	Wed Nov 25 15:45:46 2015 -0800
@@ -35,7 +35,13 @@
     print_usage ();
   endif
 
-  s = evalin ("caller", sprintf ("__varval__ (\".argn.\"){%d};", fix (n)));
+  s = "";
+  try
+    s = evalin ("caller", sprintf ("__varval__ ('.argn.'){%d}", fix (n)));
+  catch
+    return;
+  end_try_catch
+
   ## For compatibility with Matlab,
   ## return empty string if argument name is not a valid identifier.
   if (! isvarname (s))
@@ -46,20 +52,27 @@
 
 
 ## Warning: heap big magic in the following tests!!!
-## The test function builds a private context for each
-## test, with only the specified values shared between
-## them.  It does this using the following template:
+## The test function builds a private context for each test, with only the
+## specified values shared between them.  It does this using the following
+## template:
 ##
-##     function [<shared>] = testfn(<shared>)
+##     function [<shared>] = testfn (<shared>)
 ##        <test>
+##     endfunction
 ##
-## To test inputname, I need a function context invoked
-## with known parameter names.  So define a couple of
-## shared parameters, et voila!, the test is trivial.
+## To test inputname, I need a function context invoked with known parameter
+## names.  So define a couple of shared parameters, et voila!, the test is
+## trivial.
 
 %!shared hello, worldly
 %!assert (inputname (1), "hello")
 %!assert (inputname (2), "worldly")
+%!assert (inputname (3), "")
+
+## Clear parameter list so that testfn is created with zero inputs/outputs
+%!shared  
+%!assert (inputname (-1), "")
+%!assert (inputname (1), "")
 
 %!function r = __foo__ (x, y)
 %!  r = inputname (2);