annotate scripts/testfun/test.m @ 29359:7854d5752dd2

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 10:10:40 -0500
parents 495af8064428 0a5b15007766
children 76269aa97398
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 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29036
diff changeset
3 ## Copyright (C) 2005-2021 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
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 28721
diff changeset
140 if (nargin < 1)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
141 print_usage ();
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
142 elseif (! isempty (__name) && ! ischar (__name))
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
143 error ("test: NAME must be a string");
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
144 elseif (! ischar (__flag))
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
145 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
146 elseif (isempty (__name) && (nargin != 3 || ! strcmp (__flag, "explain")))
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6024
diff changeset
147 print_usage ();
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
148 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
149
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
150 ## 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
151 __logfile = ! isempty (__fid);
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
152 __batch = __logfile || nargout > 0;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
153 __close_fid = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
154 if (__logfile)
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
155 if (ischar (__fid))
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
156 __fname = __fid;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
157 __fid = fopen (__fname, "wt");
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
158 if (__fid < 0)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
159 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
160 endif
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
161 __close_fid = true;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
162 endif
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
163 if (! strcmp (__flag, "explain"))
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
164 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
165 fflush (__fid);
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
166 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
167 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
168 __fid = stdout;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
169 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
170
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
171 if (strcmp (__flag, "normal"))
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
172 __grabdemo = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
173 __rundemo = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
174 if (__logfile)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
175 __verbose = 1;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
176 elseif (__batch)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
177 __verbose = -1;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
178 else
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
179 __verbose = 0;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
180 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
181 elseif (strcmp (__flag, "quiet"))
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
182 __grabdemo = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
183 __rundemo = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
184 __verbose = -1;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
185 elseif (strcmp (__flag, "verbose"))
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
186 __grabdemo = false;
20023
6babcfbe1a0a test.m: Don't run interactive demo blocks in batch mode.
Rik <rik@octave.org>
parents: 19833
diff changeset
187 __rundemo = ! __batch;
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
188 __verbose = 1;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
189 elseif (strcmp (__flag, "grabdemo"))
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
190 __grabdemo = true;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
191 __rundemo = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
192 __verbose = -1;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
193 __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
194 __demo_idx = [];
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
195 elseif (strcmp (__flag, "explain"))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
196 fprintf (__fid, "# %s new test file\n", __signal_file);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 fflush (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
207 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
208 fclose (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
209 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
210 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
211 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10615
diff changeset
212 error ("test: unknown flag '%s'", __flag);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
213 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
214
29036
b71672c8d337 Let "test" execute BISTs that were extracted on pkg install (bug #41298).
Oliver Heimlich <oheim@posteo.de>
parents: 28720
diff changeset
215 ## Locate the file with tests.
6249
c507206c45bc [project @ 2007-01-22 20:00:06 by jwe]
jwe
parents: 6046
diff changeset
216 __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
217 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
218 ".cxx-tst"}
b71672c8d337 Let "test" execute BISTs that were extracted on pkg install (bug #41298).
Oliver Heimlich <oheim@posteo.de>
parents: 28720
diff changeset
219 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
220 break;
b71672c8d337 Let "test" execute BISTs that were extracted on pkg install (bug #41298).
Oliver Heimlich <oheim@posteo.de>
parents: 28720
diff changeset
221 endif
b71672c8d337 Let "test" execute BISTs that were extracted on pkg install (bug #41298).
Oliver Heimlich <oheim@posteo.de>
parents: 28720
diff changeset
222 __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
223 endfor
6249
c507206c45bc [project @ 2007-01-22 20:00:06 by jwe]
jwe
parents: 6046
diff changeset
224 if (iscell (__file))
6365
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
225 if (isempty (__file))
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
226 __file = "";
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
227 else
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
228 __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
229 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
230 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
231 if (isempty (__file))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
232 if (__grabdemo)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
233 __n = "";
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
234 __nmax = -1;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 endif
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
248 fflush (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
249 if (nargout > 0)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
250 if (nargout == 1)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
251 __n = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
252 else
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
253 __n = __nmax = 0;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
254 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
255 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
256 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
257 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
258 fclose (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
259 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
260 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
261 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
262
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
263 ## Grab the test code from the file.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
264 __body = __extract_test_code (__file);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
265
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
266 if (isempty (__body))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
267 if (__grabdemo)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
268 __n = "";
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
269 __nmax = [];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
270 else
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
271 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
272 fflush (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
273 if (nargout > 0)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
274 if (nargout == 1)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
275 __n = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
276 else
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
277 __n = __nmax = 0;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
278 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
279 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
280 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
281 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
282 fclose (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
283 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
284 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
285 else
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
286 ## 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
287 if (__body(end) == "\n")
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
288 __body = ["\n" __body "#"];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
289 else
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
290 __body = ["\n" __body "\n#"];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
291 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
292 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
293
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
294 ## Chop it up into blocks for evaluation.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
295 __lineidx = find (__body == "\n");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
296 __blockidx = __lineidx(find (! isspace (__body(__lineidx+1))))+1;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
297
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
298 ## Ready to start tests.
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
299 ## 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
300 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
301 disp ([__signal_file, __file]);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
302 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
303
25521
a87b4dca2ce3 test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents: 25216
diff changeset
304 ## 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
305 __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
306
25522
90c8325c14be test.m: Warn if %!tests leak variables in to base workspace.
Rik <rik@octave.org>
parents: 25521
diff changeset
307 ## 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
308 __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
309 ## 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
310 __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
311
48a9bd2d0a20 also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents: 25522
diff changeset
312 ## Track variable leaks
48a9bd2d0a20 also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents: 25522
diff changeset
313 __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
314
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
315 ## Assume all tests will pass.
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
316 __all_success = true;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
317
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
318 ## Process each block separately, initially with no shared variables.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
319 __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
320 __xfail = __xbug = __xskip = __xrtskip = __xregression = 0;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
321 __shared = " ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
322 __shared_r = " ";
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
323 __clearfcn = "";
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
324 for __i = 1:numel (__blockidx)-1
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
325
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
326 ## 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
327 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
328 unwind_protect
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
329
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
330 ## 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
331 __block = __body(__blockidx(__i):__blockidx(__i+1)-2);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
332
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
333 ## 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
334 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
335 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
336 fflush (__fid);
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
337 endif
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 ## 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
340 __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
341 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
342 __type = __block;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
343 __code = "";
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
344 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
345 __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
346 __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
347 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
348
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
349 ## 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
350 __success = true;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
351 __msg = [];
22376
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
352 __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
353 __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
354 __bug_id = "";
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
355 __fixed_bug = false;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
356
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
357 ### DEMO
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
358
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
359 ## 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
360 ## 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
361 ## 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
362 ## 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
363
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
364 __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
365 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
366 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
367 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
368 __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
369 __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
370 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
371 __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
372 __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
373 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
374
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
375 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
376 try
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
377 ## 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
378 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
379 __test__;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
380 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
381 catch
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
382 __success = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
383 __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
384 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
385 clear __test__;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
386
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
387 endif
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
388 ## 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
389 __code = "";
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
390
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
391 ### SHARED
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
392
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
393 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
394 ## 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
395 __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
396 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
397 __vars = __code;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
398 __code = "";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
399 else
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
400 __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
401 __code = __code (__idx(1):length (__code));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
402 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
403
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
404 ## 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
405 __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
406 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
407 __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
408 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
409
28720
2c367a9c9660 fix onCleanup in test files with multiple shared blocks (bug #59097)
John W. Eaton <jwe@octave.org>
parents: 28040
diff changeset
410 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
411 ## 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
412 ## 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
413 __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
414 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
415 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
416 endif
2c367a9c9660 fix onCleanup in test files with multiple shared blocks (bug #59097)
John W. Eaton <jwe@octave.org>
parents: 28040
diff changeset
417 endif
2c367a9c9660 fix onCleanup in test files with multiple shared blocks (bug #59097)
John W. Eaton <jwe@octave.org>
parents: 28040
diff changeset
418
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
419 ## 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
420 try
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
421 __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
422 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
423 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
424 __shared = __vars;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
425 __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
426 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
427 __shared = " ";
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
428 __shared_r = " ";
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
429 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
430 catch
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
431 ## 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
432 __code = "";
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
433 __success = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
434 __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
435 end_try_catch
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
436
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
437 ## 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
438
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
439 ### FUNCTION
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
440
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
441 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
442 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
443 __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
444 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
445 __success = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
446 __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
447 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
448 __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
449 __code = __block;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
450 try
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
451 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
452 __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
453 catch
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
454 __success = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
455 __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
456 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
457 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
458 __code = "";
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
459
13305
63463570d9fe Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents: 12687
diff changeset
460 ### ENDFUNCTION
63463570d9fe Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents: 12687
diff changeset
461
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
462 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
463 ## 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
464 ## 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
465 __code = "";
13305
63463570d9fe Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents: 12687
diff changeset
466
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
467 ### ASSERT
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
468 ### ASSERT <BUG-ID>
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
469 ### FAIL
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
470 ### FAIL <BUG-ID>
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
471 ###
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
472 ### 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
473 ### 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
474 ### bugs are reported as regressions.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
475
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
476 elseif (strcmp (__type, "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
477 [__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
478 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
479 __istest = true;
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
480 else
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
481 __isxtest = true;
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
482 endif
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
483 ## 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
484 __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
485 ## 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
486
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
487 ### ERROR/WARNING
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
488
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
489 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
490 __istest = true;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
491 __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
492 [__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
493 if (__id)
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
494 __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
495 else
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
496 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
497 __patstr = ["<" __pattern ">"];
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
498 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
499 __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
500 endif
16976
13affad7347c test.m: Use the syntax "BLOCK_NAME failed" for error/warnings blocks.
Rik <rik@octave.org>
parents: 16170
diff changeset
501 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
502 try
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
503 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
504 __shared, __code));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
505 catch
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
506 __success = false;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
507 __msg = [__signal_fail "test failed: syntax error\n" lasterr()];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
508 end_try_catch
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
509
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
510 if (__success)
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
511 __success = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
512 __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
513 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
514 ## 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
515 lasterr ("");
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
516 lastwarn ("");
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
517 try
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
518 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
519 if (! __iswarning)
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
520 __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
521 "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
522 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
523 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
524 [~, __err] = lastwarn ();
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
525 __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
526 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
527 __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
528 __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
529 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
530 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
531 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
532 __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
533 "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
534 elseif (__mismatch)
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
535 __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
536 "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
537 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
538 __success = true;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
539 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
540 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
541
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
542 catch
10398
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
543 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
544 [~, __err] = lasterr ();
10398
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
545 __mismatch = ! strcmp (__err, __id);
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
546 else
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
547 __err = trimerr (lasterr (), "error");
10398
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
548 __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
549 endif
7028
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
550 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
551 if (__iswarning)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
552 __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
553 "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
554 ", 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
555 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
556 __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
557 "Expected " __patstr ", but got <" __err ">\n"];
7028
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
558 else
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
559 __success = true;
7028
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
560 endif
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
561 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
562 clear __test__;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
563 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
564 ## 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
565 __code = "";
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
566
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
567 ### TESTIF HAVE_FEATURE
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
568 ### 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
569 ### 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
570 ### 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
571 ###
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
572 ### 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
573 ### 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
574 ###
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
575 ### 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
576 ### 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
577 ### 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
578 ###
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
579 ### 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
580 ### 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
581 ### 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
582
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
583 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
584 __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
585 ## 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
586 ## looking for features
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
587 __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
588 __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
589 if (__idx1)
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
590 __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
591 __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
592 if (__idx2)
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
593 __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
594 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
595 __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
596 __fixed_bug = true;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
597 endif
22376
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
598 __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
599 endif
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
600 endif
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
601 __idx = index (__feat_line, ";");
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
602 if (__idx)
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
603 __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
604 __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
605 else
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
606 __runtime_feat_test = "";
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
607 endif
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
608 __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
609 __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
610 __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
611 if (__have_feat)
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
612 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
613 if (isempty (__bug_id))
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
614 __istest = true;
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
615 else
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
616 __isxtest = true;
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
617 endif
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
618 __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
619 else
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
620 __xrtskip += 1;
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
621 __code = ""; # Skip the code.
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
622 __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
623 endif
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
624 else
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20726
diff changeset
625 __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
626 __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
627 __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
628 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
629
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
630 ### TEST
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
631 ### TEST <BUG-ID>
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
632 ###
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
633 ### 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
634 ### 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
635 ### 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
636
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
637 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
638 [__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
639 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
640 __isxtest = true;
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
641 else
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
642 __istest = true;
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
643 endif
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
644 ## 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
645
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
646 ### XTEST
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
647 ### XTEST <BUG-ID>
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
648 ###
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
649 ### 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
650 ### 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
651 ### bugs are reported as regressions.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
652
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
653 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
654 __isxtest = true;
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
655 [__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
656 ## 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
657
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
658 ### Comment block.
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
659
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
660 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
661 __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
662
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
663 ### Unknown block.
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
664
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
665 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
666 __istest = true;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
667 __success = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
668 __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
669 __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
670 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
671
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
672 ## 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
673 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
674 try
24590
b6818c2b0483 test.m: Remove requirement to avoid nested functions in %!test blocks.
Rik <rik@octave.org>
parents: 24534
diff changeset
675 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
676 __shared_r, __shared, __code));
b6818c2b0483 test.m: Remove requirement to avoid nested functions in %!test blocks.
Rik <rik@octave.org>
parents: 24534
diff changeset
677 eval (sprintf ("%s__test__(%s);", __shared_r, __shared));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
678 catch
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
679 if (isempty (lasterr ()))
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20713
diff changeset
680 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
681 else
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
682 __success = false;
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
683 if (__isxtest)
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
684 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
685 if (__fixed_bug)
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
686 __xregression += 1;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
687 __msg = "regression";
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
688 else
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
689 __xfail += 1;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
690 __msg = "known failure";
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
691 endif
22376
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
692 else
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
693 if (__fixed_bug)
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
694 __xregression += 1;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
695 else
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
696 __xbug += 1;
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 if (all (isdigit (__bug_id)))
25024
3c817af70eed maint: use https for all Octave project URLs
Mike Miller <mtmiller@octave.org>
parents: 24590
diff changeset
699 __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
700 endif
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
701 if (__fixed_bug)
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
702 __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
703 else
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
704 __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
705 endif
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
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
707 else
22379
805442f0674b * test.m: Fix doubled "!!!!!" marker in failure messages.
John W. Eaton <jwe@octave.org>
parents: 22376
diff changeset
708 __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
709 endif
22379
805442f0674b * test.m: Fix doubled "!!!!!" marker in failure messages.
John W. Eaton <jwe@octave.org>
parents: 22376
diff changeset
710 __msg = [__signal_fail __msg "\n" lasterr()];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
711 endif
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
712 end_try_catch
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
713 clear __test__;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
714 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
715
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
716 ## 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
717 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
718 ## 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
719 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
720 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
721 fflush (__fid);
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
722 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
723 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
724 ## 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
725 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
726 && ! strcmp (__type, "testif")
236163306596 * test.m: Omit details about known test failures (bug #47444).
John W. Eaton <jwe@octave.org>
parents: 21436
diff changeset
727 && ! 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
728 && ! all (__shared == " "))
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
729 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
730 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
731 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
732 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
733 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
734 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
735 __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
736 ## 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
737 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
738 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
739 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
740 __n = false;
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
741 else
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
742 __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
743 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
744 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
745 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
746 fclose (__fid);
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
747 endif
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
748 return;
6728
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
749 endif
19444
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 __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
752 __successes += __success && (__istest || __isxtest);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
753
19444
3f29b433bd5d do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents: 19402
diff changeset
754 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
755 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
756 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
757 end_unwind_protect
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
758 endfor
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
759
25525
48a9bd2d0a20 also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents: 25522
diff changeset
760 ## 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
761 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
762 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
763 endif
a87b4dca2ce3 test.m: Warn if %!tests in file leak file descriptors.
Rik <rik@octave.org>
parents: 25216
diff changeset
764
25525
48a9bd2d0a20 also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents: 25522
diff changeset
765 ## 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
766 __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
767 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
768 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
769 __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
770 endif
48a9bd2d0a20 also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents: 25522
diff changeset
771
48a9bd2d0a20 also check for tests that leak global variables (bug #54180)
John W. Eaton <jwe@octave.org>
parents: 25522
diff changeset
772 ## 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
773 __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
774 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
775 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
776 __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
777 endif
90c8325c14be test.m: Warn if %!tests leak variables in to base workspace.
Rik <rik@octave.org>
parents: 25521
diff changeset
778
28720
2c367a9c9660 fix onCleanup in test files with multiple shared blocks (bug #59097)
John W. Eaton <jwe@octave.org>
parents: 28040
diff changeset
779 ## 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
780 ## 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
781 __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
782 if (! isempty (__shared_vars))
a077eadd1325 test.m: Fix onCleanup error when testing rand.cc (bug #57456).
Rik <rik@octave.org>
parents: 27923
diff changeset
783 clear (__shared_vars{:});
a077eadd1325 test.m: Fix onCleanup error when testing rand.cc (bug #57456).
Rik <rik@octave.org>
parents: 27923
diff changeset
784 endif
a077eadd1325 test.m: Fix onCleanup error when testing rand.cc (bug #57456).
Rik <rik@octave.org>
parents: 27923
diff changeset
785
a077eadd1325 test.m: Fix onCleanup error when testing rand.cc (bug #57456).
Rik <rik@octave.org>
parents: 27923
diff changeset
786 ## 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
787 eval (__clearfcn, "");
a077eadd1325 test.m: Fix onCleanup error when testing rand.cc (bug #57456).
Rik <rik@octave.org>
parents: 27923
diff changeset
788
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
789 if (nargout == 0)
23363
0cd0db82123d distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents: 23280
diff changeset
790 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
791 if (__xfail || __xbug)
0cd0db82123d distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents: 23280
diff changeset
792 if (__xfail && __xbug)
0cd0db82123d distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents: 23280
diff changeset
793 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
794 __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
795 __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
796 __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
797 elseif (__xfail)
0cd0db82123d distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents: 23280
diff changeset
798 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
799 __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
800 __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
801 elseif (__xbug)
0cd0db82123d distinguish between reported bugs and known failures in tests
John W. Eaton <jwe@octave.org>
parents: 23280
diff changeset
802 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
803 __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
804 __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
805 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
806 else
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
807 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
808 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
809 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
810 if (__xskip)
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
811 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
812 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
813 endif
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
814 if (__xrtskip)
23280
9a0e33470da5 use "run-time condition" consistently in previous change
John W. Eaton <jwe@octave.org>
parents: 23279
diff changeset
815 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
816 ifelse (__xrtskip > 1, "s", ""));
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
817 endif
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
818 else
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
819 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
820 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
821 elseif (__grabdemo)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
822 __n = __demo_code;
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
823 __nmax = __demo_idx;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
824 elseif (nargout == 1)
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
825 __n = __all_success;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
826 else
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
827 __n = __successes;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
828 __nmax = __tests;
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
829 __nxfail = __xfail;
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
830 __nbug = __xbug;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
831 __nskip = __xskip;
23279
67d741321e21 allow skipping of tests based on run-time conditions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
832 __nrtskip = __xrtskip;
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
833 __nregression = __xregression;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
834 endif
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
835
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
836 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
837
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
838
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
839 ## 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
840 function s = var2struct (varargin)
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
841 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
842 s.(inputname (i, true)) = varargin{i};
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
843 endfor
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
844 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
845
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
846 ## 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
847 function pos = function_name (def)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
848
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
849 pos = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
850
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
851 ## Find the end of the name.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
852 right = find (def == "(", 1);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
853 if (isempty (right))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
854 return;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
855 endif
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
856 right = find (def(1:right-1) != " ", 1, "last");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
857
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
858 ## Find the beginning of the name.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
859 left = max ([find(def(1:right)==" ", 1, "last"), ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10398
diff changeset
860 find(def(1:right)=="=", 1, "last")]);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
861 if (isempty (left))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
862 return;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
863 endif
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20726
diff changeset
864 left += 1;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
865
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
866 ## Return the end points of the name.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
867 pos = [left, right];
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
868
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
869 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
870
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
871 ## 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
872 ## 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
873 function [pattern, id, rest] = getpattern (str)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
874
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
875 pattern = ".";
10398
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
876 id = [];
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
877 rest = str;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
878 str = trimleft (str);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
879 if (! isempty (str) && str(1) == "<")
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
880 close = index (str, ">");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
881 if (close)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
882 pattern = str(2:close-1);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
883 rest = str(close+1:end);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
884 endif
10398
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
885 elseif (strncmp (str, "id=", 3))
f7cf1a53e1c5 support ID test for errors and warningsin test suites
Jaroslav Hajek <highegg@gmail.com>
parents: 10130
diff changeset
886 [id, rest] = strtok (str(4:end));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
887 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
888
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
889 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
890
22376
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
891 ## 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
892 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
893
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
894 bug_id = "";
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
895 rest = str;
23571
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
896 fixed = false;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
897
22376
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
898 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
899 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
900 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
901 if (close)
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
902 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
903 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
904 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
905 fixed = true;
b6144e6dda9e allow bugs to be tagged as fixed in test suite
John W. Eaton <jwe@octave.org>
parents: 23406
diff changeset
906 endif
22376
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
907 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
908 endif
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
909 endif
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
910
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
911 endfunction
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
912
3473246a824e allow %!test blocks to be tagged with messages or bug ids
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
913
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
914 ## 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
915 function msg = trimerr (msg, prefix)
16977
0d5d3e53255f test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents: 16976
diff changeset
916 idx = index (msg, [prefix ":"]);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
917 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
918 msg(1:idx+length (prefix)) = [];
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
919 endif
16977
0d5d3e53255f test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents: 16976
diff changeset
920 msg = strtrim (msg);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
921 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
922
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
923 ## Strip leading blanks from string.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
924 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
925 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
926 str = str(idx:end);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
927 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
928
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
929 function body = __extract_test_code (nm)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
930 fid = fopen (nm, "rt");
19402
5cd83b466a3e test.m: Avoid num-to-str warning.
Rik <rik@octave.org>
parents: 19291
diff changeset
931 body = "";
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
932 if (fid >= 0)
19291
64f034147e9a test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents: 19152
diff changeset
933 while (ischar (ln = fgets (fid)))
64f034147e9a test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents: 19152
diff changeset
934 if (strncmp (ln, "%!", 2))
64f034147e9a test.m: Eliminate needless use of feof().
Rik <rik@octave.org>
parents: 19152
diff changeset
935 body = [body, ln(3:end)];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
936 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
937 endwhile
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
938 fclose (fid);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
939 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
940 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
941
16977
0d5d3e53255f test.m: Fix randomly failing %!warning test blocks (bug #35850, bug #38679).
Rik <rik@octave.org>
parents: 16976
diff changeset
942
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
943 ## 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
944 %!shared msg1,msg2
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
945 %! msg1 = "C must be a vector";
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
946 %! msg2 = "C and R must be vectors";
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
947 %!fail ("toeplitz ([])", msg1)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
948 %!fail ("toeplitz ([1,2;3,4])", msg1)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
949 %!fail ("toeplitz ([1,2],[])", msg2)
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
950 %!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
951 %!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
952 %!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
953 %!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
954 %!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
955 %!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
956 %!demo toeplitz ([1,2,3,4],[1,5,6])
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
957
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
958 ## example from kron
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
959 %!error <Invalid call to kron> kron ()
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
960 %!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
961 %!test assert (isempty (kron ([], rand (3, 4))))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
962 %!test assert (isempty (kron (rand (3, 4), [])))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
963 %!test assert (isempty (kron ([], [])))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
964 %!shared A, B
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
965 %!test
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
966 %! A = [1, 2, 3; 4, 5, 6];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
967 %! B = [1, -1; 2, -2];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
968 %!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
969 %!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
970 %!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
971 %!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
972 %!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
973 %!assert (kron (pi, A), pi*A)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
974 %!assert (kron (A, e), e*A)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
975 %!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
976 %!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
977 %!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
978 %!test
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
979 %! 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
980 %! assert (kron (A, B), res);
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
981 %!shared # clear out shared variables
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
982
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
983 ## Now verify test() itself
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
984
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
985 ## Test 'fail' keyword
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
986 %!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
987 %!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
988 %!fail ('test ("test", "invalid")', "unknown flag") # incorrect args
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
989 %!fail ('garbage','garbage.*undefined') # usage on nonexistent function should be
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
990
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
991 ## 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
992 %!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
993 %!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
994 %!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
995 %!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
996
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
997 ## Test 'warning' keyword
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
998 %!warning warning ("warning message"); # no pattern
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
999 %!warning <warning message> warning ("warning message"); # with pattern
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 'shared' keyword
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1002 %!shared a # create a shared variable
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1003 %!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
1004 %!test assert (a, 3) # variable should equal 3
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1005 %!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
1006 %!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
1007 %!test assert (isempty (b)); # variables start off empty
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1008 %!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
1009 %!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
1010 %!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
1011 %!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
1012 %!test c=6; # update a value
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1013 %!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
1014 %!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
1015 %!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
1016 %!shared a,b,c # support for initializer shorthand
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1017 %! a=1; b=2; c=4;
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1018 %!shared # clear all shared variables for remainder of tests
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1019
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1020 ## 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
1021 %!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
1022 %! x = 2*y;
13305
63463570d9fe Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents: 12687
diff changeset
1023 %!endfunction
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1024 %!assert (__test_a (2), 4) # Test a test function
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1025
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1026 %!function __test_a (y)
22627
7b190a2f11cb maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents: 22379
diff changeset
1027 %! x = 2*y;
13305
63463570d9fe Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents: 12687
diff changeset
1028 %!endfunction
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1029 %!test
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1030 %! __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
1031
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1032 %!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
1033 %! x = 2*y;
7b190a2f11cb maint: Use 2-space indent in definition of BIST %!functions.
Rik <rik@octave.org>
parents: 22379
diff changeset
1034 %! z = 3*y;
13305
63463570d9fe Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents: 12687
diff changeset
1035 %!endfunction
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1036 %!test
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1037 %! [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
1038 %! assert (x,6);
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1039 %! assert (z,9);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1040
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1041 ## Test 'assert' keyword
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1042 %!assert (isempty ([])) # support for test assert shorthand
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1043 %!assert (size (ones (1,2,3)), [1 2 3])
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1044
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1045 ## Test 'demo' keyword
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1046 %!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
1047 %! 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
1048 %! plot (t,x);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1049 %! % 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
1050
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1051 %!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
1052
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1053 %!test
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1054 %! [code, idx] = test ("test", "grabdemo");
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1055 %! assert (numel (idx), 4);
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1056 %! assert (code(idx(3):end),
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1057 %! " a=3 # single line demo blocks work too");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1058
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1059 ## Test 'testif' keyword
20835
14cd86258b3d use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents: 20735
diff changeset
1060 %!testif HAVE_INVALID_FEATURE
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1061 %! 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
1062
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1063 ## Test 'xtest' keyword
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1064 %!xtest
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1065 %! assert (1, 1); # Test passes
25216
b72972ab83f1 test: Add bug IDs to failing %!xtest blocks.
Rik <rik@octave.org>
parents: 25054
diff changeset
1066 %!xtest <53613>
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1067 %! assert (0, 1); # Test fails
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1068
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21460
diff changeset
1069 ## Test comment block. It can contain anything.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1070 %!##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
1071 %! 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
1072 %! 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
1073 %! 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
1074
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1075 ## Test test() input validation
19048
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1076 %!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
1077 %!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
1078 %!error test ([], "normal")
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1079
ec28b7216501 test.m: Overhaul function (also fixes bug #39703).
Rik <rik@octave.org>
parents: 18857
diff changeset
1080 ## 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
1081 ## 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
1082 ## 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
1083 ## %!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
1084 ## %!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
1085 ## %!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
1086 ## %!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
1087 ## %!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
1088 ## %!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
1089 ## %!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
1090 ## %!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
1091 ## %!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
1092 ## %!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
1093 ## %!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
1094 ## %!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
1095 ## %! 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
1096 ## %!error
45a64a6c7273 fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents: 20852
diff changeset
1097 ## %! 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
1098 ## %! test ("nonexistent file");
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21634
diff changeset
1099 ## %! ## 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
1100 ## %! ## 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
1101 ## %! ## so of course the informational message is not printed in the log.