Mercurial > octave
annotate scripts/testfun/test.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2005-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26650
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26650
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26650
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26650
diff
changeset
|
5 ## |
5589 | 6 ## |
7016 | 7 ## This file is part of Octave. |
5589 | 8 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23571
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
7016 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23571
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
12 ## (at your option) any later version. |
7016 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22627
diff
changeset
|
17 ## GNU General Public License for more details. |
5589 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23571
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
5589 | 22 |
23 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
24 ## @deftypefn {} {} test @var{name} |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
25 ## @deftypefnx {} {} test @var{name} quiet|normal|verbose |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
26 ## @deftypefnx {} {} test ("@var{name}", "quiet|normal|verbose", @var{fid}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
27 ## @deftypefnx {} {} test ("@var{name}", "quiet|normal|verbose", @var{fname}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
28 ## @deftypefnx {} {@var{success} =} test (@dots{}) |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
29 ## @deftypefnx {} {[@var{n}, @var{nmax}, @var{nxfail}, @var{nbug}, @var{nskip}, @var{nrtskip}, @var{nregression}] =} test (@dots{}) |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
30 ## @deftypefnx {} {[@var{code}, @var{idx}] =} test ("@var{name}", "grabdemo") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
31 ## @deftypefnx {} {} test ([], "explain", @var{fid}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
32 ## @deftypefnx {} {} test ([], "explain", @var{fname}) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
33 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
34 ## 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:
18857
diff
changeset
|
35 ## @var{name}. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
36 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
37 ## @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:
18857
diff
changeset
|
38 ## operation of test is determined by a combination of mode (interactive or |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19137
diff
changeset
|
39 ## batch), reporting level (@qcode{"quiet"}, @qcode{"normal"}, |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19137
diff
changeset
|
40 ## @qcode{"verbose"}), and whether a logfile or summary output variable is |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19137
diff
changeset
|
41 ## used. |
5589 | 42 ## |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
43 ## 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:
18857
diff
changeset
|
44 ## 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:
18857
diff
changeset
|
45 ## 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:
18857
diff
changeset
|
46 ## 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:
18857
diff
changeset
|
47 ## reporting. Tests which require user interaction, i.e., demo blocks, |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
48 ## are never run in batch mode. |
5589 | 49 ## |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
50 ## 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:
18857
diff
changeset
|
51 ## 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:
18857
diff
changeset
|
52 ## such as @var{success}, @var{n}, etc. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
53 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
54 ## The optional second argument determines the amount of output to generate and |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
55 ## which types of tests to run. The default value is @qcode{"normal"}. |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
56 ## Requesting an output argument will suppress printing the final summary |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
57 ## message and any intermediate warnings, unless verbose reporting is |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
58 ## enabled. |
5589 | 59 ## |
60 ## @table @asis | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
61 ## @item @qcode{"quiet"} |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
62 ## 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:
18857
diff
changeset
|
63 ## 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:
18857
diff
changeset
|
64 ## require user interaction. |
5589 | 65 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
66 ## @item @qcode{"normal"} |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
67 ## 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:
18857
diff
changeset
|
68 ## execution. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
69 ## 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:
18857
diff
changeset
|
70 ## 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:
18857
diff
changeset
|
71 ## require user interaction. |
5589 | 72 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
73 ## @item @qcode{"verbose"} |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
74 ## Display tests before execution. Print all warning messages. In interactive |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
75 ## mode, run all tests including those which require user interaction. |
5589 | 76 ## @end table |
77 ## | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
78 ## 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:
18857
diff
changeset
|
79 ## 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:
18857
diff
changeset
|
80 ## (@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:
18857
diff
changeset
|
81 ## 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:
18857
diff
changeset
|
82 ## @var{fid}. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
83 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
84 ## 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:
18857
diff
changeset
|
85 ## 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:
18857
diff
changeset
|
86 ## 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:
18857
diff
changeset
|
87 ## the total number of tests in the file (@var{nmax}), the number of xtest |
23363
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
88 ## failures (@var{nxfail}), the number of tests failed due known bugs |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
89 ## (@var{nbug}), the number of tests skipped due to missing features |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
90 ## (@var{nskip}), the number of tests skipped due to run-time |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
91 ## conditions (@var{nrtskip}), and the number of regressions |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
92 ## (@var{nregression}) are returned. |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
93 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
94 ## Example |
5589 | 95 ## |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
96 ## @example |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
97 ## @group |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
98 ## test sind |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
99 ## @result{} |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
100 ## PASSES 5 out of 5 tests |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
101 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
102 ## [n, nmax] = test ("sind") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
103 ## @result{} |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
104 ## n = 5 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
105 ## nmax = 5 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
106 ## @end group |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
107 ## @end example |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
108 ## |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
109 ## Additional Calling Syntaxes |
5589 | 110 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
111 ## If the second argument is the string @qcode{"grabdemo"}, the contents of |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
112 ## 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:
18857
diff
changeset
|
113 ## 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:
18857
diff
changeset
|
114 ## 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:
18857
diff
changeset
|
115 ## extract demo blocks from files, @xref{XREFexample,,example}. |
5589 | 116 ## |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
117 ## 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:
18857
diff
changeset
|
118 ## 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:
18857
diff
changeset
|
119 ## 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:
18857
diff
changeset
|
120 ## |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
121 ## @seealso{assert, fail, demo, example, error} |
5589 | 122 ## @end deftypefn |
123 | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
124 ## 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:
18857
diff
changeset
|
125 ## 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:
18857
diff
changeset
|
126 ## collide with the names used in the test.m function itself. |
5589 | 127 |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
128 function [__n, __nmax, __nxfail, __nbug, __nskip, __nrtskip, __nregression] = test (__name, __flag = "normal", __fid = []) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
129 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
130 ## 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:
18857
diff
changeset
|
131 persistent __signal_fail = "!!!!! "; |
5589 | 132 persistent __signal_empty = "????? "; |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
133 persistent __signal_block = "***** "; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
134 persistent __signal_file = ">>>>> "; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
135 persistent __signal_skip = "----- "; |
6730 | 136 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
137 if (nargin < 1 || nargin > 3) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
138 print_usage (); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
139 elseif (! isempty (__name) && ! ischar (__name)) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
140 error ("test: NAME must be a string"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
141 elseif (! ischar (__flag)) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
142 error ("test: second argument must be a string"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
143 elseif (isempty (__name) && (nargin != 3 || ! strcmp (__flag, "explain"))) |
6046 | 144 print_usage (); |
5589 | 145 endif |
146 | |
8506 | 147 ## Decide if error messages should be collected. |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
148 __logfile = ! isempty (__fid); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
149 __batch = __logfile || nargout > 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
150 __close_fid = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
151 if (__logfile) |
6494 | 152 if (ischar (__fid)) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
153 __fname = __fid; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
154 __fid = fopen (__fname, "wt"); |
6494 | 155 if (__fid < 0) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
156 error ("test: could not open log file %s", __fname); |
6494 | 157 endif |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
158 __close_fid = true; |
5589 | 159 endif |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
160 if (! strcmp (__flag, "explain")) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
161 fprintf (__fid, "%sprocessing %s\n", __signal_file, __name); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
162 fflush (__fid); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
163 endif |
5589 | 164 else |
165 __fid = stdout; | |
166 endif | |
167 | |
6494 | 168 if (strcmp (__flag, "normal")) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
169 __grabdemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
170 __rundemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
171 if (__logfile) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
172 __verbose = 1; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
173 elseif (__batch) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
174 __verbose = -1; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
175 else |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
176 __verbose = 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
177 endif |
6494 | 178 elseif (strcmp (__flag, "quiet")) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
179 __grabdemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
180 __rundemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
181 __verbose = -1; |
6494 | 182 elseif (strcmp (__flag, "verbose")) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
183 __grabdemo = false; |
20023
6babcfbe1a0a
test.m: Don't run interactive demo blocks in batch mode.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
184 __rundemo = ! __batch; |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
185 __verbose = 1; |
6494 | 186 elseif (strcmp (__flag, "grabdemo")) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
187 __grabdemo = true; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
188 __rundemo = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
189 __verbose = -1; |
5589 | 190 __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
|
191 __demo_idx = []; |
6494 | 192 elseif (strcmp (__flag, "explain")) |
193 fprintf (__fid, "# %s new test file\n", __signal_file); | |
194 fprintf (__fid, "# %s no tests in file\n", __signal_empty); | |
195 fprintf (__fid, "# %s test had an unexpected result\n", __signal_fail); | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
196 fprintf (__fid, "# %s test was skipped\n", __signal_skip); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
197 fprintf (__fid, "# %s code for the test\n\n", __signal_block); |
5589 | 198 fprintf (__fid, "# Search for the unexpected results in the file\n"); |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20196
diff
changeset
|
199 fprintf (__fid, "# then page back to find the filename which caused it.\n"); |
5589 | 200 fprintf (__fid, "# The result may be an unexpected failure (in which\n"); |
201 fprintf (__fid, "# case an error will be reported) or an unexpected\n"); | |
202 fprintf (__fid, "# success (in which case no error will be reported).\n"); | |
5908 | 203 fflush (__fid); |
6494 | 204 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
|
205 fclose (__fid); |
6494 | 206 endif |
5589 | 207 return; |
208 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10615
diff
changeset
|
209 error ("test: unknown flag '%s'", __flag); |
5589 | 210 endif |
211 | |
8506 | 212 ## Locate the file to test. |
6249 | 213 __file = file_in_loadpath (__name, "all"); |
214 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
|
215 __file = file_in_loadpath ([__name ".m"], "all"); |
5589 | 216 endif |
217 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
|
218 __file = file_in_loadpath ([__name ".cc"], "all"); |
6249 | 219 endif |
220 if (iscell (__file)) | |
6365 | 221 if (isempty (__file)) |
222 __file = ""; | |
223 else | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
224 __file = __file{1}; # If repeats, return first in path. |
6365 | 225 endif |
5589 | 226 endif |
227 if (isempty (__file)) | |
228 if (__grabdemo) | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
229 __n = ""; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
230 __nmax = -1; |
5589 | 231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 endif |
5908 | 244 fflush (__fid); |
6494 | 245 if (nargout > 0) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
246 if (nargout == 1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
247 __n = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
248 else |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
249 __n = __nmax = 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
250 endif |
6494 | 251 endif |
5589 | 252 endif |
6494 | 253 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
|
254 fclose (__fid); |
6494 | 255 endif |
5589 | 256 return; |
257 endif | |
258 | |
8506 | 259 ## Grab the test code from the file. |
5589 | 260 __body = __extract_test_code (__file); |
261 | |
262 if (isempty (__body)) | |
263 if (__grabdemo) | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
264 __n = ""; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
265 __nmax = []; |
5589 | 266 else |
6494 | 267 fprintf (__fid, "%s%s has no tests available\n", __signal_empty, __file); |
5908 | 268 fflush (__fid); |
6494 | 269 if (nargout > 0) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
270 if (nargout == 1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
271 __n = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
272 else |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
273 __n = __nmax = 0; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
274 endif |
6494 | 275 endif |
5589 | 276 endif |
6494 | 277 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
|
278 fclose (__fid); |
6494 | 279 endif |
5589 | 280 return; |
281 else | |
8506 | 282 ## Add a dummy comment block to the end for ease of indexing. |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
283 if (__body(end) == "\n") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
284 __body = ["\n" __body "#"]; |
5589 | 285 else |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
286 __body = ["\n" __body "\n#"]; |
5589 | 287 endif |
288 endif | |
289 | |
8506 | 290 ## Chop it up into blocks for evaluation. |
6494 | 291 __lineidx = find (__body == "\n"); |
292 __blockidx = __lineidx(find (! isspace (__body(__lineidx+1))))+1; | |
5589 | 293 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
294 ## Ready to start tests. |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
295 ## 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:
18857
diff
changeset
|
296 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
|
297 disp ([__signal_file, __file]); |
5589 | 298 endif |
299 | |
25521
a87b4dca2ce3
test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents:
25216
diff
changeset
|
300 ## Track file descriptor leaks |
25525
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
301 __fid_list_orig = fopen ("all"); |
25521
a87b4dca2ce3
test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents:
25216
diff
changeset
|
302 |
25522
90c8325c14be
test.m: Warn if %!tests leak variables in to base workspace.
Rik <rik@octave.org>
parents:
25521
diff
changeset
|
303 ## Track variable leaks |
25525
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
304 __base_variables_orig = evalin ("base", "who"); |
25555
364a31cd4c4f
test.m: Don't emit warning about leaking the automatic variable "ans".
Rik <rik@octave.org>
parents:
25525
diff
changeset
|
305 ## Add automatic variable "ans" which may not have been created yet. |
364a31cd4c4f
test.m: Don't emit warning about leaking the automatic variable "ans".
Rik <rik@octave.org>
parents:
25525
diff
changeset
|
306 __base_variables_orig{end+1} = "ans"; |
25525
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
307 |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
308 ## Track variable leaks |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
309 __global_variables_orig = who ("global"); |
25522
90c8325c14be
test.m: Warn if %!tests leak variables in to base workspace.
Rik <rik@octave.org>
parents:
25521
diff
changeset
|
310 |
8506 | 311 ## Assume all tests will pass. |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
312 __all_success = true; |
5589 | 313 |
8506 | 314 ## Process each block separately, initially with no shared variables. |
5589 | 315 __tests = __successes = 0; |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
316 __xfail = __xbug = __xskip = __xrtskip = __xregression = 0; |
5589 | 317 __shared = " "; |
318 __shared_r = " "; | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
319 __clearfcn = ""; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
320 for __i = 1:numel (__blockidx)-1 |
5589 | 321 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
322 ## 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:
19402
diff
changeset
|
323 orig_wstate = warning (); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
324 unwind_protect |
5589 | 325 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
326 ## Extract the block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
327 __block = __body(__blockidx(__i):__blockidx(__i+1)-2); |
5589 | 328 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
329 ## 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:
19402
diff
changeset
|
330 if (__verbose > 0) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
331 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:
19402
diff
changeset
|
332 fflush (__fid); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
333 endif |
5589 | 334 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
335 ## 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:
19402
diff
changeset
|
336 __idx = find (! isletter (__block)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
337 if (isempty (__idx)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
338 __type = __block; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
339 __code = ""; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
340 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
341 __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:
19402
diff
changeset
|
342 __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:
19402
diff
changeset
|
343 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
344 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
345 ## Assume the block will succeed. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
346 __success = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
347 __msg = []; |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
348 __istest = false; |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
349 __isxtest = false; |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
350 __bug_id = ""; |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
351 __fixed_bug = false; |
5589 | 352 |
8506 | 353 ### DEMO |
354 | |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
355 ## 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:
19402
diff
changeset
|
356 ## 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:
19402
diff
changeset
|
357 ## 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:
19402
diff
changeset
|
358 ## 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:
19402
diff
changeset
|
359 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
360 __isdemo = strcmp (__type, "demo"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
361 if (__grabdemo || __isdemo) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
362 if (__grabdemo && __isdemo) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
363 if (isempty (__demo_code)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
364 __demo_code = __code; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
365 __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:
19402
diff
changeset
|
366 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
367 __demo_code = [__demo_code, __code]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
368 __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:
19402
diff
changeset
|
369 endif |
5589 | 370 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
371 elseif (__rundemo && __isdemo) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
372 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
373 ## 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:
19402
diff
changeset
|
374 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:
19402
diff
changeset
|
375 __test__; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
376 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:
19402
diff
changeset
|
377 catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
378 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
379 __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:
19402
diff
changeset
|
380 end_try_catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
381 clear __test__; |
5589 | 382 |
10549 | 383 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
384 ## Code already processed. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
385 __code = ""; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
386 |
8506 | 387 ### SHARED |
388 | |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
389 elseif (strcmp (__type, "shared")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
390 ## Separate initialization code from variables. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
391 __idx = find (__code == "\n"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
392 if (isempty (__idx)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
393 __vars = __code; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
394 __code = ""; |
10549 | 395 else |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
396 __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:
19402
diff
changeset
|
397 __code = __code (__idx(1):length (__code)); |
10549 | 398 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
399 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
400 ## Strip comments off the variables. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
401 __idx = find (__vars == "%" | __vars == "#"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
402 if (! isempty (__idx)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
403 __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:
19402
diff
changeset
|
404 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
405 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
406 ## Assign default values to variables. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
407 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
408 __vars = deblank (__vars); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
409 if (! isempty (__vars)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
410 eval ([strrep(__vars, ",", "=[];"), "=[];"]); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
411 __shared = __vars; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
412 __shared_r = ["[ " __vars "] = "]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
413 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
414 __shared = " "; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
415 __shared_r = " "; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
416 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
417 catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
418 ## 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:
19402
diff
changeset
|
419 __code = ""; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
420 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
421 __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:
19402
diff
changeset
|
422 end_try_catch |
5589 | 423 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
424 ## 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
|
425 |
8506 | 426 ### FUNCTION |
427 | |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
428 elseif (strcmp (__type, "function")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
429 persistent __fn = 0; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
430 __name_position = function_name (__block); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
431 if (isempty (__name_position)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
432 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
433 __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:
19402
diff
changeset
|
434 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
435 __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:
19402
diff
changeset
|
436 __code = __block; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
437 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
438 eval (__code); # Define the function |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
439 __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:
19402
diff
changeset
|
440 catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
441 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
442 __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:
19402
diff
changeset
|
443 end_try_catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
444 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
445 __code = ""; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
446 |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
447 ### ENDFUNCTION |
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
448 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
449 elseif (strcmp (__type, "endfunction")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
450 ## 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:
19402
diff
changeset
|
451 ## There is no processing to be done here, just skip to next block. |
10549 | 452 __code = ""; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
453 |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
454 ### ASSERT |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
455 ### ASSERT <BUG-ID> |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
456 ### FAIL |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
457 ### FAIL <BUG-ID> |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
458 ### |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
459 ### BUG-ID is a bug number from the bug tracker. A prefix of '*' |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
460 ### indicates a bug that has been fixed. Tests that fail for fixed |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
461 ### bugs are reported as regressions. |
5589 | 462 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
463 elseif (strcmp (__type, "assert") || strcmp (__type, "fail")) |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
464 [__bug_id, __code, __fixed_bug] = getbugid (__code); |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
465 if (isempty (__bug_id)) |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
466 __istest = true; |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
467 else |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
468 __isxtest = true; |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
469 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
470 ## Put the keyword back on the code. |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
471 __code = [__type __code]; |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
472 ## 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
|
473 |
8506 | 474 ### ERROR/WARNING |
475 | |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
476 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:
19402
diff
changeset
|
477 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
478 __iswarning = strcmp (__type, "warning"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
479 [__pattern, __id, __code] = getpattern (__code); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
480 if (__id) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
481 __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
|
482 else |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
483 if (! strcmp (__pattern, '.')) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
484 __patstr = ["<" __pattern ">"]; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
485 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
486 __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:
19402
diff
changeset
|
487 endif |
16976
13affad7347c
test.m: Use the syntax "BLOCK_NAME failed" for error/warnings blocks.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
488 endif |
5589 | 489 try |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
490 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:
19402
diff
changeset
|
491 __shared, __code)); |
5589 | 492 catch |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
493 __success = false; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
494 __msg = [__signal_fail "test failed: syntax error\n" lasterr()]; |
5589 | 495 end_try_catch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
496 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
497 if (__success) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
498 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
499 __warnstate = warning ("query", "quiet"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
500 warning ("on", "quiet"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
501 ## 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:
19402
diff
changeset
|
502 lasterr (""); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
503 lastwarn (""); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
504 try |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
505 eval (sprintf ("__test__(%s);", __shared)); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
506 if (! __iswarning) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
507 __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:
19402
diff
changeset
|
508 "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:
19402
diff
changeset
|
509 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
510 if (! isempty (__id)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
511 [~, __err] = lastwarn (); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
512 __mismatch = ! strcmp (__err, __id); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
513 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
514 __err = trimerr (lastwarn (), "warning"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
515 __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:
19402
diff
changeset
|
516 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
517 warning (__warnstate.state, "quiet"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
518 if (isempty (__err)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
519 __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:
19402
diff
changeset
|
520 "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:
19402
diff
changeset
|
521 elseif (__mismatch) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
522 __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:
19402
diff
changeset
|
523 "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:
19402
diff
changeset
|
524 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
525 __success = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
526 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
527 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
528 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
529 catch |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
530 if (! isempty (__id)) |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
531 [~, __err] = lasterr (); |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
532 __mismatch = ! strcmp (__err, __id); |
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
533 else |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
534 __err = trimerr (lasterr (), "error"); |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
535 __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
|
536 endif |
7028 | 537 warning (__warnstate.state, "quiet"); |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
538 if (__iswarning) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
539 __msg = [__signal_fail "warning failed.\n" ... |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
540 "Expected warning " __patstr ... |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
541 ", 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
|
542 elseif (__mismatch) |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
543 __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:
19402
diff
changeset
|
544 "Expected " __patstr ", but got <" __err ">\n"]; |
7028 | 545 else |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
546 __success = true; |
7028 | 547 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
548 end_try_catch |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
549 clear __test__; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
550 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
551 ## Code already processed. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
552 __code = ""; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
553 |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
554 ### TESTIF HAVE_FEATURE |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
555 ### TESTIF HAVE_FEATURE ; RUNTIME_CONDITION |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
556 ### TESTIF HAVE_FEATURE <BUG-ID> |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
557 ### TESTIF HAVE_FEATURE ; RUNTIME_CONDITION <BUG-ID> |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
558 ### |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
559 ### HAVE_FEATURE is a comma- or whitespace separated list of |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
560 ### macro names that may be checked with __have_feature__. |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
561 ### |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
562 ### RUNTIME_CONDITION is an expression to evaluate to check |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
563 ### whether some condition is met when the test is executed. For |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
564 ### example, have_window_system. |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
565 ### |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
566 ### BUG-ID is a bug number from the bug tracker. A prefix of '*' |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
567 ### indicates a bug that has been fixed. Tests that fail for fixed |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
568 ### bugs are reported as regressions. |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
569 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
570 elseif (strcmp (__type, "testif")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
571 __e = regexp (__code, '.$', 'lineanchors', 'once'); |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
572 ## Strip any comment and bug-id from testif line before |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
573 ## looking for features |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
574 __feat_line = strtok (__code(1:__e), '#%'); |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
575 __idx1 = index (__feat_line, "<"); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
576 if (__idx1) |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
577 __tmp = __feat_line(__idx1+1:end); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
578 __idx2 = index (__tmp, ">"); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
579 if (__idx2) |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
580 __bug_id = __tmp(1:__idx2-1); |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
581 if (strncmp (__bug_id, "*", 1)) |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
582 __bug_id = __bug_id(2:end); |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
583 __fixed_bug = true; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
584 endif |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
585 __feat_line = __feat_line(1:__idx1-1); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
586 endif |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
587 endif |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
588 __idx = index (__feat_line, ";"); |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
589 if (__idx) |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
590 __runtime_feat_test = __feat_line(__idx+1:end); |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
591 __feat_line = __feat_line(1:__idx-1); |
23396
945b53af4655
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23363
diff
changeset
|
592 else |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
593 __runtime_feat_test = ""; |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
594 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
595 __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:
19402
diff
changeset
|
596 __feat = strrep (__feat, "HAVE_", ""); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
597 __have_feat = __have_feature__ (__feat); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
598 if (__have_feat) |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
599 if (isempty (__runtime_feat_test) || eval (__runtime_feat_test)) |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
600 if (isempty (__bug_id)) |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
601 __istest = true; |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
602 else |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
603 __isxtest = true; |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
604 endif |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
605 __code = __code(__e + 1 : end); |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
606 else |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
607 __xrtskip += 1; |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
608 __code = ""; # Skip the code. |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
609 __msg = [__signal_skip "skipped test (runtime test)\n"]; |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
610 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
611 else |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20726
diff
changeset
|
612 __xskip += 1; |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
613 __code = ""; # Skip the code. |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
614 __msg = [__signal_skip "skipped test (missing feature)\n"]; |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
615 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
616 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
617 ### TEST |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
618 ### TEST <BUG-ID> |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
619 ### |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
620 ### BUG-ID is a bug number from the bug tracker. A prefix of '*' |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
621 ### indicates a bug that has been fixed. Tests that fail for fixed |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
622 ### bugs are reported as regressions. |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
623 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
624 elseif (strcmp (__type, "test")) |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
625 [__bug_id, __code, __fixed_bug] = getbugid (__code); |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
626 if (! isempty (__bug_id)) |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
627 __isxtest = true; |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
628 else |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
629 __istest = true; |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
630 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
631 ## Code will be evaluated below. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
632 |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
633 ### XTEST |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
634 ### XTEST <BUG-ID> |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
635 ### |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
636 ### BUG-ID is a bug number from the bug tracker. A prefix of '*' |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
637 ### indicates a bug that has been fixed. Tests that fail for fixed |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
638 ### bugs are reported as regressions. |
5589 | 639 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
640 elseif (strcmp (__type, "xtest")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
641 __isxtest = true; |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
642 [__bug_id, __code, __fixed_bug] = getbugid (__code); |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
643 ## Code will be evaluated below. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
644 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
645 ### Comment block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
646 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
647 elseif (strcmp (__block(1:1), "#")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
648 __code = ""; # skip the code |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
649 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
650 ### Unknown block. |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
651 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
652 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
653 __istest = true; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
654 __success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
655 __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:
19402
diff
changeset
|
656 __code = ""; # skip the code |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
657 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
658 |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
659 ## 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:
19402
diff
changeset
|
660 if (! isempty(__code)) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
661 try |
24590
b6818c2b0483
test.m: Remove requirement to avoid nested functions in %!test blocks.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
662 eval (sprintf ("function %s__test__(%s)\n%s\nendfunction", |
b6818c2b0483
test.m: Remove requirement to avoid nested functions in %!test blocks.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
663 __shared_r, __shared, __code)); |
b6818c2b0483
test.m: Remove requirement to avoid nested functions in %!test blocks.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
664 eval (sprintf ("%s__test__(%s);", __shared_r, __shared)); |
10549 | 665 catch |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
666 if (isempty (lasterr ())) |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
667 error ("test: empty error text, probably Ctrl-C --- aborting"); |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
668 else |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
669 __success = false; |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
670 if (__isxtest) |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
671 if (isempty (__bug_id)) |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
672 if (__fixed_bug) |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
673 __xregression += 1; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
674 __msg = "regression"; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
675 else |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
676 __xfail += 1; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
677 __msg = "known failure"; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
678 endif |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
679 else |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
680 if (__fixed_bug) |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
681 __xregression += 1; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
682 else |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
683 __xbug += 1; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
684 endif |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
685 if (all (isdigit (__bug_id))) |
25024
3c817af70eed
maint: use https for all Octave project URLs
Mike Miller <mtmiller@octave.org>
parents:
24590
diff
changeset
|
686 __bug_id = ["https://octave.org/testfailure/?" __bug_id]; |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
687 endif |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
688 if (__fixed_bug) |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
689 __msg = ["regression: " __bug_id]; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
690 else |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
691 __msg = ["known bug: " __bug_id]; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
692 endif |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
693 endif |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
694 else |
22379
805442f0674b
* test.m: Fix doubled "!!!!!" marker in failure messages.
John W. Eaton <jwe@octave.org>
parents:
22376
diff
changeset
|
695 __msg = "test failed"; |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
696 endif |
22379
805442f0674b
* test.m: Fix doubled "!!!!!" marker in failure messages.
John W. Eaton <jwe@octave.org>
parents:
22376
diff
changeset
|
697 __msg = [__signal_fail __msg "\n" lasterr()]; |
5589 | 698 endif |
10549 | 699 end_try_catch |
700 clear __test__; | |
5589 | 701 endif |
702 | |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
703 ## 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:
19402
diff
changeset
|
704 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:
19402
diff
changeset
|
705 ## 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:
19402
diff
changeset
|
706 if (__verbose < 1) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
707 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:
19402
diff
changeset
|
708 fflush (__fid); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
709 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
710 fprintf (__fid, "%s\n", __msg); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
711 ## Show the variable context. |
21460
236163306596
* test.m: Omit details about known test failures (bug #47444).
John W. Eaton <jwe@octave.org>
parents:
21436
diff
changeset
|
712 if (! strcmp (__type, "error") |
236163306596
* test.m: Omit details about known test failures (bug #47444).
John W. Eaton <jwe@octave.org>
parents:
21436
diff
changeset
|
713 && ! strcmp (__type, "testif") |
236163306596
* test.m: Omit details about known test failures (bug #47444).
John W. Eaton <jwe@octave.org>
parents:
21436
diff
changeset
|
714 && ! strcmp (__type, "xtest") |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
715 && ! all (__shared == " ")) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
716 fputs (__fid, "shared variables "); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
717 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
|
718 endif |
20196
10414d7a25f8
test.m: Show error message and shared variables section in pager (bug #45007).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20023
diff
changeset
|
719 fflush (__fid); |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
720 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
721 if (! __success && ! __isxtest) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
722 __all_success = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
723 ## 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:
19402
diff
changeset
|
724 if (! __batch || nargout == 1) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
725 if (nargout > 0) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
726 if (nargout == 1) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
727 __n = false; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
728 else |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
729 __n = __nmax = 0; |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
730 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
731 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
732 if (__close_fid) |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
733 fclose (__fid); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
734 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
735 return; |
6728 | 736 endif |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
737 endif |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
738 __tests += (__istest || __isxtest); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
739 __successes += __success && (__istest || __isxtest); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
740 |
19444
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
741 unwind_protect_cleanup |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
742 warning ("off", "all"); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
743 warning (orig_wstate); |
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19402
diff
changeset
|
744 end_unwind_protect |
5589 | 745 endfor |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
746 |
25525
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
747 ## Clear any functions created during test run. |
26650
39c2c387caba
use onCleanup to clear functions used in tests
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
748 __clear_functions = onCleanup (@() eval (__clearfcn, "")); |
5589 | 749 |
25525
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
750 ## Verify test file did not leak file descriptors. |
25521
a87b4dca2ce3
test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents:
25216
diff
changeset
|
751 if (! isempty (setdiff (fopen ("all"), __fid_list_orig))) |
a87b4dca2ce3
test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents:
25216
diff
changeset
|
752 warning ("test: file %s leaked file descriptors\n", __file); |
a87b4dca2ce3
test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents:
25216
diff
changeset
|
753 endif |
a87b4dca2ce3
test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents:
25216
diff
changeset
|
754 |
25525
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
755 ## Verify test file did not leak variables in to base workspace. |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
756 __leaked_vars = setdiff (evalin ("base", "who"), __base_variables_orig); |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
757 if (! isempty (__leaked_vars)) |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
758 warning ("test: file %s leaked variables to base workspace:%s\n", |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
759 __file, sprintf (" %s", __leaked_vars{:})); |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
760 endif |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
761 |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
762 ## Verify test file did not leak global variables. |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
763 __leaked_vars = setdiff (who ("global"), __global_variables_orig); |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
764 if (! isempty (__leaked_vars)) |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
765 warning ("test: file %s leaked global variables:%s\n", |
48a9bd2d0a20
also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents:
25522
diff
changeset
|
766 __file, sprintf (" %s", __leaked_vars{:})); |
25522
90c8325c14be
test.m: Warn if %!tests leak variables in to base workspace.
Rik <rik@octave.org>
parents:
25521
diff
changeset
|
767 endif |
90c8325c14be
test.m: Warn if %!tests leak variables in to base workspace.
Rik <rik@octave.org>
parents:
25521
diff
changeset
|
768 |
5589 | 769 if (nargout == 0) |
23363
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
770 if (__tests || __xfail || __xbug || __xskip || __xrtskip) |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
771 if (__xfail || __xbug) |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
772 if (__xfail && __xbug) |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
773 printf ("PASSES %d out of %d test%s (%d known failure%s; %d known bug%s)\n", |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
774 __successes, __tests, ifelse (__tests > 1, "s", ""), |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
775 __xfail, ifelse (__xfail > 1, "s", ""), |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
776 __xbug, ifelse (__xbug > 1, "s", "")); |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
777 elseif (__xfail) |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
778 printf ("PASSES %d out of %d test%s (%d known failure%s)\n", |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
779 __successes, __tests, ifelse (__tests > 1, "s", ""), |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
780 __xfail, ifelse (__xfail > 1, "s", "")); |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
781 elseif (__xbug) |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
782 printf ("PASSES %d out of %d test%s (%d known bug%s)\n", |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
783 __successes, __tests, ifelse (__tests > 1, "s", ""), |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
784 __xbug, ifelse (__xbug > 1, "s", "")); |
0cd0db82123d
distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents:
23280
diff
changeset
|
785 endif |
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
|
786 else |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
787 printf ("PASSES %d out of %d test%s\n", __successes, __tests, |
16992
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
788 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
|
789 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
|
790 if (__xskip) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
791 printf ("Skipped %d test%s due to missing features\n", __xskip, |
16992
4e8f49304059
test.m: Use correct English singular/plural in reporting messages (bug #39164).
Rafael Laboissiere <rafael@laboissiere.net>
parents:
16977
diff
changeset
|
792 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
|
793 endif |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
794 if (__xrtskip) |
23280
9a0e33470da5
use "run-time condition" consistently in previous change
John W. Eaton <jwe@octave.org>
parents:
23279
diff
changeset
|
795 printf ("Skipped %d test%s due to run-time conditions\n", __xrtskip, |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
796 ifelse (__xrtskip > 1, "s", "")); |
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
797 endif |
6730 | 798 else |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
799 printf ("%s%s has no tests available\n", __signal_empty, __file); |
7242 | 800 endif |
5589 | 801 elseif (__grabdemo) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
802 __n = __demo_code; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
803 __nmax = __demo_idx; |
6494 | 804 elseif (nargout == 1) |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
805 __n = __all_success; |
5589 | 806 else |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
807 __n = __successes; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
808 __nmax = __tests; |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
809 __nxfail = __xfail; |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
810 __nbug = __xbug; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
811 __nskip = __xskip; |
23279
67d741321e21
allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
812 __nrtskip = __xrtskip; |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
813 __nregression = __xregression; |
5589 | 814 endif |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
815 |
5589 | 816 endfunction |
817 | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
818 |
8506 | 819 ## Create structure with fieldnames the name of the input variables. |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
820 function s = var2struct (varargin) |
6494 | 821 for i = 1:nargin |
26214
c0ac6fc191d7
allow inputname to return non-ID arguments (bug #55213)
John W. Eaton <jwe@octave.org>
parents:
26208
diff
changeset
|
822 s.(inputname (i, true)) = varargin{i}; |
5589 | 823 endfor |
824 endfunction | |
825 | |
8506 | 826 ## Find [start,end] of fn in 'function [a,b] = fn'. |
6494 | 827 function pos = function_name (def) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
828 |
5589 | 829 pos = []; |
830 | |
8506 | 831 ## Find the end of the name. |
6494 | 832 right = find (def == "(", 1); |
833 if (isempty (right)) | |
834 return; | |
835 endif | |
836 right = find (def(1:right-1) != " ", 1, "last"); | |
5589 | 837 |
8506 | 838 ## Find the beginning of the name. |
6494 | 839 left = max ([find(def(1:right)==" ", 1, "last"), ... |
10549 | 840 find(def(1:right)=="=", 1, "last")]); |
6494 | 841 if (isempty (left)) |
842 return; | |
843 endif | |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20726
diff
changeset
|
844 left += 1; |
5589 | 845 |
8506 | 846 ## Return the end points of the name. |
6494 | 847 pos = [left, right]; |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
848 |
5589 | 849 endfunction |
850 | |
8506 | 851 ## Strip <pattern> from '<pattern> code'. |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
852 ## Optionally also handles 'id=ID code' |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
853 function [pattern, id, rest] = getpattern (str) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
854 |
6494 | 855 pattern = "."; |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
856 id = []; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
857 rest = str; |
6494 | 858 str = trimleft (str); |
859 if (! isempty (str) && str(1) == "<") | |
860 close = index (str, ">"); | |
861 if (close) | |
5589 | 862 pattern = str(2:close-1); |
863 rest = str(close+1:end); | |
864 endif | |
10398
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
865 elseif (strncmp (str, "id=", 3)) |
f7cf1a53e1c5
support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents:
10130
diff
changeset
|
866 [id, rest] = strtok (str(4:end)); |
5589 | 867 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
868 |
5589 | 869 endfunction |
870 | |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
871 ## Strip <bug-id> from '<pattern> code'. |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
872 function [bug_id, rest, fixed] = getbugid (str) |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
873 |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
874 bug_id = ""; |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
875 rest = str; |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
876 fixed = false; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
877 |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
878 str = trimleft (str); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
879 if (! isempty (str) && str(1) == "<") |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
880 close = index (str, ">"); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
881 if (close) |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
882 bug_id = str(2:close-1); |
23571
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
883 if (strncmp (bug_id, "*", 1)) |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
884 bug_id = bug_id(2:end); |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
885 fixed = true; |
b6144e6dda9e
allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents:
23406
diff
changeset
|
886 endif |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
887 rest = str(close+1:end); |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
888 endif |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
889 endif |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
890 |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
891 endfunction |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
892 |
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
893 |
8506 | 894 ## Strip '.*prefix:' from '.*prefix: msg\n' and strip trailing blanks. |
6494 | 895 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
|
896 idx = index (msg, [prefix ":"]); |
6494 | 897 if (idx > 0) |
898 msg(1:idx+length(prefix)) = []; | |
899 endif | |
16977
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
900 msg = strtrim (msg); |
5589 | 901 endfunction |
902 | |
8506 | 903 ## Strip leading blanks from string. |
6494 | 904 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
|
905 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
|
906 str = str(idx:end); |
5589 | 907 endfunction |
908 | |
909 function body = __extract_test_code (nm) | |
910 fid = fopen (nm, "rt"); | |
19402 | 911 body = ""; |
5589 | 912 if (fid >= 0) |
19291
64f034147e9a
test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
913 while (ischar (ln = fgets (fid))) |
64f034147e9a
test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
914 if (strncmp (ln, "%!", 2)) |
64f034147e9a
test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
915 body = [body, ln(3:end)]; |
5589 | 916 endif |
917 endwhile | |
918 fclose (fid); | |
919 endif | |
920 endfunction | |
921 | |
16977
0d5d3e53255f
test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents:
16976
diff
changeset
|
922 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
923 ## 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
|
924 %!shared msg1,msg2 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
925 %! msg1 = "C must be a vector"; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
926 %! msg2 = "C and R must be vectors"; |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
927 %!fail ("toeplitz ([])", msg1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
928 %!fail ("toeplitz ([1,2;3,4])", msg1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
929 %!fail ("toeplitz ([1,2],[])", msg2) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
930 %!fail ("toeplitz ([1,2],[1,2;3,4])", msg2) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
931 %!fail ("toeplitz ([1,2;3,4],[1,2])", msg2) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
932 %!test fail ("toeplitz", "Invalid call to toeplitz") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
933 %!fail ("toeplitz (1, 2, 3)", "Invalid call to toeplitz") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
934 %!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:
18857
diff
changeset
|
935 %!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:
18857
diff
changeset
|
936 %!demo toeplitz ([1,2,3,4],[1,5,6]) |
5589 | 937 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
938 ## example from kron |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
939 %!error <Invalid call to kron> kron () |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
940 %!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
|
941 %!test assert (isempty (kron ([], rand (3, 4)))) |
5589 | 942 %!test assert (isempty (kron (rand (3, 4), []))) |
943 %!test assert (isempty (kron ([], []))) | |
944 %!shared A, B | |
945 %!test | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
946 %! A = [1, 2, 3; 4, 5, 6]; |
5589 | 947 %! B = [1, -1; 2, -2]; |
948 %!assert (size (kron (zeros (3, 0), A)), [ 3*rows(A), 0 ]) | |
949 %!assert (size (kron (zeros (0, 3), A)), [ 0, 3*columns(A) ]) | |
950 %!assert (size (kron (A, zeros (3, 0))), [ 3*rows(A), 0 ]) | |
951 %!assert (size (kron (A, zeros (0, 3))), [ 0, 3*columns(A) ]) | |
952 %!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
|
953 %!assert (kron (pi, A), pi*A) |
5589 | 954 %!assert (kron (A, e), e*A) |
955 %!assert (kron ([1, 2, 3], A), [ A, 2*A, 3*A ]) | |
956 %!assert (kron ([1; 2; 3], A), [ A; 2*A; 3*A ]) | |
957 %!assert (kron ([1, 2; 3, 4], A), [ A, 2*A; 3*A, 4*A ]) | |
958 %!test | |
959 %! 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]; | |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
960 %! assert (kron (A, B), res); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
961 %!shared # clear out shared variables |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
962 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
963 ## Now verify test() itself |
5589 | 964 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
965 ## Test 'fail' keyword |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
966 %!fail ("test", "Invalid call to test") # no args, generates usage() |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
967 %!fail ("test (1,2,3,4)", "usage.*test") # too many args, generates usage() |
20835
14cd86258b3d
use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents:
20735
diff
changeset
|
968 %!fail ('test ("test", "invalid")', "unknown flag") # incorrect args |
5589 | 969 %!fail ('garbage','garbage.*undefined') # usage on nonexistent function should be |
970 | |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
971 ## Test 'error' keyword |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
972 %!error test # no args, generates usage() |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
973 %!error test (1,2,3,4) # too many args, generates usage() |
20835
14cd86258b3d
use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents:
20735
diff
changeset
|
974 %!error <unknown flag> test ("test", "invalid"); # incorrect args |
14cd86258b3d
use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents:
20735
diff
changeset
|
975 %!error test ("test", "invalid"); # test without pattern |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
976 %!error <'garbage' undefined> garbage; # usage on nonexistent function is error |
5589 | 977 |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
978 ## Test 'warning' keyword |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
979 %!warning warning ("warning message"); # no pattern |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
980 %!warning <warning message> warning ("warning message"); # with pattern |
5589 | 981 |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
982 ## Test 'shared' keyword |
5589 | 983 %!shared a # create a shared variable |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
984 %!test a = 3; # assign to a shared variable |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
985 %!test assert (a, 3) # variable should equal 3 |
5589 | 986 %!shared b,c # replace shared variables |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
987 %!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
|
988 %!test assert (isempty (b)); # variables start off empty |
5589 | 989 %!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
|
990 %!test assert (isempty (a)); # value is empty even if it had a previous value |
5589 | 991 %!test a=1; b=2; c=3; # give values to all variables |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
992 %!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:
18857
diff
changeset
|
993 %!test c=6; # update a value |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
994 %!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:
18857
diff
changeset
|
995 %!shared # clear all shared variables |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
996 %!test assert (! exist ("a", "var")) # show that they are cleared |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
997 %!shared a,b,c # support for initializer shorthand |
5589 | 998 %! a=1; b=2; c=4; |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
999 %!shared # clear all shared variables for remainder of tests |
5589 | 1000 |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1001 ## 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
|
1002 %!function x = __test_a (y) |
22627
7b190a2f11cb
maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents:
22379
diff
changeset
|
1003 %! x = 2*y; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
1004 %!endfunction |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1005 %!assert (__test_a (2), 4) # Test a test function |
5589 | 1006 |
1007 %!function __test_a (y) | |
22627
7b190a2f11cb
maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents:
22379
diff
changeset
|
1008 %! x = 2*y; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
1009 %!endfunction |
5589 | 1010 %!test |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1011 %! __test_a (2); # Test a test function with no return value |
5589 | 1012 |
1013 %!function [x,z] = __test_a (y) | |
22627
7b190a2f11cb
maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents:
22379
diff
changeset
|
1014 %! x = 2*y; |
7b190a2f11cb
maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents:
22379
diff
changeset
|
1015 %! z = 3*y; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
12687
diff
changeset
|
1016 %!endfunction |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1017 %!test |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1018 %! [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
|
1019 %! assert (x,6); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1020 %! assert (z,9); |
5589 | 1021 |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1022 ## Test 'assert' keyword |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1023 %!assert (isempty ([])) # support for test assert shorthand |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1024 %!assert (size (ones (1,2,3)), [1 2 3]) |
5589 | 1025 |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1026 ## Test 'demo' keyword |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1027 %!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
|
1028 %! 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
|
1029 %! plot (t,x); |
5589 | 1030 %! % you should now see a sine wave in your figure window |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1031 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1032 %!demo a=3 # single line demo blocks work too |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1033 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1034 %!test |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1035 %! [code, idx] = test ("test", "grabdemo"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1036 %! assert (numel (idx), 4); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1037 %! assert (code(idx(3):end), |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1038 %! " a=3 # single line demo blocks work too"); |
5589 | 1039 |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1040 ## Test 'testif' keyword |
20835
14cd86258b3d
use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents:
20735
diff
changeset
|
1041 %!testif HAVE_INVALID_FEATURE |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1042 %! error ("testif executed code despite not having feature"); |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1043 |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1044 ## Test 'xtest' keyword |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1045 %!xtest |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1046 %! assert (1, 1); # Test passes |
25216
b72972ab83f1
test: Add bug IDs to failing %!xtest blocks.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1047 %!xtest <53613> |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1048 %! assert (0, 1); # Test fails |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1049 |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21460
diff
changeset
|
1050 ## Test comment block. It can contain anything. |
5589 | 1051 %!## |
1052 %! 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
|
1053 %! and it stays as a comment even through continuation lines |
5589 | 1054 %! which means that it works well with commenting out whole tests |
1055 | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1056 ## Test test() input validation |
19048
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1057 %!error <NAME must be a string> test (1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1058 %!error <second argument must be a string> test ("ls", 1) |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1059 %!error test ([], "normal") |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1060 |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1061 ## All of the following tests should fail. These tests should |
ec28b7216501
test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
1062 ## be disabled unless you are developing test() since users don't |
22376
3473246a824e
allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1063 ## like to be presented with known failures. |
20929
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1064 ## %!test error("---------Failure tests. Use test('test','verbose',1)"); |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1065 ## %!test assert([a,b,c],[1,3,6]); # variables have wrong values |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1066 ## %!invalid # unknown block type |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1067 ## %!error toeplitz([1,2,3]); # correct usage |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1068 ## %!test syntax errors) # syntax errors fail properly |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1069 ## %!shared garbage in # variables must be comma separated |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1070 ## %!error syntax++error # error test fails on syntax errors |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1071 ## %!error "succeeds."; # error test fails if code succeeds |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1072 ## %!error <wrong pattern> error("message") # error pattern must match |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1073 ## %!demo with syntax error # syntax errors in demo fail properly |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1074 ## %!shared a,b,c |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1075 ## %!demo # shared variables not available in demo |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1076 ## %! assert (exist ("a", "var")) |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1077 ## %!error |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1078 ## %! test ('/etc/passwd'); |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1079 ## %! test ("nonexistent file"); |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21634
diff
changeset
|
1080 ## %! ## These don't signal an error, so the test for an error fails. Note |
20929
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1081 ## %! ## that the call doesn't reference the current fid (it is unavailable), |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1082 ## %! ## so of course the informational message is not printed in the log. |