comparison scripts/testfun/assert.m @ 18438:7994d3ce6e8e stable

assert.m: Fix regression and accept more than 3 arguments for certain cases (bug #41332). * assert.m: Accept more than 3 arguments when one of the arguments is a format string for error() and the extra arguments are passed on. Add %!tests to verify this works.
author Rik <rik@octave.org>
date Fri, 24 Jan 2014 10:14:57 -0800
parents 6a381b9ae055
children fcd87f68af4f 9472e3c8f43e
comparison
equal deleted inserted replaced
18437:4b32677b6229 18438:7994d3ce6e8e
54 ## @seealso{test, fail, error} 54 ## @seealso{test, fail, error}
55 ## @end deftypefn 55 ## @end deftypefn
56 56
57 function assert (cond, varargin) 57 function assert (cond, varargin)
58 58
59 if (nargin == 0 || nargin > 3) 59 if (nargin == 0)
60 print_usage (); 60 print_usage ();
61 endif 61 endif
62 62
63 persistent call_depth = -1; 63 persistent call_depth = -1;
64 persistent errmsg; 64 persistent errmsg;
82 endif 82 endif
83 else 83 else
84 expected = varargin{1}; 84 expected = varargin{1};
85 if (nargin < 3) 85 if (nargin < 3)
86 tol = 0; 86 tol = 0;
87 elseif (nargin == 3)
88 tol = varargin{2};
87 else 89 else
88 tol = varargin{2}; 90 print_usage ();
89 endif 91 endif
90 92
91 ## Add to list as the errors accumulate. If empty at end then no errors. 93 ## Add to list as the errors accumulate. If empty at end then no errors.
92 err.index = {}; 94 err.index = {};
93 err.observed = {}; 95 err.observed = {};
394 %!assert (ones (1,3)) 396 %!assert (ones (1,3))
395 %!assert (ones (3,4)) 397 %!assert (ones (3,4))
396 %!error assert ([1,0,1]) 398 %!error assert ([1,0,1])
397 %!error assert ([1;1;0]) 399 %!error assert ([1;1;0])
398 %!error assert ([1,0;1,1]) 400 %!error assert ([1,0;1,1])
401 %!error <2-part error> assert (false, "%s %s", "2-part", "error")
402 %!error <2-part error> assert (false, "TST:msg_id", "%s %s", "2-part", "error")
399 403
400 ## scalars 404 ## scalars
401 %!error <Dimensions don't match> assert (3, [3,3]) 405 %!error <Dimensions don't match> assert (3, [3,3])
402 %!error <Dimensions don't match> assert (3, [3,3; 3,3]) 406 %!error <Dimensions don't match> assert (3, [3,3; 3,3])
403 %!error <Dimensions don't match> assert ([3,3; 3,3], 3) 407 %!error <Dimensions don't match> assert ([3,3; 3,3], 3)