annotate scripts/testfun/test.m @ 31191:bb9d776eafac stable

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