changeset 26716:daa281e03d9a

Harden BIST tests against changes in format(). * oct-parse.yy: Save/restore format before running some evalc() tests. * Map.m: Save/restore format and change %!error to %!test with fail(). * pr-output.cc (Frats): Save/restore format before running rats() tests.
author Rik <rik@octave.org>
date Sun, 10 Feb 2019 08:39:30 -0800
parents 24e11ee4fe45
children 87d3baf1c024
files libinterp/corefcn/pr-output.cc libinterp/parse-tree/oct-parse.yy scripts/+containers/Map.m
diffstat 3 files changed, 47 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Sat Feb 09 12:24:26 2019 +0100
+++ b/libinterp/corefcn/pr-output.cc	Sun Feb 10 08:39:30 2019 -0800
@@ -3163,17 +3163,23 @@
 }
 
 /*
-%!assert (rats (2.0005, 9), "4001/2000")
-%!assert (rats (-2.0005, 10), "-4001/2000")
-%!assert (strtrim (rats (2.0005, 30)), "4001/2000")
-%!assert (pi - str2num (rats (pi, 30)), 0, 4 * eps)
-%!assert (e - str2num (rats (e, 30)), 0, 4 * eps)
-%!assert (rats (123, 2), " *")
-
 %!test
-%! v = 1 / double (intmax);
-%! err = v - str2num (rats(v, 12));
-%! assert (err, 0, 4 * eps);
+%! [old_fmt, old_spacing] = format ();
+%! unwind_protect
+%!   format short;
+%!   assert (rats (2.0005, 9), "4001/2000");
+%!   assert (rats (-2.0005, 10), "-4001/2000");
+%!   assert (strtrim (rats (2.0005, 30)), "4001/2000");
+%!   assert (pi - str2num (rats (pi, 30)), 0, 4 * eps);
+%!   assert (e - str2num (rats (e, 30)), 0, 4 * eps);
+%!   assert (rats (123, 2), " *");
+%!   v = 1 / double (intmax);
+%!   err = v - str2num (rats (v, 12));
+%!   assert (err, 0, 4 * eps);
+%! unwind_protect_cleanup
+%!   format (old_fmt);
+%!   format (old_spacing);
+%! end_unwind_protect
 */
 
 DEFUN (disp, args, nargout,
--- a/libinterp/parse-tree/oct-parse.yy	Sat Feb 09 12:24:26 2019 +0100
+++ b/libinterp/parse-tree/oct-parse.yy	Sun Feb 10 08:39:30 2019 -0800
@@ -5748,7 +5748,17 @@
 
 /*
 
-%!assert (evalc ("1"), "ans =  1\n")
+%!test
+%! [old_fmt, old_spacing] = format ();
+%! unwind_protect
+%!   format short;
+%!   str = evalc ("1");
+%!   assert (str, "ans =  1\n");
+%! unwind_protect_cleanup
+%!   format (old_fmt);
+%!   format (old_spacing);
+%! end_unwind_protect
+
 %!assert (evalc ("1;"), "")
 
 %!test
@@ -5762,8 +5772,16 @@
 %! assert (y, 1);
 
 %!test
-%! assert (evalc ("y = 2"), "y =  2\n");
-%! assert (y, 2);
+%! [old_fmt, old_spacing] = format ();
+%! unwind_protect
+%!   format short;
+%!   str = evalc ("y = 2");
+%!   assert (str, "y =  2\n");
+%!   assert (y, 2);
+%! unwind_protect_cleanup
+%!   format (old_fmt);
+%!   format (old_spacing);
+%! end_unwind_protect
 
 %!test
 %! assert (evalc ("y = 3;"), "");
--- a/scripts/+containers/Map.m	Sat Feb 09 12:24:26 2019 +0100
+++ b/scripts/+containers/Map.m	Sun Feb 10 08:39:30 2019 -0800
@@ -785,9 +785,16 @@
 %!error <specified key .b. does not exist>
 %! m = containers.Map ("a", 1);
 %! m("b");
-%!error <specified key .2. does not exist>
-%! m = containers.Map (1, 1);
-%! m(2);
+%!test
+%! [old_fmt, old_spacing] = format ();
+%! unwind_protect
+%!   format short;
+%!   m = containers.Map (1, 1);
+%!   fail ("m(2)", "specified key <2> does not exist");
+%! unwind_protect_cleanup
+%!   format (old_fmt);
+%!   format (old_spacing);
+%! end_unwind_protect
 %!error <only '\(\)' indexing is supported>
 %! m = containers.Map ("a", 1);
 %! m{1};