Mercurial > hgweb > octave
changeset 32240:d1bbd7a0982c
optimget.m,optimset.m: Emit an error when short name matches multiple properties (bug #64525)
* optimget.m, optimset.m: Replace call to warning() with call to error() if
short name is ambiguous and matches multiple possible properties. Use single
quotes around short name in error messages to make it stand out. Adjust
BIST tests for new behavior
| author | Rik <rik@octave.org> |
|---|---|
| date | Mon, 07 Aug 2023 11:16:51 -0700 |
| parents | 10db16bf2440 |
| children | 4379d4e29943 1ce1c922a34b |
| files | scripts/optimization/optimget.m scripts/optimization/optimset.m |
| diffstat | 2 files changed, 10 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/optimization/optimget.m +++ b/scripts/optimization/optimget.m @@ -48,11 +48,11 @@ if (nmatch == 1) optname = opts{idx}; elseif (nmatch == 0) - warning ("optimget: unrecognized option: %s", optname); + warning ("optimget: unrecognized option: '%s'", optname); else - fmt = sprintf ("optimget: ambiguous option: %%s (%s%%s)", + fmt = sprintf ("optimget: ambiguous option: '%%s' (%s%%s)", repmat ("%s, ", 1, nmatch-1)); - warning (fmt, optname, opts{idx}); + error (fmt, optname, opts{idx}); endif if (isfield (options, optname) && ! isempty (options.(optname))) @@ -79,5 +79,5 @@ %!error <Invalid call> optimget (1) %!error optimget (1, "name") %!error optimget (struct (), 2) -%!warning <unrecognized option: foobar> (optimget (opts, "foobar")); -%!warning <ambiguous option: Max> (optimget (opts, "Max")); +%!warning <unrecognized option: 'foobar'> (optimget (opts, "foobar")); +%!error <ambiguous option: 'Max'> (optimget (opts, "Max"));
--- a/scripts/optimization/optimset.m +++ b/scripts/optimization/optimset.m @@ -184,11 +184,11 @@ if (nmatch == 1) key = opts{find (i)}; elseif (nmatch == 0) - warning ("optimset: unrecognized option: %s", key); + warning ("optimset: unrecognized option: '%s'", key); else - fmt = sprintf ("optimset: ambiguous option: %%s (%s%%s)", + fmt = sprintf ("optimset: ambiguous option: '%%s' (%s%%s)", repmat ("%s, ", 1, nmatch-1)); - warning (fmt, key, opts{i}); + error (fmt, key, opts{i}); endif endif if (useempty || ! isempty (val)) @@ -220,5 +220,5 @@ ## Test input validation %!error optimset ("1_Parameter") %!error <no defaults for function> optimset ("%NOT_A_REAL_FUNCTION_NAME%") -%!warning <unrecognized option: foobar> optimset ("foobar", 13); -%!warning <ambiguous option: Max> optimset ("Max", 10); +%!warning <unrecognized option: 'foobar'> optimset ("foobar", 13); +%!error <ambiguous option: 'Max'> optimset ("Max", 10);
