changeset 12881:49553ea11764

Return 0x1 empty struct when nargchk, nargoutcheck passes for ML compatability (bug #33808) * nargchck.m, nargoutchk.m: Return 0x1 empty struct when tests pass.
author Rik <octave@nomad.inbox5.com>
date Mon, 25 Jul 2011 10:18:48 -0700
parents ff264eae88cf
children 6e2971841d67
files scripts/general/nargchk.m scripts/general/nargoutchk.m
diffstat 2 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/nargchk.m	Sun Jul 24 22:11:26 2011 -0700
+++ b/scripts/general/nargchk.m	Mon Jul 25 10:18:48 2011 -0700
@@ -30,16 +30,14 @@
 
 ## Author: Bill Denney <bill@denney.ws>
 
-function msg = nargchk (minargs, maxargs, nargs, outtype)
+function msg = nargchk (minargs, maxargs, nargs, outtype = "string")
 
   if (nargin < 3 || nargin > 4)
     print_usage ();
   elseif (minargs > maxargs)
     error ("nargchk: MINARGS must be <= MAXARGS");
-  elseif (nargin == 3)
-    outtype = "string";
   elseif (! any (strcmpi (outtype, {"string", "struct"})))
-    error ("nargchk: output type must be either string or struct");
+    error ('nargchk: output type must be either "string" or "struct"');
   elseif (! (isscalar (minargs) && isscalar (maxargs) && isscalar (nargs)))
     error ("nargchk: MINARGS, MAXARGS, and NARGS must be scalars");
   endif
@@ -55,6 +53,9 @@
 
   if (strcmpi (outtype, "string"))
     msg = msg.message;
+  elseif (isempty (msg.message))
+    ## Compatability: Matlab returns a 0x1 empty struct when nargchk passes
+    msg = resize (msg, 0, 1);
   endif
 
 endfunction
@@ -62,8 +63,7 @@
 
 ## Tests
 %!shared stnul, stmin, stmax
-%!  stnul = struct ("message", "",
-%!                  "identifier", "");
+%!  stnul = resize (struct ("message", "", "identifier", ""), 0, 1);
 %!  stmin = struct ("message", "not enough input arguments",
 %!                  "identifier", "Octave:nargchk:not-enough-inputs");
 %!  stmax = struct ("message", "too many input arguments",
@@ -74,7 +74,7 @@
 %!assert (nargchk (0, 1, 2), "too many input arguments")
 %!assert (nargchk (0, 1, 2, "string"), "too many input arguments")
 ## Struct outputs
-%!assert (nargchk (0, 1, 0, "struct"), stnul)
-%!assert (nargchk (0, 1, 1, "struct"), stnul)
+%!assert (isequal (nargchk (0, 1, 0, "struct"), stnul))
+%!assert (isequal (nargchk (0, 1, 1, "struct"), stnul))
 %!assert (nargchk (1, 1, 0, "struct"), stmin)
 %!assert (nargchk (0, 1, 2, "struct"), stmax)
--- a/scripts/general/nargoutchk.m	Sun Jul 24 22:11:26 2011 -0700
+++ b/scripts/general/nargoutchk.m	Mon Jul 25 10:18:48 2011 -0700
@@ -55,6 +55,9 @@
 
   if (strcmpi (outtype, "string"))
     msg = msg.message;
+  elseif (isempty (msg.message))
+    ## Compatability: Matlab returns a 0x1 empty struct when nargchk passes
+    msg = resize (msg, 0, 1);
   endif
 
 endfunction
@@ -62,8 +65,7 @@
 
 ## Tests
 %!shared stnul, stmin, stmax
-%!  stnul = struct ("message", "",
-%!                  "identifier", "");
+%!  stnul = resize (struct ("message", "", "identifier", ""), 0, 1);
 %!  stmin = struct ("message", "not enough output arguments",
 %!                  "identifier", "Octave:nargoutchk:not-enough-outputs");
 %!  stmax = struct ("message", "too many output arguments",
@@ -74,8 +76,8 @@
 %!assert (nargoutchk (0, 1, 2), "too many output arguments")
 %!assert (nargoutchk (0, 1, 2, "string"), "too many output arguments")
 ## Struct outputs
-%!assert (nargoutchk (0, 1, 0, "struct"), stnul)
-%!assert (nargoutchk (0, 1, 1, "struct"), stnul)
+%!assert (isequal (nargoutchk (0, 1, 0, "struct"), stnul))
+%!assert (isequal (nargoutchk (0, 1, 1, "struct"), stnul))
 %!assert (nargoutchk (1, 1, 0, "struct"), stmin)
 %!assert (nargoutchk (0, 1, 2, "struct"), stmax)