annotate scripts/testfun/test.m @ 20058:6babcfbe1a0a

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