changeset 25108:7561fb4ab972 stable

pr-output.cc: Fix BIST tests so that display format is saved & restored. * pr-output.cc (Fdisp): Use unwind_protect block to save/restore the display format and spacing when conducting BIST tests.
author Rik <rik@octave.org>
date Tue, 03 Apr 2018 22:20:20 -0700
parents 13cd142c3f88
children 68039183fac4 d890fdd23c95
files libinterp/corefcn/pr-output.cc
diffstat 1 files changed, 33 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Tue Apr 03 22:12:05 2018 -0700
+++ b/libinterp/corefcn/pr-output.cc	Tue Apr 03 22:20:20 2018 -0700
@@ -3377,30 +3377,43 @@
 }
 
 /*
+## FIXME: This test writes values to a file, but then never checks them.
 %!test
-%! format short
-%! fd = tmpfile ();
-%! for r = [0, Inf -Inf, NaN]
-%!   for i = [0, Inf -Inf, NaN]
-%!     fdisp (fd, complex (r, i));
+%! [old_fmt, old_spacing] = format ();
+%! unwind_protect
+%!   format short
+%!   fd = tmpfile ();
+%!   for r = [0, Inf -Inf, NaN]
+%!     for i = [0, Inf -Inf, NaN]
+%!       fdisp (fd, complex (r, i));
+%!     endfor
 %!   endfor
-%! endfor
-%! fclose (fd);
+%!   fclose (fd);
+%! unwind_protect_cleanup
+%!   format (old_fmt);
+%!   format (old_spacing);
+%! end_unwind_protect
 
 %!test
-%! foo.real = pi * ones (3,20,3);
-%! foo.complex = pi * ones (3,20,3) + 1i;
-%! foo.char = repmat ("- Hello World -", [3, 20]);
-%! foo.cell = {foo.real, foo.complex, foo.char};
-%! fields = fieldnames (foo);
-%! for f = 1:numel (fields)
-%!   format loose;
-%!   loose = disp (foo.(fields{f}));
-%!   format compact;
-%!   compact = disp (foo.(fields{f}));
-%!   expected = strrep (loose, "\n\n", "\n");
-%!   assert (expected, compact);
-%! endfor
+%! [old_fmt, old_spacing] = format ();
+%! unwind_protect
+%!   foo.real = pi * ones (3,20,3);
+%!   foo.complex = pi * ones (3,20,3) + 1i;
+%!   foo.char = repmat ("- Hello World -", [3, 20]);
+%!   foo.cell = {foo.real, foo.complex, foo.char};
+%!   fields = fieldnames (foo);
+%!   for f = 1:numel (fields)
+%!     format loose;
+%!     loose = disp (foo.(fields{f}));
+%!     format compact;
+%!     compact = disp (foo.(fields{f}));
+%!     expected = strrep (loose, "\n\n", "\n");
+%!     assert (expected, compact);
+%!   endfor
+%! unwind_protect_cleanup
+%!   format (old_fmt);
+%!   format (old_spacing);
+%! end_unwind_protect
 */
 
 DEFUN (display, args, ,