# HG changeset patch # User Carnë Draug # Date 1444331719 -3600 # Node ID a61f0d6beb714108b5773efd461a25e51c85ac6f # Parent 780431fc41374622c32df0fc1663be67990077ca inputParser: do not perform validation of default values (bug #45837) diff -r 780431fc4137 -r a61f0d6beb71 scripts/general/inputParser.m --- a/scripts/general/inputParser.m Thu Oct 08 20:06:45 2015 +0100 +++ b/scripts/general/inputParser.m Thu Oct 08 20:15:19 2015 +0100 @@ -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;