changeset 20786:a61f0d6beb71

inputParser: do not perform validation of default values (bug #45837)
author Carnë Draug <carandraug@octave.org>
date Thu, 08 Oct 2015 20:15:19 +0100
parents 780431fc4137
children 40ed9b46a800
files scripts/general/inputParser.m
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/inputParser.m
+++ b/scripts/general/inputParser.m
@@ -303,7 +303,6 @@
                 "after ParamValue or Switch"]);
       endif
       this.validate_name ("Optional", name);
-      this.validate_default ("Optional", name, def, val);
       this.Optional{end+1} = struct ("name", name, "def", def, "val", val);
     endfunction
 
@@ -312,7 +311,6 @@
         print_usage ();
       endif
       this.validate_name ("ParamValue", name);
-      this.validate_default ("ParamValue", name, def, val);
       this.ParamValue.(name).def = def;
       this.ParamValue.(name).val = val;
     endfunction
@@ -435,13 +433,6 @@
       this.Parameters{end+1} = name;
     endfunction
 
-    function validate_default (this, type, name, def, val)
-      if (! feval (val, def))
-        error ("inputParser.add%s: failed validation for '%s' default value",
-               type, name);
-      endif
-    endfunction
-
     function validate_arg (this, name, val, in)
         if (! val (in))
           this.error (sprintf ("failed validation of %s", toupper (name)));
@@ -582,6 +573,19 @@
 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line},
 %!         {"file", "foo", 80,    true,      "circle"});
 
+## We must not perform validation of default values (bug #45837)
+%!test
+%! p = inputParser;
+%! p.addParamValue ("Dir", [], @ischar);
+%! p.parse ();
+%! assert (p.Results.Dir, [])
+
+%!test
+%! p = inputParser;
+%! p.addParamValue ("positive", -1, @(x) x > 5);
+%! p.parse ();
+%! assert (p.Results.positive, -1)
+
 ## FIXME: This somehow works in Matlab
 #%!test
 #%! p = inputParser;