1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
########################################################################
##
## Copyright (C) 2006-2026 The Octave Project Developers
##
## See the file COPYRIGHT.md in the top-level directory of this
## distribution or <https://octave.org/copyright/>.
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, see
## <https://www.gnu.org/licenses/>.
##
########################################################################
## Test %!error usage
%!function g ()
%! error ("foo");
%!endfunction
%!function f ()
%! g ();
%!endfunction
%!error <foo> f ()
%!function g ()
%! error ("foo\n");
%!endfunction
%!function f ()
%! g
%!endfunction
%!error <foo> f ()
%!error error ()
%!error <foo> error ("foo\n")
## Test %!warning usage
%!function g ()
%! warning ("foo");
%!endfunction
%!function f ()
%! g;
%!endfunction
%!warning <foo> f ()
%!test
%! st.identifier = "backtrace";
%! ws = warning ("query", "backtrace");
%! warning ("on", "backtrace");
%! st.state = "on";
%! assert (warning ("query", "backtrace"), st);
%! warning ("off", "backtrace");
%! st.state = "off";
%! assert (warning ("query", "backtrace"), st);
%! warning (ws.state, "backtrace");
%!test
%! saved_opts = warning ();
%! saved_id = {saved_opts.identifier};
%! saved_state = {saved_opts.state};
%! warning ("off", "all");
%! assert (warning (), struct ("identifier", {"all"}, "state", {"off"}));
%! warning ("off", "all");
%! warning (saved_opts);
%! t1_opts = struct ("identifier", {"foo:bar"}, "state", {"off"});
%! t1_id = {t1_opts.identifier};
%! t1_state = {t1_opts.state};
%! warning (t1_opts);
%! t2_opts = struct ("identifier", [saved_id, t1_id], "state", [saved_state, t1_state]);
%! assert (warning (), t2_opts);
%! warning ("off", "all");
%! warning (saved_opts);
## Bug 36393
%!test
%! w0 = warning;
%! warnoffId = "MATLAB:singularMatrix";
%! warnstat = warning ("query", warnoffId);
%! warnoff = warnstat;
%! warnoff.state = "off";
%! warning (warnoff); # update warning status
%! warning (warnstat); # reset warning status
%! w = warning;
%! assert (w, w0);
%!error <ERR struct must contain the fields> rethrow (struct ())
%!error <STACK struct must contain the fields>
%! rethrow (struct ("message", "foo", "identifier", "", "stack", struct ()))
%!test
%! try
%! union ({'a'}, 1);
%! catch
%! x = lasterror ();
%! try
%! rethrow (lasterror ());
%! catch
%! assert (x, lasterror ());
%! end_try_catch
%! end_try_catch
%!test
%! try
%! union ({'a'}, 1);
%! catch
%! x = lasterror ();
%! try
%! y = struct ("message", "msg", "identifier", "", "stack",
%! struct ("file", "foo.m", "name", "foo", "line", 13));
%! rethrow (y);
%! catch
%! stk = y.stack;
%! [stk.column] = deal (-1);
%! y.stack = stk;
%! assert (y, lasterror ());
%! end_try_catch
%! end_try_catch
|