Mercurial > octave
changeset 31075:bcadacfac44f
maint: Merge stable to default.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 06 Jun 2022 14:28:06 +0200 |
parents | 396f60e0b984 (current diff) 2c8ab613e805 (diff) |
children | f0343b3685df |
files | |
diffstat | 1 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/inputParser.m Sun Jun 05 18:11:28 2022 -0400 +++ b/scripts/miscellaneous/inputParser.m Mon Jun 06 14:28:06 2022 +0200 @@ -543,9 +543,29 @@ function validate_arg (this, name, val, in) - if (! val (in)) - this.error (sprintf ("failed validation of %s with %s", - toupper (name), func2str (val))); + ## Checking "nargout (val)" doesn't work for builtin functions. + ## So, we need to use this nested try-catch construct. + err = sprintf ('Checked with "%s"', func2str (val)); + try + ok = val (in); + catch exception + if (strcmp (exception.identifier, "Octave:invalid-fun-call")) + ## check if function also fails when called without output argument + try + val (in); + ok = true; + catch exception + ok = false; + err = exception.message; + end_try_catch + else + ok = false; + err = exception.message; + endif + end_try_catch + if (! ok) + this.error (sprintf ("failed validation of %s. %s", + toupper (name), err)); endif this.Results.(name) = in; @@ -859,7 +879,7 @@ %! assert (p.Unmatched, struct ()); ## Test for patch #9241 -%!error <failed validation of A with ischar> +%!error <failed validation of A.*ischar> %! p = inputParser (); %! p.addParameter ("a", [], @ischar); %! p.parse ("a", 1);