# HG changeset patch # User Rik # Date 1522819220 25200 # Node ID 7561fb4ab972e87f645e685aa07f4f0826857d74 # Parent 13cd142c3f887ed73830b52e2f20a1762ff67f28 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. diff -r 13cd142c3f88 -r 7561fb4ab972 libinterp/corefcn/pr-output.cc --- 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, ,