diff scripts/miscellaneous/methods.m @ 26974:aa50801747a9

methods.m: Add input validation and BIST tests for option argument (bug #55858). * methods.m: Validate that option input is "-full" if it exists. Re-organize BIST tests. Add input validation BIST tests.
author Rik <rik@octave.org>
date Mon, 25 Mar 2019 13:59:41 -0700
parents 0ffbc690b493
children b442ec6dda5c
line wrap: on
line diff
--- a/scripts/miscellaneous/methods.m	Sun Mar 24 15:19:56 2019 -0400
+++ b/scripts/miscellaneous/methods.m	Mon Mar 25 13:59:41 2019 -0700
@@ -43,8 +43,14 @@
     print_usage ();
   endif
 
-  showsigs = (nargin > 1 && ischar (opt) && strcmp (opt, "-full"));
   havesigs = false;
+  showsigs = false;
+  if (nargin == 2)
+    if (! strcmp (opt, "-full"))
+      error ("methods: invalid option");
+    endif
+    showsigs = true;
+  endif
 
   if (isobject (obj))
     ## Call internal C++ function for Octave objects
@@ -102,31 +108,37 @@
 endfunction
 
 
-## test Octave classname
+## test old-style @classname
 %!test
 %! mtds = methods ("ftp");
 %! assert (mtds{1}, "ascii");
 
 ## test Java classname
 %!testif HAVE_JAVA; usejava ("jvm")
-%! mtds = methods ("java.lang.Double", "-full");
-%! search = strfind (mtds, "java.lang.Double valueOf");
-%! assert (! isempty ([search{:}]));
-
-## test Java classname
-%!testif HAVE_JAVA; usejava ("jvm")
 %! mtds = methods ("java.lang.Double");
 %! search = strfind (mtds, "valueOf");
 %! assert (! isempty ([search{:}]));
 
-## Test that methods does the right thing when passed a String object
+## test Java classname with -full prototypes
+%!testif HAVE_JAVA; usejava ("jvm")
+%! mtds = methods ("java.lang.Double", "-full");
+%! search = strfind (mtds, "java.lang.Double valueOf");
+%! assert (! isempty ([search{:}]));
+
+## test that methods does the right thing when passed a String object
 %!testif HAVE_JAVA; usejava ("jvm") <*48758>
 %! object = javaObject ("java.lang.String", "java.lang.Integer");
-%! assert (methods (object), methods ("java.lang.String"))
+%! assert (methods (object), methods ("java.lang.String"));
 
-## classdef
+## test classdef classname
 %!assert (methods ("inputParser"),
 %!        {"addOptional"; "addParamValue"; "addParameter";
 %!         "addRequired"; "addSwitch"; "add_missing"; "delete";
 %!         "disp"; "error"; "is_argname"; "parse"; "validate_arg";
 %!         "validate_name"});
+
+## Test input validation
+%!error methods ()
+%!error methods ("a", "b", "c")
+%!error <invalid option> methods ("ftp", "option1")
+%!error <invalid input argument> methods (1)