Mercurial > hg > octave-nkf
annotate scripts/testfun/test.m @ 20828:a3b9ee5c040a
Replace bsxfun with broadcasting for performance with complex inputs (bug #38628).
cumtrapz.m, quadgk.m, trapz.m, center.m, zscore.m: Replace bsxfun with
broadcasting for performance where inputs might be complex.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 12 Oct 2015 21:28:32 -0700 |
parents | 10414d7a25f8 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19794
diff
changeset
|
1 ## Copyright (C) 2005-2015 Paul Kienzle |
5589 | 2 ## |
7016 | 3 ## This file is part of Octave. |
5589 | 4 ## |
7016 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
5589 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5589 | 18 |
19 ## -*- texinfo -*- | |
11412
a8a9f062d0ef
test.m: Use 'Command' for deftype in docstring.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
20 ## @deftypefn {Command} {} test @var{name} |
a8a9f062d0ef
test.m: Use 'Command' for deftype in docstring.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
21 ## @deftypefnx {Command} {} test @var{name} quiet|normal|verbose |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
22 ## @deftypefnx {Function File} {} test ("@var{name}", "quiet|normal|verbose", @var{fid}) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
23 ## @deftypefnx {Function File} {} test ("@var{name}", "quiet|normal|verbose", @var{fname}) |
5589 | 24 ## @deftypefnx {Function File} {@var{success} =} test (@dots{}) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
25 ## @deftypefnx {Function File} {[@var{n}, @var{nmax}, @var{nxfail}, @var{nskip}] =} test (@dots{}) |
14359
7277fe922e99
doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
26 ## @deftypefnx {Function File} {[@var{code}, @var{idx}] =} test ("@var{name}", "grabdemo") |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
27 ## @deftypefnx {Function File} {} test ([], "explain", @var{fid}) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
28 ## @deftypefnx {Function File} {} test ([], "explain", @var{fname}) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
29 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
30 ## Perform built-in self-tests from the first file in the loadpath matching |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
31 ## @var{name}. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
32 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
33 ## @code{test} can be called in either command or functional form. The exact |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
34 ## operation of test is determined by a combination of mode (interactive or |
19344
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19329
diff
changeset
|
35 ## batch), reporting level (@qcode{"quiet"}, @qcode{"normal"}, |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19329
diff
changeset
|
36 ## @qcode{"verbose"}), and whether a logfile or summary output variable is |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19329
diff
changeset
|
37 ## used. |
5589 | 38 ## |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
39 ## The default mode when @code{test} is called from the command line is |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
40 ## interactive. In this mode, tests will be run until the first error is |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
41 ## encountered, or all tests complete successfully. In batch mode, all tests |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
42 ## are run regardless of any failures, and the results are collected for |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
43 ## reporting. Tests which require user interaction, i.e., demo blocks, |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
44 ## are never run in batch mode. |
5589 | 45 ## |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
46 ## Batch mode is enabled by either 1) specifying a logfile using the third |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
47 ## argument @var{fname} or @var{fid}, or 2) requesting an output argument |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
48 ## such as @var{success}, @var{n}, etc. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
49 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
50 ## The optional second argument determines the amount of output to generate and |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
51 ## which types of tests to run. The default value is @qcode{"normal"}. |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
52 ## Requesting an output argument will suppress printing the final summary |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
53 ## message and any intermediate warnings, unless verbose reporting is |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
54 ## enabled. |
5589 | 55 ## |
56 ## @table @asis | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
57 ## @item @qcode{"quiet"} |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
58 ## Print a summary message when all tests pass, or print an error with the |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
59 ## results of the first bad test when a failure occurs. Don't run tests which |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
60 ## require user interaction. |
5589 | 61 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
62 ## @item @qcode{"normal"} |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
63 ## Display warning messages about skipped tests or failing xtests during test |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
64 ## execution. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
65 ## Print a summary message when all tests pass, or print an error with the |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
66 ## results of the first bad test when a failure occurs. Don't run tests which |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
67 ## require user interaction. |
5589 | 68 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
69 ## @item @qcode{"verbose"} |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
70 ## Display tests before execution. Print all warning messages. In interactive |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
71 ## mode, run all tests including those which require user interaction. |
5589 | 72 ## @end table |
73 ## | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
74 ## The optional third input argument specifies a logfile where results of the |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
75 ## tests should be written. The logfile may be a character string |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
76 ## (@var{fname}) or an open file descriptor ID (@var{fid}). To enable batch |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
77 ## processing, but still print the results to the screen, use @code{stdout} for |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
78 ## @var{fid}. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
79 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
80 ## When called with just a single output argument @var{success}, @code{test} |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
81 ## returns true if all of the tests were successful. If called with more |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
82 ## than one output argument then the number of successful tests (@var{n}), |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
83 ## the total number of tests in the file (@var{nmax}), the number of xtest |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
84 ## failures (@var{nxfail}), and the number of skipped tests (@var{nskip} are |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
85 ## returned. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
86 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
87 ## Example |
5589 | 88 ## |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
89 ## @example |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
90 ## @group |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
91 ## test sind |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
92 ## @result{} |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
93 ## PASSES 5 out of 5 tests |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
94 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
95 ## [n, nmax] = test ("sind") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
96 ## @result{} |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
97 ## n = 5 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
98 ## nmax = 5 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
99 ## @end group |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
100 ## @end example |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
101 ## |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
102 ## Additional Calling Syntaxes |
5589 | 103 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
104 ## If the second argument is the string @qcode{"grabdemo"}, the contents of |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
105 ## any built-in demo blocks are extracted but not executed. The text for all |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
106 ## code blocks is concatenated and returned as @var{code} with @var{idx} being |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
107 ## a vector of positions of the ends of each demo block. For an easier way to |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
108 ## extract demo blocks from files, @xref{XREFexample,,example}. |
5589 | 109 ## |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
110 ## If the second argument is @qcode{"explain"} then @var{name} is ignored and |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
111 ## an explanation of the line markers used in @code{test} output reports is |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
112 ## written to the file specified by @var{fname} or @var{fid}. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
113 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
114 ## @seealso{assert, fail, demo, example, error} |
5589 | 115 ## @end deftypefn |
116 | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
117 ## Programming Note: All variables for test() must use the internal prefix "__". |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
118 ## Shared variables are eval'ed into the current workspace and therefore might |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
119 ## collide with the names used in the test.m function itself. |
5589 | 120 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
121 function [__n, __nmax, __nxfail, __nskip] = test (__name, __flag = "normal", __fid = []) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
122 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
123 ## Output from test is prefixed by a "key" to quickly understand the issue. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
124 persistent __signal_fail = "!!!!! "; |
5589 | 125 persistent __signal_empty = "????? "; |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
126 persistent __signal_block = "***** "; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
127 persistent __signal_file = ">>>>> "; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
128 persistent __signal_skip = "----- "; |
6730 | 129 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
130 if (nargin < 1 || nargin > 3) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
131 print_usage (); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
132 elseif (! isempty (__name) && ! ischar (__name)) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
133 error ("test: NAME must be a string"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
134 elseif (! ischar (__flag)) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
135 error ("test: second argument must be a string"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
136 elseif (isempty (__name) && (nargin != 3 || ! strcmp (__flag, "explain"))) |
6046 | 137 print_usage (); |
5589 | 138 endif |
139 | |
8506 | 140 ## Decide if error messages should be collected. |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
141 __logfile = ! isempty (__fid); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
142 __batch = __logfile || nargout > 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
143 __close_fid = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
144 if (__logfile) |
6494 | 145 if (ischar (__fid)) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
146 __fname = __fid; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
147 __fid = fopen (__fname, "wt"); |
6494 | 148 if (__fid < 0) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
149 error ("test: could not open log file %s", __fname); |
6494 | 150 endif |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
151 __close_fid = true; |
5589 | 152 endif |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
153 if (! strcmp (__flag, "explain")) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
154 fprintf (__fid, "%sprocessing %s\n", __signal_file, __name); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
155 fflush (__fid); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
156 endif |
5589 | 157 else |
158 __fid = stdout; | |
159 endif | |
160 | |
6494 | 161 if (strcmp (__flag, "normal")) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
162 __grabdemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
163 __rundemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
164 if (__logfile) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
165 __verbose = 1; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
166 elseif (__batch) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
167 __verbose = -1; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
168 else |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
169 __verbose = 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
170 endif |
6494 | 171 elseif (strcmp (__flag, "quiet")) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
172 __grabdemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
173 __rundemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
174 __verbose = -1; |
6494 | 175 elseif (strcmp (__flag, "verbose")) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
176 __grabdemo = false; |
20233
6babcfbe1a0a
test.m: Don't run interactive demo blocks in batch mode.
Rik <rik@octave.org>
parents:
20038
diff
changeset
|
177 __rundemo = ! __batch; |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
178 __verbose = 1; |
6494 | 179 elseif (strcmp (__flag, "grabdemo")) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
180 __grabdemo = true; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
181 __rundemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
182 __verbose = -1; |
5589 | 183 __demo_code = ""; |
12643
55430618bd5f
Properly warn when demo or example called on a function without demos
Rik <octave@nomad.inbox5.com>
parents:
12447
diff
changeset
|
184 __demo_idx = []; |
6494 | 185 elseif (strcmp (__flag, "explain")) |
186 fprintf (__fid, "# %s new test file\n", __signal_file); | |
187 fprintf (__fid, "# %s no tests in file\n", __signal_empty); | |
188 fprintf (__fid, "# %s test had an unexpected result\n", __signal_fail); | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
189 fprintf (__fid, "# %s test was skipped\n", __signal_skip); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
190 fprintf (__fid, "# %s code for the test\n\n", __signal_block); |
5589 | 191 fprintf (__fid, "# Search for the unexpected results in the file\n"); |
192 fprintf (__fid, "# then page back to find the file name which caused it.\n"); | |
193 fprintf (__fid, "# The result may be an unexpected failure (in which\n"); | |
194 fprintf (__fid, "# case an error will be reported) or an unexpected\n"); | |
195 fprintf (__fid, "# success (in which case no error will be reported).\n"); | |
5908 | 196 fflush (__fid); |
6494 | 197 if (__close_fid) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
198 fclose (__fid); |
6494 | 199 endif |
5589 | 200 return; |
201 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10615
diff
changeset
|
202 error ("test: unknown flag '%s'", __flag); |
5589 | 203 endif |
204 | |
8506 | 205 ## Locate the file to test. |
6249 | 206 __file = file_in_loadpath (__name, "all"); |
207 if (isempty (__file)) | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16992
diff
changeset
|
208 __file = file_in_loadpath ([__name ".m"], "all"); |
5589 | 209 endif |
210 if (isempty (__file)) | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16992
diff
changeset
|
211 __file = file_in_loadpath ([__name ".cc"], "all"); |
6249 | 212 endif |
213 if (iscell (__file)) | |
6365 | 214 if (isempty (__file)) |
215 __file = ""; | |
216 else | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
217 __file = __file{1}; # If repeats, return first in path. |
6365 | 218 endif |
5589 | 219 endif |
220 if (isempty (__file)) | |
221 if (__grabdemo) | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
222 __n = ""; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
223 __nmax = -1; |
5589 | 224 else |
15762
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
225 ftype = exist (__name); |
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
226 if (ftype == 3) |
12447
890e89c3dfeb
More explicit error message when source with tests for dynamically linked functions not found (#30341)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
227 fprintf (__fid, "%s%s source code with tests for dynamically linked function not found\n", __signal_empty, __name); |
15762
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
228 elseif (ftype == 5) |
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
229 fprintf (__fid, "%s%s is a built-in function\n", __signal_empty, __name); |
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
230 elseif (any (strcmp (__operators__ (), __name))) |
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
231 fprintf (__fid, "%s%s is an operator\n", __signal_empty, __name); |
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
232 elseif (any (strcmp (__keywords__ (), __name))) |
a5475ba0d199
test.m: Better error reporting for arguments that can't be tested (bug #37592)
Mike Miller <mtmiller@ieee.org>
parents:
15520
diff
changeset
|
233 fprintf (__fid, "%s%s is a keyword\n", __signal_empty, __name); |
12447
890e89c3dfeb
More explicit error message when source with tests for dynamically linked functions not found (#30341)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
234 else |
890e89c3dfeb
More explicit error message when source with tests for dynamically linked functions not found (#30341)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
235 fprintf (__fid, "%s%s does not exist in path\n", __signal_empty, __name); |
890e89c3dfeb
More explicit error message when source with tests for dynamically linked functions not found (#30341)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
236 endif |
5908 | 237 fflush (__fid); |
6494 | 238 if (nargout > 0) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
239 if (nargout == 1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
240 __n = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
241 else |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
242 __n = __nmax = 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
243 endif |
6494 | 244 endif |
5589 | 245 endif |
6494 | 246 if (__close_fid) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
247 fclose (__fid); |
6494 | 248 endif |
5589 | 249 return; |
250 endif | |
251 | |
8506 | 252 ## Grab the test code from the file. |
5589 | 253 __body = __extract_test_code (__file); |
254 | |
255 if (isempty (__body)) | |
256 if (__grabdemo) | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
257 __n = ""; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
258 __nmax = []; |
5589 | 259 else |
6494 | 260 fprintf (__fid, "%s%s has no tests available\n", __signal_empty, __file); |
5908 | 261 fflush (__fid); |
6494 | 262 if (nargout > 0) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
263 if (nargout == 1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
264 __n = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
265 else |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
266 __n = __nmax = 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
267 endif |
6494 | 268 endif |
5589 | 269 endif |
6494 | 270 if (__close_fid) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
271 fclose (__fid); |
6494 | 272 endif |
5589 | 273 return; |
274 else | |
8506 | 275 ## Add a dummy comment block to the end for ease of indexing. |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
276 if (__body(end) == "\n") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
277 __body = ["\n" __body "#"]; |
5589 | 278 else |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
279 __body = ["\n" __body "\n#"]; |
5589 | 280 endif |
281 endif | |
282 | |
8506 | 283 ## Chop it up into blocks for evaluation. |
6494 | 284 __lineidx = find (__body == "\n"); |
285 __blockidx = __lineidx(find (! isspace (__body(__lineidx+1))))+1; | |
5589 | 286 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
287 ## Ready to start tests. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
288 ## If in batch mode, with a logfile, report what is happening. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
289 if (__verbose > 0) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16992
diff
changeset
|
290 disp ([__signal_file, __file]); |
5589 | 291 endif |
292 | |
8506 | 293 ## Assume all tests will pass. |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
294 __all_success = true; |
5589 | 295 |
8506 | 296 ## Process each block separately, initially with no shared variables. |
5589 | 297 __tests = __successes = 0; |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
298 __xfail = __xskip = 0; |
5589 | 299 __shared = " "; |
300 __shared_r = " "; | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
301 __clearfcn = ""; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
302 for __i = 1:numel (__blockidx)-1 |
5589 | 303 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
304 ## FIXME: Should other global settings be similarly saved and restored? |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
305 orig_wstate = warning (); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
306 unwind_protect |
5589 | 307 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
308 ## Extract the block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
309 __block = __body(__blockidx(__i):__blockidx(__i+1)-2); |
5589 | 310 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
311 ## Print the code block before execution if in verbose mode. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
312 if (__verbose > 0) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
313 fprintf (__fid, "%s%s\n", __signal_block, __block); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
314 fflush (__fid); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
315 endif |
5589 | 316 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
317 ## Split __block into __type and __code. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
318 __idx = find (! isletter (__block)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
319 if (isempty (__idx)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
320 __type = __block; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
321 __code = ""; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
322 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
323 __type = __block(1:__idx(1)-1); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
324 __code = __block(__idx(1):length (__block)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
325 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
326 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
327 ## Assume the block will succeed. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
328 __success = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
329 __msg = []; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
330 __isxtest = false; |
5589 | 331 |
8506 | 332 ### DEMO |
333 | |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
334 ## If in __grabdemo mode, then don't process any other block type. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
335 ## So that the other block types don't have to worry about |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
336 ## this __grabdemo mode, the demo block processor grabs all block |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
337 ## types and skips those which aren't demo blocks. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
338 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
339 __isdemo = strcmp (__type, "demo"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
340 if (__grabdemo || __isdemo) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
341 __istest = false; |
8506 | 342 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
343 if (__grabdemo && __isdemo) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
344 if (isempty (__demo_code)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
345 __demo_code = __code; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
346 __demo_idx = [1, length(__demo_code)+1]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
347 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
348 __demo_code = [__demo_code, __code]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
349 __demo_idx = [__demo_idx, length(__demo_code)+1]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
350 endif |
5589 | 351 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
352 elseif (__rundemo && __isdemo) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
353 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
354 ## process the code in an environment without variables |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
355 eval (sprintf ("function __test__ ()\n%s\nendfunction", __code)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
356 __test__; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
357 input ("Press <enter> to continue: ", "s"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
358 catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
359 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
360 __msg = [__signal_fail "demo failed\n" lasterr()]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
361 end_try_catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
362 clear __test__; |
5589 | 363 |
10549 | 364 endif |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
365 ## Code already processed. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
366 __code = ""; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
367 |
8506 | 368 ### SHARED |
369 | |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
370 elseif (strcmp (__type, "shared")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
371 __istest = false; |
5589 | 372 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
373 ## Separate initialization code from variables. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
374 __idx = find (__code == "\n"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
375 if (isempty (__idx)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
376 __vars = __code; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
377 __code = ""; |
10549 | 378 else |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
379 __vars = __code (1:__idx(1)-1); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
380 __code = __code (__idx(1):length (__code)); |
10549 | 381 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
382 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
383 ## Strip comments off the variables. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
384 __idx = find (__vars == "%" | __vars == "#"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
385 if (! isempty (__idx)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
386 __vars = __vars(1:__idx(1)-1); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
387 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
388 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
389 ## Assign default values to variables. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
390 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
391 __vars = deblank (__vars); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
392 if (! isempty (__vars)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
393 eval ([strrep(__vars, ",", "=[];"), "=[];"]); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
394 __shared = __vars; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
395 __shared_r = ["[ " __vars "] = "]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
396 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
397 __shared = " "; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
398 __shared_r = " "; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
399 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
400 catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
401 ## Couldn't declare, so don't initialize. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
402 __code = ""; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
403 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
404 __msg = [__signal_fail "shared variable initialization failed\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
405 end_try_catch |
5589 | 406 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
407 ## Initialization code will be evaluated below. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
408 |
8506 | 409 ### FUNCTION |
410 | |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
411 elseif (strcmp (__type, "function")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
412 __istest = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
413 persistent __fn = 0; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
414 __name_position = function_name (__block); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
415 if (isempty (__name_position)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
416 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
417 __msg = [__signal_fail "test failed: missing function name\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
418 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
419 __name = __block(__name_position(1):__name_position(2)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
420 __code = __block; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
421 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
422 eval (__code); # Define the function |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
423 __clearfcn = sprintf ("%sclear %s;\n", __clearfcn, __name); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
424 catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
425 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
426 __msg = [__signal_fail "test failed: syntax error\n" lasterr()]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
427 end_try_catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
428 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
429 __code = ""; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
430 |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
431 ### ENDFUNCTION |
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
432 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
433 elseif (strcmp (__type, "endfunction")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
434 ## endfunction simply declares the end of a previous function block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
435 ## There is no processing to be done here, just skip to next block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
436 __istest = false; |
10549 | 437 __code = ""; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
438 |
8506 | 439 ### ASSERT/FAIL |
5589 | 440 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
441 elseif (strcmp (__type, "assert") || strcmp (__type, "fail")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
442 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
443 ## Put the keyword back on the code. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
444 __code = __block; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
445 ## The code will be evaluated below as a test block. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
446 |
8506 | 447 ### ERROR/WARNING |
448 | |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
449 elseif (strcmp (__type, "error") || strcmp (__type, "warning")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
450 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
451 __iswarning = strcmp (__type, "warning"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
452 [__pattern, __id, __code] = getpattern (__code); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
453 if (__id) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
454 __patstr = ["id=" __id]; |
16976
13affad7347c
test.m: Use the syntax "BLOCK_NAME failed" for error/warnings blocks.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
455 else |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
456 if (! strcmp (__pattern, '.')) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
457 __patstr = ["<" __pattern ">"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
458 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
459 __patstr = ifelse (__iswarning, "a warning", "an error"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
460 endif |
16976
13affad7347c
test.m: Use the syntax "BLOCK_NAME failed" for error/warnings blocks.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
461 endif |
5589 | 462 try |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
463 eval (sprintf ("function __test__(%s)\n%s\nendfunction", |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
464 __shared, __code)); |
5589 | 465 catch |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
466 __success = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
467 __msg = [__signal_fail "test failed: syntax error\n" lasterr()]; |
5589 | 468 end_try_catch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
469 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
470 if (__success) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
471 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
472 __warnstate = warning ("query", "quiet"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
473 warning ("on", "quiet"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
474 ## Clear error and warning strings before starting |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
475 lasterr (""); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
476 lastwarn (""); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
477 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
478 eval (sprintf ("__test__(%s);", __shared)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
479 if (! __iswarning) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
480 __msg = [__signal_fail "error failed.\n" ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
481 "Expected " __patstr ", but got no error\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
482 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
483 if (! isempty (__id)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
484 [~, __err] = lastwarn (); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
485 __mismatch = ! strcmp (__err, __id); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
486 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
487 __err = trimerr (lastwarn (), "warning"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
488 __mismatch = isempty (regexp (__err, __pattern, "once")); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
489 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
490 warning (__warnstate.state, "quiet"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
491 if (isempty (__err)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
492 __msg = [__signal_fail "warning failed.\n" ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
493 "Expected " __patstr ", but got no warning\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
494 elseif (__mismatch) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
495 __msg = [__signal_fail "warning failed.\n" ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
496 "Expected " __patstr ", but got <" __err ">\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
497 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
498 __success = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
499 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
500 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
501 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
502 catch |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
503 if (! isempty (__id)) |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
504 [~, __err] = lasterr (); |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
505 __mismatch = ! strcmp (__err, __id); |
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
506 else |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
507 __err = trimerr (lasterr (), "error"); |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
508 __mismatch = isempty (regexp (__err, __pattern, "once")); |
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
509 endif |
7028 | 510 warning (__warnstate.state, "quiet"); |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
511 if (__iswarning) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
512 __msg = [__signal_fail "warning failed.\n" ... |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
513 "Expected warning " __patstr ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
514 ", but got error <" __err ">\n"]; |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
515 elseif (__mismatch) |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
516 __msg = [__signal_fail "error failed.\n" ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
517 "Expected " __patstr ", but got <" __err ">\n"]; |
7028 | 518 else |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
519 __success = true; |
7028 | 520 endif |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
521 end_try_catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
522 clear __test__; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
523 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
524 ## Code already processed. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
525 __code = ""; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
526 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
527 ### TESTIF |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
528 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
529 elseif (strcmp (__type, "testif")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
530 __e = regexp (__code, '.$', 'lineanchors', 'once'); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
531 ## Strip any comment from testif line before looking for features |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
532 __feat_line = strtok (__code(1:__e), '#%'); |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
533 __feat = regexp (__feat_line, '\w+', 'match'); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
534 __feat = strrep (__feat, "HAVE_", ""); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
535 __have_feat = __have_feature__ (__feat); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
536 if (__have_feat) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
537 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
538 __code = __code(__e + 1 : end); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
539 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
540 __xskip++; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
541 __istest = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
542 __code = ""; # Skip the code. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
543 __msg = [__signal_skip "skipped test\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
544 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
545 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
546 ### TEST |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
547 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
548 elseif (strcmp (__type, "test")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
549 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
550 ## Code will be evaluated below. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
551 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
552 ### XTEST |
5589 | 553 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
554 elseif (strcmp (__type, "xtest")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
555 __istest = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
556 __isxtest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
557 ## Code will be evaluated below. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
558 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
559 ### Comment block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
560 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
561 elseif (strcmp (__block(1:1), "#")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
562 __istest = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
563 __code = ""; # skip the code |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
564 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
565 ### Unknown block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
566 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
567 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
568 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
569 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
570 __msg = [__signal_fail "unknown test type!\n"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
571 __code = ""; # skip the code |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
572 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
573 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
574 ## evaluate code for test, shared, and assert. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
575 if (! isempty(__code)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
576 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
577 ## FIXME: Must check for embedded test functions, which cause |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
578 ## segfaults, until issues with subfunctions in functions are fixed. |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
579 embed_func = regexp (__code, '^\s*function ', 'once', 'lineanchors'); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
580 if (isempty (embed_func)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
581 eval (sprintf ("function %s__test__(%s)\n%s\nendfunction", |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
582 __shared_r, __shared, __code)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
583 eval (sprintf ("%s__test__(%s);", __shared_r, __shared)); |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
584 else |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
585 error (["Functions embedded in %!test blocks are not allowed.\n", ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
586 "Use the %!function/%!endfunction syntax instead to define shared functions for testing.\n"]); |
10549 | 587 endif |
588 catch | |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
589 if (strcmp (__type, "xtest")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
590 __msg = [__signal_fail "known failure\n" lasterr()]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
591 __xfail++; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
592 __success = false; |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
593 else |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
594 __msg = [__signal_fail "test failed\n" lasterr()]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
595 __success = false; |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
596 endif |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
597 if (isempty (lasterr ())) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
598 error ("empty error text, probably Ctrl-C --- aborting"); |
5589 | 599 endif |
10549 | 600 end_try_catch |
601 clear __test__; | |
5589 | 602 endif |
603 | |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
604 ## All done. Remember if we were successful and print any messages. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
605 if (! isempty (__msg) && (__verbose >= 0 || __logfile)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
606 ## Make sure the user knows what caused the error. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
607 if (__verbose < 1) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
608 fprintf (__fid, "%s%s\n", __signal_block, __block); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
609 fflush (__fid); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
610 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
611 fprintf (__fid, "%s\n", __msg); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
612 ## Show the variable context. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
613 if (! strcmp (__type, "error") && ! strcmp (__type, "testif") |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
614 && ! all (__shared == " ")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
615 fputs (__fid, "shared variables "); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
616 eval (sprintf ("fdisp(__fid,var2struct(%s));", __shared)); |
14066
80bda7c4f012
Avoid segfault in test() and demo() blocks with embedded functions (Bugs #35068, #32843, #33981)
Rik <octave@nomad.inbox5.com>
parents:
13914
diff
changeset
|
617 endif |
20406
10414d7a25f8
test.m: Show error message and shared variables section in pager (bug #45007).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20233
diff
changeset
|
618 fflush (__fid); |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
619 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
620 if (! __success && ! __isxtest) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
621 __all_success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
622 ## Stop after 1 error if not in batch mode or only pass/fail requested. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
623 if (! __batch || nargout == 1) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
624 if (nargout > 0) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
625 if (nargout == 1) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
626 __n = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
627 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
628 __n = __nmax = 0; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
629 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
630 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
631 if (__close_fid) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
632 fclose (__fid); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
633 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
634 return; |
6728 | 635 endif |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
636 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
637 __tests += (__istest || __isxtest); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
638 __successes += __success && (__istest || __isxtest); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
639 |
19641
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
640 unwind_protect_cleanup |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
641 warning ("off", "all"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
642 warning (orig_wstate); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19599
diff
changeset
|
643 end_unwind_protect |
5589 | 644 endfor |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
645 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
646 ## Clear any functions created during test run |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
647 eval (__clearfcn, ""); |
5589 | 648 |
649 if (nargout == 0) | |
8422
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
650 if (__tests || __xfail || __xskip) |
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
651 if (__xfail) |
16992
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
652 printf ("PASSES %d out of %d test%s (%d expected failure%s)\n", |
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
653 __successes, __tests, ifelse (__tests > 1, "s", ""), |
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
654 __xfail, ifelse (__xfail > 1, "s", "")); |
8422
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
655 else |
16992
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
656 printf ("PASSES %d out of %d test%s\n", __successes, __tests, |
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
657 ifelse (__tests > 1, "s", "")); |
8422
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
658 endif |
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
659 if (__xskip) |
16992
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
660 printf ("Skipped %d test%s due to missing features\n", __xskip, |
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
661 ifelse (__xskip > 1, "s", "")); |
8422
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
662 endif |
6730 | 663 else |
8422
20cbb0fdab48
test.m: print "has no tests" message if there are demos but no tests
John W. Eaton <jwe@octave.org>
parents:
8202
diff
changeset
|
664 printf ("%s%s has no tests available\n", __signal_empty, __file); |
7242 | 665 endif |
5589 | 666 elseif (__grabdemo) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
667 __n = __demo_code; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
668 __nmax = __demo_idx; |
6494 | 669 elseif (nargout == 1) |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
670 __n = __all_success; |
5589 | 671 else |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
672 __n = __successes; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
673 __nmax = __tests; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
674 __nxfail = __xfail; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
675 __nskip = __xskip; |
5589 | 676 endif |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
677 |
5589 | 678 endfunction |
679 | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
680 |
8506 | 681 ## Create structure with fieldnames the name of the input variables. |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
682 function s = var2struct (varargin) |
6494 | 683 for i = 1:nargin |
684 s.(deblank (argn(i,:))) = varargin{i}; | |
5589 | 685 endfor |
686 endfunction | |
687 | |
8506 | 688 ## Find [start,end] of fn in 'function [a,b] = fn'. |
6494 | 689 function pos = function_name (def) |
5589 | 690 pos = []; |
691 | |
8506 | 692 ## Find the end of the name. |
6494 | 693 right = find (def == "(", 1); |
694 if (isempty (right)) | |
695 return; | |
696 endif | |
697 right = find (def(1:right-1) != " ", 1, "last"); | |
5589 | 698 |
8506 | 699 ## Find the beginning of the name. |
6494 | 700 left = max ([find(def(1:right)==" ", 1, "last"), ... |
10549 | 701 find(def(1:right)=="=", 1, "last")]); |
6494 | 702 if (isempty (left)) |
703 return; | |
704 endif | |
5589 | 705 left++; |
706 | |
8506 | 707 ## Return the end points of the name. |
6494 | 708 pos = [left, right]; |
5589 | 709 endfunction |
710 | |
8506 | 711 ## Strip <pattern> from '<pattern> code'. |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
712 ## Also handles 'id=ID code' |
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
713 function [pattern, id, rest] = getpattern (str) |
6494 | 714 pattern = "."; |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
715 id = []; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
716 rest = str; |
6494 | 717 str = trimleft (str); |
718 if (! isempty (str) && str(1) == "<") | |
719 close = index (str, ">"); | |
720 if (close) | |
5589 | 721 pattern = str(2:close-1); |
722 rest = str(close+1:end); | |
723 endif | |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
724 elseif (strncmp (str, "id=", 3)) |
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
725 [id, rest] = strtok (str(4:end)); |
5589 | 726 endif |
727 endfunction | |
728 | |
8506 | 729 ## Strip '.*prefix:' from '.*prefix: msg\n' and strip trailing blanks. |
6494 | 730 function msg = trimerr (msg, prefix) |
16977
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
731 idx = index (msg, [prefix ":"]); |
6494 | 732 if (idx > 0) |
733 msg(1:idx+length(prefix)) = []; | |
734 endif | |
16977
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
735 msg = strtrim (msg); |
5589 | 736 endfunction |
737 | |
8506 | 738 ## Strip leading blanks from string. |
6494 | 739 function str = trimleft (str) |
16977
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
740 idx = find (! isspace (str), 1); |
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
741 str = str(idx:end); |
5589 | 742 endfunction |
743 | |
744 function body = __extract_test_code (nm) | |
745 fid = fopen (nm, "rt"); | |
19599 | 746 body = ""; |
5589 | 747 if (fid >= 0) |
19483
64f034147e9a
test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
748 while (ischar (ln = fgets (fid))) |
64f034147e9a
test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
749 if (strncmp (ln, "%!", 2)) |
64f034147e9a
test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
750 body = [body, ln(3:end)]; |
5589 | 751 endif |
752 endwhile | |
753 fclose (fid); | |
754 endif | |
755 endfunction | |
756 | |
16977
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
757 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
758 ## example from toeplitz |
13914
4b1ce071f504
test.m: Update tests which depend on error messages changed in toeplitz.m
Rik <octave@nomad.inbox5.com>
parents:
13305
diff
changeset
|
759 %!shared msg1,msg2 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
760 %! msg1 = "C must be a vector"; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
761 %! msg2 = "C and R must be vectors"; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
762 %!fail ("toeplitz ([])", msg1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
763 %!fail ("toeplitz ([1,2;3,4])", msg1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
764 %!fail ("toeplitz ([1,2],[])", msg2) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
765 %!fail ("toeplitz ([1,2],[1,2;3,4])", msg2) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
766 %!fail ("toeplitz ([1,2;3,4],[1,2])", msg2) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
767 %!test fail ("toeplitz", "Invalid call to toeplitz") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
768 %!fail ("toeplitz (1, 2, 3)", "Invalid call to toeplitz") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
769 %!test assert (toeplitz ([1,2,3], [1,4]), [1,4; 2,1; 3,2]) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
770 %!assert (toeplitz ([1,2,3], [1,4]), [1,4; 2,1; 3,2]) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
771 %!demo toeplitz ([1,2,3,4],[1,5,6]) |
5589 | 772 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
773 ## example from kron |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
774 %!error <Invalid call to kron> kron () |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
775 %!error <Invalid call to kron> kron (1) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
776 %!test assert (isempty (kron ([], rand (3, 4)))) |
5589 | 777 %!test assert (isempty (kron (rand (3, 4), []))) |
778 %!test assert (isempty (kron ([], []))) | |
779 %!shared A, B | |
780 %!test | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
781 %! A = [1, 2, 3; 4, 5, 6]; |
5589 | 782 %! B = [1, -1; 2, -2]; |
783 %!assert (size (kron (zeros (3, 0), A)), [ 3*rows(A), 0 ]) | |
784 %!assert (size (kron (zeros (0, 3), A)), [ 0, 3*columns(A) ]) | |
785 %!assert (size (kron (A, zeros (3, 0))), [ 3*rows(A), 0 ]) | |
786 %!assert (size (kron (A, zeros (0, 3))), [ 0, 3*columns(A) ]) | |
787 %!assert (kron (pi, e), pi*e) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
788 %!assert (kron (pi, A), pi*A) |
5589 | 789 %!assert (kron (A, e), e*A) |
790 %!assert (kron ([1, 2, 3], A), [ A, 2*A, 3*A ]) | |
791 %!assert (kron ([1; 2; 3], A), [ A; 2*A; 3*A ]) | |
792 %!assert (kron ([1, 2; 3, 4], A), [ A, 2*A; 3*A, 4*A ]) | |
793 %!test | |
794 %! res = [1,-1,2,-2,3,-3; 2,-2,4,-4,6,-6; 4,-4,5,-5,6,-6; 8,-8,10,-10,12,-12]; | |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
795 %! assert (kron (A, B), res); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
796 %!shared # clear out shared variables |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
797 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
798 ## Now verify test() itself |
5589 | 799 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
800 ## Test 'fail' keyword |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
801 %!fail ("test", "Invalid call to test") # no args, generates usage() |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
802 %!fail ("test (1,2,3,4)", "usage.*test") # too many args, generates usage() |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
803 %!fail ('test ("test", "bogus")', "unknown flag") # incorrect args |
5589 | 804 %!fail ('garbage','garbage.*undefined') # usage on nonexistent function should be |
805 | |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
806 ## Test 'error' keyword |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
807 %!error test # no args, generates usage() |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
808 %!error test (1,2,3,4) # too many args, generates usage() |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
809 %!error <unknown flag> test ("test", "bogus"); # incorrect args |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
810 %!error test ("test", "bogus"); # test without pattern |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
811 %!error <'garbage' undefined> garbage; # usage on nonexistent function is error |
5589 | 812 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
813 ## Test 'warning' keyword |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
814 %!warning warning ("warning message"); # no pattern |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
815 %!warning <warning message> warning ("warning message"); # with pattern |
5589 | 816 |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
817 ## Test 'shared' keyword |
5589 | 818 %!shared a # create a shared variable |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
819 %!test a = 3; # assign to a shared variable |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
820 %!test assert (a, 3) # variable should equal 3 |
5589 | 821 %!shared b,c # replace shared variables |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
822 %!test assert (! exist ("a", "var")); # a no longer exists |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
823 %!test assert (isempty (b)); # variables start off empty |
5589 | 824 %!shared a,b,c # recreate a shared variable |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
825 %!test assert (isempty (a)); # value is empty even if it had a previous value |
5589 | 826 %!test a=1; b=2; c=3; # give values to all variables |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
827 %!test assert ([a,b,c], [1,2,3]); # test all of them together |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
828 %!test c=6; # update a value |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
829 %!test assert ([a,b,c], [1,2,6]); # show that the update sticks |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
830 %!shared # clear all shared variables |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
831 %!test assert (! exist ("a", "var")) # show that they are cleared |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
832 %!shared a,b,c # support for initializer shorthand |
5589 | 833 %! a=1; b=2; c=4; |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
834 %!shared # clear all shared variables for remainder of tests |
5589 | 835 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
836 ## Test 'function' keyword |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
837 %!function x = __test_a (y) |
5589 | 838 %! x = 2*y; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
839 %!endfunction |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
840 %!assert (__test_a (2), 4) # Test a test function |
5589 | 841 |
842 %!function __test_a (y) | |
843 %! x = 2*y; | |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
844 %!endfunction |
5589 | 845 %!test |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
846 %! __test_a (2); # Test a test function with no return value |
5589 | 847 |
848 %!function [x,z] = __test_a (y) | |
849 %! x = 2*y; | |
850 %! z = 3*y; | |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
851 %!endfunction |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
852 %!test |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
853 %! [x,z] = __test_a (3); # Test a test function with multiple returns |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
854 %! assert (x,6); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
855 %! assert (z,9); |
5589 | 856 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
857 ## Test 'assert' keyword |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
858 %!assert (isempty ([])) # support for test assert shorthand |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
859 %!assert (size (ones (1,2,3)), [1 2 3]) |
5589 | 860 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
861 ## Test 'demo' keyword |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
862 %!demo # multiline demo block |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14190
diff
changeset
|
863 %! t = [0:0.01:2*pi]; x = sin (t); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14190
diff
changeset
|
864 %! plot (t,x); |
5589 | 865 %! % you should now see a sine wave in your figure window |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
866 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
867 %!demo a=3 # single line demo blocks work too |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
868 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
869 %!test |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
870 %! [code, idx] = test ("test", "grabdemo"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
871 %! assert (numel (idx), 4); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
872 %! assert (code(idx(3):end), |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
873 %! " a=3 # single line demo blocks work too"); |
5589 | 874 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
875 ## Test 'testif' keyword |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
876 %!testif HAVE_BOGUS_FEATURE |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
877 %! error ("testif executed code despite not having feature"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
878 |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
879 ## Test 'xtest' keyword |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
880 %!xtest |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
881 %! assert (1, 1); # Test passes |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
882 %!xtest |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
883 %! assert (0, 1); # Test fails |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
884 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
885 ## Test comment block. it can contain anything. |
5589 | 886 %!## |
887 %! it is the "#" as the block type that makes it a comment | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14190
diff
changeset
|
888 %! and it stays as a comment even through continuation lines |
5589 | 889 %! which means that it works well with commenting out whole tests |
890 | |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
891 ## Test test() input validation |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
892 %!error <NAME must be a string> test (1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
893 %!error <second argument must be a string> test ("ls", 1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
894 %!error test ([], "normal") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
895 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
896 ## All of the following tests should fail. These tests should |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
897 ## be disabled unless you are developing test() since users don't |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
898 ## like to be presented with expected failures. I use '% !' to disable. |
5589 | 899 % !test error("---------Failure tests. Use test('test','verbose',1)"); |
900 % !test assert([a,b,c],[1,3,6]); # variables have wrong values | |
901 % !bogus # unknown block type | |
902 % !error toeplitz([1,2,3]); # correct usage | |
903 % !test syntax errors) # syntax errors fail properly | |
904 % !shared garbage in # variables must be comma separated | |
905 % !error syntax++error # error test fails on syntax errors | |
906 % !error "succeeds."; # error test fails if code succeeds | |
907 % !error <wrong pattern> error("message") # error pattern must match | |
908 % !demo with syntax error # syntax errors in demo fail properly | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
909 % !shared a,b,c |
5589 | 910 % !demo # shared variables not available in demo |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
911 % ! assert (exist ("a", "var")) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
912 % !error |
19240
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
913 % ! test ('/etc/passwd'); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
19047
diff
changeset
|
914 % ! test ("nonexistent file"); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
915 % ! ## These don't signal an error, so the test for an error fails. Note |
5589 | 916 % ! ## that the call doesn't reference the current fid (it is unavailable), |
917 % ! ## so of course the informational message is not printed in the log. | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14190
diff
changeset
|
918 |