changeset 31960:3df2579631b5

assert.m: Fix character matrix equality (bug #63988) * assert.m: Reshape 'cond' and 'expected' character arrays to row vectors before adding single quotes around them for display in error messages. Add BIST test for bug #63988.
author Rik <rik@octave.org>
date Sat, 01 Apr 2023 20:14:17 -0700
parents 90f21a2c471f
children 476c84c4f201
files scripts/testfun/assert.m
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/testfun/assert.m	Sat Apr 01 15:58:29 2023 -0400
+++ b/scripts/testfun/assert.m	Sat Apr 01 20:14:17 2023 -0700
@@ -138,10 +138,8 @@
           endif
         elseif (! strcmp (cond, expected))
           err.index{end+1} = "[]";
-          rr = repmat ("'", rows (cond), 1);
-          err.observed{end+1} = [rr cond rr];
-          rr = repmat ("'", rows (expected), 1);
-          err.expected{end+1} = [rr expected rr];
+          err.observed{end+1} = ["'" cond(:).' "'"];
+          err.expected{end+1} = ["'" expected(:).' "'"];
           err.reason{end+1} = "Strings don't match";
         endif
 
@@ -747,6 +745,18 @@
 %!   assert (isempty (strfind (errmsg, "sprintf: invalid field width")));
 %! end_try_catch
 
+%!test <*63988>
+%! A = ["ab"; "cd"];
+%! B = ["ad"; "cb"];
+%! try
+%!   assert (A, B);
+%! catch
+%!   errmsg = lasterr ();
+%!   if (regexp (errmsg, 'horizontal dimensions mismatch'))
+%!     error ("assert failed for char arrays with multiple rows");
+%!   endif
+%! end_try_catch
+
 ## test input validation
 %!error <Invalid call> assert ()
 %!error <Invalid call> assert (1,2,3,4)