annotate scripts/testfun/test.m @ 9051:1bf0ce0930be

Grammar check TexInfo in all .m files Cleanup documentation sources to follow a few consistent rules. Spellcheck was NOT done. (but will be in another changeset)
author Rik <rdrider0-list@yahoo.com>
date Fri, 27 Mar 2009 22:31:03 -0700
parents eb63fbe60fab
children 929e53107f09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
1 ## Copyright (C) 2005, 2006, 2007, 2008, 2009 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 -*-
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {} test @var{name}
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {} test @var{name} quiet|normal|verbose
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {} test ('@var{name}', 'quiet|normal|verbose', @var{fid})
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
23 ## @deftypefnx {Function File} {} test ([], 'explain', @var{fid})
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
24 ## @deftypefnx {Function File} {@var{success} =} test (@dots{})
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
25 ## @deftypefnx {Function File} {[@var{n}, @var{max}] =} test (@dots{})
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
26 ## @deftypefnx {Function File} {[@var{code}, @var{idx}] =} test ('@var{name}','grabdemo')
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
27 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
28 ## Perform tests from the first file in the loadpath matching @var{name}.
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
29 ## @code{test} can be called as a command or as a function. Called with
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
30 ## a single argument @var{name}, the tests are run interactively and stop
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
31 ## after the first error is encountered.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
32 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
33 ## With a second argument the tests which are performed and the amount of
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
34 ## output is selected.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
35 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
36 ## @table @asis
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
37 ## @item 'quiet'
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
38 ## Don't report all the tests as they happen, just the errors.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
39 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
40 ## @item 'normal'
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
41 ## Report all tests as they happen, but don't do tests which require
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
42 ## user interaction.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
43 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
44 ## @item 'verbose'
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
45 ## Do tests which require user interaction.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
46 ## @end table
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
47 ##
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
48 ## The argument @var{fid} can be used to allow batch processing. Errors
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
49 ## can be written to the already open file defined by @var{fid}, and
8481
00df69d7e698 [docs] capitalize Octave consistently
Brian Gough <bjg@gnu.org>
parents: 8422
diff changeset
50 ## hopefully when Octave crashes this file will tell you what was happening
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
51 ## when it did. You can use @code{stdout} if you want to see the results as
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
52 ## they happen. You can also give a file name rather than an @var{fid}, in
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
53 ## which case the contents of the file will be replaced with the log from
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
54 ## the current test.
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 ## Called with a single output argument @var{success}, @code{test} returns
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
57 ## true if all of the tests were successful. Called with two output arguments
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6730
diff changeset
58 ## @var{n} and @var{max}, the number of successful tests and the total number
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
59 ## of tests in the file @var{name} are returned.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
60 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
61 ## If the second argument is the string 'grabdemo', the contents of the demo
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
62 ## blocks are extracted but not executed. Code for all code blocks is
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6730
diff changeset
63 ## concatenated and returned as @var{code} with @var{idx} being a vector of
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
64 ## positions of the ends of the demo blocks.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
65 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
66 ## If the second argument is 'explain', then @var{name} is ignored and an
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
67 ## explanation of the line markers used is written to the file @var{fid}.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5589
diff changeset
68 ## @seealso{error, assert, fail, demo, example}
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
69 ## @end deftypefn
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
70
8202
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 7940
diff changeset
71 ## FIXME: * Consider using keyword fail rather then error? This allows us
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 7940
diff changeset
72 ## to make a functional form of error blocks, which means we
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 7940
diff changeset
73 ## can include them in test sections which means that we can use
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 7940
diff changeset
74 ## octave flow control for both kinds of tests.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
75
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
76 function [__ret1, __ret2, __ret3, __ret4] = test (__name, __flag, __fid)
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
77 ## Information from test will be introduced by "key".
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
78 persistent __signal_fail = "!!!!! ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
79 persistent __signal_empty = "????? ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
80 persistent __signal_block = " ***** ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
81 persistent __signal_file = ">>>>> ";
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
82 persistent __signal_skip = "----- ";
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
83
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
84 __xfail = 0;
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
85 __xskip = 0;
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
86
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
87 if (nargin < 2 || isempty (__flag))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
88 __flag = "quiet";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
89 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
90 if (nargin < 3)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
91 __fid = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
92 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
93 if (nargin < 1 || nargin > 3
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
94 || (! ischar (__name) && ! isempty (__name)) || ! ischar (__flag))
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6024
diff changeset
95 print_usage ();
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
96 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
97 if (isempty (__name) && (nargin != 3 || ! strcmp (__flag, "explain")))
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6024
diff changeset
98 print_usage ();
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
99 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
100 __batch = (! isempty (__fid));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
101
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
102 ## Decide if error messages should be collected.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
103 __close_fid = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
104 if (__batch)
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
105 if (ischar (__fid))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
106 __fid = fopen (__fid, "wt");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
107 if (__fid < 0)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
108 error ("could not open log file");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
109 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
110 __close_fid = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
111 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
112 fprintf (__fid, "%sprocessing %s\n", __signal_file, __name);
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
113 fflush (__fid);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
114 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
115 __fid = stdout;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
116 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
117
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
118 if (strcmp (__flag, "normal"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
119 __grabdemo = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
120 __rundemo = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
121 __verbose = __batch;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
122 elseif (strcmp (__flag, "quiet"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
123 __grabdemo = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
124 __rundemo = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
125 __verbose = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
126 elseif (strcmp (__flag, "verbose"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
127 __grabdemo = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
128 __rundemo = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
129 __verbose = 1;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
130 elseif (strcmp (__flag, "grabdemo"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
131 __grabdemo = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
132 __rundemo = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
133 __verbose = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
134 __demo_code = "";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
135 __demo_idx = 1;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
136 elseif (strcmp (__flag, "explain"))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
137 fprintf (__fid, "# %s new test file\n", __signal_file);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
138 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
139 fprintf (__fid, "# %s test had an unexpected result\n", __signal_fail);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
140 fprintf (__fid, "# %s code for the test\n", __signal_block);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
141 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
142 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
143 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
144 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
145 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
146 fflush (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
147 if (__close_fid)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
148 fclose(__fid);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
149 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
150 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
151 else
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
152 error ("test unknown flag '%s'", __flag);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
153 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
154
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
155 ## Locate the file to test.
6249
c507206c45bc [project @ 2007-01-22 20:00:06 by jwe]
jwe
parents: 6046
diff changeset
156 __file = file_in_loadpath (__name, "all");
c507206c45bc [project @ 2007-01-22 20:00:06 by jwe]
jwe
parents: 6046
diff changeset
157 if (isempty (__file))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
158 __file = file_in_loadpath (cstrcat (__name, ".m"), "all");
5589
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 if (isempty (__file))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
161 __file = file_in_loadpath (cstrcat (__name, ".cc"), "all");
6249
c507206c45bc [project @ 2007-01-22 20:00:06 by jwe]
jwe
parents: 6046
diff changeset
162 endif
c507206c45bc [project @ 2007-01-22 20:00:06 by jwe]
jwe
parents: 6046
diff changeset
163 if (iscell (__file))
6365
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
164 ## If repeats, return first in path.
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
165 if (isempty (__file))
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
166 __file = "";
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
167 else
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
168 __file = __file{1};
ccdb8ffbb994 [project @ 2007-02-27 19:43:35 by jwe]
jwe
parents: 6249
diff changeset
169 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
170 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
171 if (isempty (__file))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
172 if (__grabdemo)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
173 __ret1 = "";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
174 __ret2 = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
175 else
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
176 fprintf (__fid, "%s%s does not exist in path\n", __signal_empty, __name);
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
177 fflush (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
178 if (nargout > 0)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
179 __ret1 = __ret2 = 0;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
180 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
181 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
182 if (__close_fid)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
183 fclose(__fid);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
184 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
185 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
186 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
187
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
188 ## Grab the test code from the file.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
189 __body = __extract_test_code (__file);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
190
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
191 if (isempty (__body))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
192 if (__grabdemo)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
193 __ret1 = "";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
194 __ret2 = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
195 else
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
196 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
197 fflush (__fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
198 if (nargout > 0)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
199 __ret1 = __ret2 = 0;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
200 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
201 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
202 if (__close_fid)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
203 fclose(__fid);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
204 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
205 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
206 else
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
207 ## Add a dummy comment block to the end for ease of indexing.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
208 if (__body (length(__body)) == "\n")
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
209 __body = sprintf ("\n%s#", __body);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
210 else
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
211 __body = sprintf ("\n%s\n#", __body);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
212 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
213 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
214
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
215 ## Chop it up into blocks for evaluation.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
216 __lineidx = find (__body == "\n");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
217 __blockidx = __lineidx(find (! isspace (__body(__lineidx+1))))+1;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
218
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
219 ## Ready to start tests ... if in batch mode, tell us what is happening.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
220 if (__verbose)
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
221 disp (cstrcat (__signal_file, __file));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
222 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
223
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
224 ## Assume all tests will pass.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
225 __all_success = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
226
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
227 ## Process each block separately, initially with no shared variables.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
228 __tests = __successes = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
229 __shared = " ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
230 __shared_r = " ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
231 __clear = "";
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
232 for __i = 1:length(__blockidx)-1
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
233
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
234 ## Extract the block.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
235 __block = __body(__blockidx(__i):__blockidx(__i+1)-2);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
236
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
237 ## Let the user/logfile know what is happening.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
238 if (__verbose)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
239 fprintf (__fid, "%s%s\n", __signal_block, __block);
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
240 fflush (__fid);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
241 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
242
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
243 ## Split __block into __type and __code.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
244 __idx = find (! isletter (__block));
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
245 if (isempty (__idx))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
246 __type = __block;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
247 __code = "";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
248 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
249 __type = __block(1:__idx(1)-1);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
250 __code = __block(__idx(1):length(__block));
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
251 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
252
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
253 ## Assume the block will succeed.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
254 __success = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
255 __msg = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
256
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
257 ### DEMO
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
258
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
259 ## If in __grabdemo mode, then don't process any other block type.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
260 ## So that the other block types don't have to worry about
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
261 ## this __grabdemo mode, the demo block processor grabs all block
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
262 ## types and skips those which aren't demo blocks.
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
263
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
264 __isdemo = strcmp (__type, "demo");
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
265 if (__grabdemo || __isdemo)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
266 __istest = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
267
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
268 if (__grabdemo && __isdemo)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
269 if (isempty(__demo_code))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
270 __demo_code = __code;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
271 __demo_idx = [1, length(__demo_code)+1];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
272 else
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
273 __demo_code = cstrcat(__demo_code, __code);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
274 __demo_idx = [__demo_idx, length(__demo_code)+1];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
275 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
276
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
277 elseif (__rundemo && __isdemo)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
278 try
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
279 ## process the code in an environment without variables
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
280 eval (sprintf ("function __test__()\n%s\nendfunction", __code));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
281 __test__;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
282 input ("Press <enter> to continue: ", "s");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
283 catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
284 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
285 __msg = sprintf ("%sdemo failed\n%s", __signal_fail, __error_text__);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
286 end_try_catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
287 clear __test__;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
288
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
289 endif
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
290 ## Code already processed.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
291 __code = "";
5589
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 ### SHARED
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
294
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
295 elseif (strcmp (__type, "shared"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
296 __istest = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
297
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
298 ## Separate initialization code from variables.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
299 __idx = find (__code == "\n");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
300 if (isempty (__idx))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
301 __vars = __code;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
302 __code = "";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
303 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
304 __vars = __code (1:__idx(1)-1);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
305 __code = __code (__idx(1):length(__code));
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
306 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
307
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
308 ## Strip comments off the variables.
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
309 __idx = find (__vars == "%" | __vars == "#");
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
310 if (! isempty (__idx))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
311 __vars = __vars(1:__idx(1)-1);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
312 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
313
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
314 ## Assign default values to variables.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
315 try
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
316 __vars = deblank (__vars);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
317 if (! isempty (__vars))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
318 eval (cstrcat (strrep (__vars, ",", "=[];"), "=[];"));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
319 __shared = __vars;
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
320 __shared_r = cstrcat ("[ ", __vars, "] = ");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
321 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
322 __shared = " ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
323 __shared_r = " ";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
324 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
325 catch
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
326 ## Couldn't declare, so don't initialize.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
327 __code = "";
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
328 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
329 __msg = sprintf ("%sshared variable initialization failed\n",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
330 __signal_fail);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
331 end_try_catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
332
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
333 ## Clear shared function definitions.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
334 eval (__clear, "");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
335 __clear = "";
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
336
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
337 ## Initialization code will be evaluated below.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
338
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
339 ### FUNCTION
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
340
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
341 elseif (strcmp (__type, "function"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
342 __istest = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
343 persistent __fn = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
344 __name_position = function_name (__block);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
345 if (isempty (__name_position))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
346 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
347 __msg = sprintf ("%stest failed: missing function name\n",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
348 __signal_fail);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
349 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
350 __name = __block(__name_position(1):__name_position(2));
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
351 __code = __block;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
352 try
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
353 eval(__code); ## Define the function
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
354 __clear = sprintf ("%sclear %s;\n", __clear, __name);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
355 catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
356 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
357 __msg = sprintf ("%stest failed: syntax error\n%s",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
358 __signal_fail, __error_text__);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
359 end_try_catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
360 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
361 __code = "";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
362
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
363 ### ASSERT/FAIL
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
364
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
365 elseif (strcmp (__type, "assert") || strcmp (__type, "fail"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
366 __istest = 1;
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
367 ## Put the keyword back on the code.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
368 __code = __block;
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
369 ## The code will be evaluated below as a test block.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
370
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
371 ### ERROR/WARNING
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
372
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
373 elseif (strcmp (__type, "error") || strcmp(__type, "warning"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
374 __istest = 1;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
375 __warning = strcmp (__type, "warning");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
376 [__pattern, __code] = getpattern (__code);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
377 try
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
378 eval (sprintf ("function __test__(%s)\n%s\nendfunction",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
379 __shared, __code));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
380 catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
381 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
382 __msg = sprintf ("%stest failed: syntax error\n%s",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
383 __signal_fail, __error_text__);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
384 end_try_catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
385
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
386 if (__success)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
387 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
388 __warnstate = warning ("query", "quiet");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
389 warning ("on", "quiet");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
390 try
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
391 eval (sprintf ("__test__(%s);", __shared));
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
392 if (! __warning)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
393 __msg = sprintf ("%sexpected <%s> but got no error\n",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
394 __signal_fail, __pattern);
7028
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
395 else
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
396 __err = trimerr (lastwarn, "warning");
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
397 warning (__warnstate.state, "quiet");
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
398 if (isempty (__err))
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
399 __msg = sprintf ("%sexpected <%s> but got no warning\n",
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
400 __signal_fail, __pattern);
7028
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
401 elseif (isempty (regexp (__err, __pattern, "once")))
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
402 __msg = sprintf ("%sexpected <%s> but got %s\n",
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
403 __signal_fail, __pattern, __err);
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
404 else
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
405 __success = 1;
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
406 endif
ecd6347f7d1c [project @ 2007-10-15 09:00:02 by dbateman]
dbateman
parents: 7017
diff changeset
407 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
408
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
409 catch
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
410 __err = trimerr (lasterr, "error");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
411 warning (__warnstate.state, "quiet");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
412 if (__warning)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
413 __msg = sprintf ("%sexpected warning <%s> but got error %s\n",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
414 __signal_fail, __pattern, __err);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
415 elseif (isempty (regexp (__err, __pattern, "once")))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
416 __msg = sprintf ("%sexpected <%s> but got %s\n",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
417 __signal_fail, __pattern, __err);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
418 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
419 __success = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
420 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
421 end_try_catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
422 clear __test__;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
423 endif
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
424 ## Code already processed.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
425 __code = "";
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
426
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
427 ### TESTIF
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
428
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
429 elseif (strcmp (__type, "testif"))
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
430 [__e, __feat] = regexp (__code, '^\s*([^\s]+)', 'end', 'tokens');
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
431 if (isempty (findstr (octave_config_info ("DEFS"), __feat{1}{1})))
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
432 __xskip++;
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
433 __success = 0;
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
434 __istest = 0;
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
435 ## Skip the code.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
436 __code = "";
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
437 __msg = sprintf ("%sskipped test\n", __signal_skip);
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
438 else
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
439 __istest = 1;
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
440 __code = __code(__e + 1 : end);
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
441 endif
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
442
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
443 ### TEST
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
444
6728
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
445 elseif (strcmp (__type, "test") || strcmp (__type, "xtest"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
446 __istest = 1;
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
447 ## Code will be evaluated below.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
448
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
449 ### Comment block.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
450
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
451 elseif (strcmp (__block(1:1), "#"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
452 __istest = 0;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
453 __code = ""; # skip the code
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
454
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
455 ### Unknown block.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
456
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
457 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
458 __istest = 1;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
459 __success = 0;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
460 __msg = sprintf ("%sunknown test type!\n", __signal_fail);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
461 __code = ""; # skip the code
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
462 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
463
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
464 ## evaluate code for test, shared, and assert.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
465 if (! isempty(__code))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
466 try
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
467 eval (sprintf ("function %s__test__(%s)\n%s\nendfunction",
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
468 __shared_r,__shared, __code));
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
469 eval (sprintf ("%s__test__(%s);", __shared_r, __shared));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
470 catch
6728
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
471 if (strcmp (__type, "xtest"))
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
472 __msg = sprintf ("%sknown failure\n%s", __signal_fail, __error_text__);
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
473 __xfail++;
6728
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
474 else
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
475 __msg = sprintf ("%stest failed\n%s", __signal_fail, __error_text__);
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
476 __success = 0;
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
477 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
478 if (isempty (__error_text__))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
479 error ("empty error text, probably Ctrl-C --- aborting");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
480 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
481 end_try_catch
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
482 clear __test__;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
483 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
484
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
485 ## All done. Remember if we were successful and print any messages.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
486 if (! isempty (__msg))
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
487 ## Make sure the user knows what caused the error.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
488 if (! __verbose)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
489 fprintf (__fid, "%s%s\n", __signal_block, __block);
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
490 fflush (__fid);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
491 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
492 fputs (__fid, __msg);
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
493 fflush (__fid);
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
494 ## Show the variable context.
7244
5a9561046b89 [project @ 2007-12-04 02:27:27 by jwe]
jwe
parents: 7243
diff changeset
495 if (! strcmp (__type, "error") && ! strcmp (__type, "testif")
5a9561046b89 [project @ 2007-12-04 02:27:27 by jwe]
jwe
parents: 7243
diff changeset
496 && ! all (__shared == " "))
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
497 fputs (__fid, "shared variables ");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
498 eval (sprintf ("fdisp(__fid,bundle(%s));", __shared));
5908
9c134531c2c4 [project @ 2006-07-27 17:14:24 by jwe]
jwe
parents: 5803
diff changeset
499 fflush (__fid);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
500 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
501 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
502 if (__success == 0)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
503 __all_success = 0;
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
504 ## Stop after one error if not in batch mode.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
505 if (! __batch)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
506 if (nargout > 0)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
507 __ret1 = __ret2 = 0;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
508 endif
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
509 if (__close_fid)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
510 fclose(__fid);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
511 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
512 return;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
513 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
514 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
515 __tests += __istest;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
516 __successes += __success * __istest;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
517 endfor
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
518 eval (__clear, "");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
519
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
520 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
521 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
522 if (__xfail)
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
523 printf ("PASSES %d out of %d tests (%d expected failures)\n",
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
524 __successes, __tests, __xfail);
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
525 else
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
526 printf ("PASSES %d out of %d tests\n", __successes, __tests);
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
527 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
528 if (__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
529 printf ("Skipped %d tests due to missing features\n", __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
530 endif
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
531 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
532 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
533 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
534 elseif (__grabdemo)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
535 __ret1 = __demo_code;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
536 __ret2 = __demo_idx;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
537 elseif (nargout == 1)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
538 __ret1 = __all_success;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
539 else
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
540 __ret1 = __successes;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
541 __ret2 = __tests;
6730
230f9c49857e [project @ 2007-06-15 04:22:13 by jwe]
jwe
parents: 6728
diff changeset
542 __ret3 = __xfail;
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
543 __ret4 = __xskip;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
544 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
545 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
546
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
547 ## Create structure with fieldnames the name of the input variables.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
548 function s = varstruct (varargin)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
549 for i = 1:nargin
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
550 s.(deblank (argn(i,:))) = varargin{i};
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
551 endfor
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
552 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
553
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
554 ## 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
555 function pos = function_name (def)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
556 pos = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
557
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
558 ## Find the end of the name.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
559 right = find (def == "(", 1);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
560 if (isempty (right))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
561 return;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
562 endif
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
563 right = find (def(1:right-1) != " ", 1, "last");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
564
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
565 ## Find the beginning of the name.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
566 left = max ([find(def(1:right)==" ", 1, "last"), ...
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
567 find(def(1:right)=="=", 1, "last")]);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
568 if (isempty (left))
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
569 return;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
570 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
571 left++;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
572
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
573 ## Return the end points of the name.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
574 pos = [left, right];
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
575 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
576
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
577 ## Strip <pattern> from '<pattern> code'.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
578 function [pattern, rest] = getpattern (str)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
579 pattern = ".";
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
580 rest = str;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
581 str = trimleft (str);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
582 if (! isempty (str) && str(1) == "<")
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
583 close = index (str, ">");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
584 if (close)
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
585 pattern = str(2:close-1);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
586 rest = str(close+1:end);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
587 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
588 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
589 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
590
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
591 ## 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
592 function msg = trimerr (msg, prefix)
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
593 idx = index (msg, cstrcat (prefix, ":"));
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
594 if (idx > 0)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
595 msg(1:idx+length(prefix)) = [];
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
596 endif
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
597 msg = trimleft (deblank (msg));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
598 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
599
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
600 ## Strip leading blanks from string.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
601 function str = trimleft (str)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
602 idx = find (isspace (str));
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
603 leading = find (idx == 1:length(idx));
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
604 if (! isempty (leading))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
605 str = str(leading(end)+1:end);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
606 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
607 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
608
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
609 ## Make a structure out of the named variables
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
610 ## (based on Etienne Grossmann's tar function).
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
611 function s = bundle (varargin)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
612 for i = 1:nargin
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
613 s.(deblank (argn(i,:))) = varargin{i};
7151
aeeb646f6538 [project @ 2007-11-09 19:34:17 by jwe]
jwe
parents: 7028
diff changeset
614 endfor
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
615 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
616
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
617 function body = __extract_test_code (nm)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
618 fid = fopen (nm, "rt");
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
619 body = [];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
620 if (fid >= 0)
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
621 while (! feof (fid))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
622 ln = fgetl (fid);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6365
diff changeset
623 if (length (ln) >= 2 && strcmp (ln(1:2), "%!"))
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
624 body = [body, "\n"];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
625 if (length(ln) > 2)
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7244
diff changeset
626 body = cstrcat (body, ln(3:end));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
627 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
628 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
629 endwhile
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
630 fclose (fid);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
631 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
632 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
633
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8481
diff changeset
634 ### Test for test for missing features
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
635 %!testif OCTAVE_SOURCE
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
636 %! ## This test should be run
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
637 %! assert (true);
7243
e8d7eed42935 [project @ 2007-12-04 02:10:17 by jwe]
jwe
parents: 7242
diff changeset
638
e8d7eed42935 [project @ 2007-12-04 02:10:17 by jwe]
jwe
parents: 7242
diff changeset
639 ### Disable this test to avoid spurious skipped test for "make check"
e8d7eed42935 [project @ 2007-12-04 02:10:17 by jwe]
jwe
parents: 7242
diff changeset
640 % !testif HAVE_FOOBAR
e8d7eed42935 [project @ 2007-12-04 02:10:17 by jwe]
jwe
parents: 7242
diff changeset
641 % ! ## missing feature. Fail if this test is run
e8d7eed42935 [project @ 2007-12-04 02:10:17 by jwe]
jwe
parents: 7242
diff changeset
642 % ! error("Failed missing feature test");
7242
e4398e3903be [project @ 2007-12-03 23:52:07 by dbateman]
dbateman
parents: 7151
diff changeset
643
6728
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
644 ### Test for a known failure
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
645 %!xtest error("This test is known to fail")
a25173d58101 [project @ 2007-06-14 21:10:48 by jwe]
jwe
parents: 6494
diff changeset
646
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
647 ### example from toeplitz
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
648 %!shared msg
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
649 %! msg="expecting vector arguments";
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
650 %!fail ('toeplitz([])', msg);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
651 %!fail ('toeplitz([1,2],[])', msg);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
652 %!fail ('toeplitz([1,2;3,4])', msg);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
653 %!fail ('toeplitz([1,2],[1,2;3,4])', msg);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
654 %!fail ('toeplitz ([1,2;3,4],[1,2])', msg);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
655 % !fail ('toeplitz','usage: toeplitz'); # usage doesn't generate an error
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
656 % !fail ('toeplitz(1, 2, 3)', 'usage: toeplitz');
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
657 %!test assert (toeplitz ([1,2,3], [1,4]), [1,4; 2,1; 3,2]);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
658 %!demo toeplitz ([1,2,3,4],[1,5,6])
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
659
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
660 ### example from kron
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5681
diff changeset
661 %!#error kron # FIXME suppress these until we can handle output
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
662 %!#error kron(1,2,3)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
663 %!test assert (isempty (kron ([], rand(3, 4))))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
664 %!test assert (isempty (kron (rand (3, 4), [])))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
665 %!test assert (isempty (kron ([], [])))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
666 %!shared A, B
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
667 %!test
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
668 %! A = [1, 2, 3; 4, 5, 6];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
669 %! B = [1, -1; 2, -2];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
670 %!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
671 %!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
672 %!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
673 %!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
674 %!assert (kron (pi, e), pi*e)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
675 %!assert (kron (pi, A), pi*A)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
676 %!assert (kron (A, e), e*A)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
677 %!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
678 %!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
679 %!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
680 %!test
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
681 %! 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];
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
682 %! assert (kron (A, B), res)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
683
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
684 ### an extended demo from specgram
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
685 %!#demo
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
686 %! ## Speech spectrogram
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
687 %! [x, Fs] = auload(file_in_loadpath("sample.wav")); # audio file
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
688 %! step = fix(5*Fs/1000); # one spectral slice every 5 ms
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
689 %! window = fix(40*Fs/1000); # 40 ms data window
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
690 %! fftn = 2^nextpow2(window); # next highest power of 2
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
691 %! [S, f, t] = specgram(x, fftn, Fs, window, window-step);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
692 %! S = abs(S(2:fftn*4000/Fs,:)); # magnitude in range 0<f<=4000 Hz.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
693 %! S = S/max(max(S)); # normalize magnitude so that max is 0 dB.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
694 %! S = max(S, 10^(-40/10)); # clip below -40 dB.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
695 %! S = min(S, 10^(-3/10)); # clip above -3 dB.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
696 %! imagesc(flipud(20*log10(S)), 1);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
697 %! % you should now see a spectrogram in the image window
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
698
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
699
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
700 ### now test test itself
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
701
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
702 %!## usage and error testing
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
703 % !fail ('test','usage.*test') # no args, generates usage()
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
704 % !fail ('test(1,2,3,4)','usage.*test') # too many args, generates usage()
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
705 %!fail ('test("test", "bogus")','unknown flag') # incorrect args
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
706 %!fail ('garbage','garbage.*undefined') # usage on nonexistent function should be
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
707
7940
1bfb88e78027 fix tests
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
708 %!error test # no args, generates usage()
1bfb88e78027 fix tests
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
709 %!error test(1,2,3,4) # too many args, generates usage()
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
710 %!error <unknown flag> test("test", 'bogus'); # incorrect args, generates error()
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
711 %!error <garbage' undefined> garbage # usage on nonexistent function should be
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
712
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
713 %!error test("test", 'bogus'); # test without pattern
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
714
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5642
diff changeset
715 %!test
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5642
diff changeset
716 %! lastwarn(); # clear last warning just in case
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5642
diff changeset
717
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
718 %!warning <warning message> warning('warning message');
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
719
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
720 %!## test of shared variables
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
721 %!shared a # create a shared variable
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
722 %!test a=3; # assign to a shared variable
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
723 %!test assert(a,3) # variable should equal 3
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
724 %!shared b,c # replace shared variables
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
725 %!test assert (!exist("a")); # a no longer exists
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
726 %!test assert (isempty(b)); # variables start off empty
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
727 %!shared a,b,c # recreate a shared variable
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
728 %!test assert (isempty(a)); # value is empty even if it had a previous value
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
729 %!test a=1; b=2; c=3; # give values to all variables
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
730 %!test assert ([a,b,c],[1,2,3]); # test all of them together
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
731 %!test c=6; # update a value
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
732 %!test assert([a, b, c],[1, 2, 6]); # show that the update sticks
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
733 %!shared # clear all shared variables
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
734 %!test assert(!exist("a")) # show that they are cleared
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
735 %!shared a,b,c # support for initializer shorthand
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
736 %! a=1; b=2; c=4;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
737
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
738 %!function x = __test_a(y)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
739 %! x = 2*y;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
740 %!assert(__test_a(2),4); # Test a test function
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
741
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
742 %!function __test_a (y)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
743 %! x = 2*y;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
744 %!test
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
745 %! __test_a(2); # Test a test function with no return value
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
746
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
747 %!function [x,z] = __test_a (y)
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
748 %! x = 2*y;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
749 %! z = 3*y;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
750 %!test # Test a test function with multiple returns
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
751 %! [x,z] = __test_a(3);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
752 %! assert(x,6);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
753 %! assert(z,9);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
754
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
755 %!## test of assert block
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
756 %!assert (isempty([])) # support for test assert shorthand
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
757
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
758 %!## demo blocks
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
759 %!demo # multiline demo block
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
760 %! t=[0:0.01:2*pi]; x=sin(t);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
761 %! plot(t,x);
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
762 %! % you should now see a sine wave in your figure window
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
763 %!demo a=3 # single line demo blocks work too
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
764
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
765 %!## this is a comment block. it can contain anything.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
766 %!##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
767 %! it is the "#" as the block type that makes it a comment
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
768 %! and it stays as a comment even through continuation lines
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
769 %! 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
770
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
771 % !# failure tests. All the following should fail. These tests should
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
772 % !# be disabled unless you are developing test() since users don't
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
773 % !# like to be presented with expected failures. I use % ! to disable.
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
774 % !test error("---------Failure tests. Use test('test','verbose',1)");
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
775 % !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
776 % !bogus # unknown block type
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
777 % !error toeplitz([1,2,3]); # correct usage
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
778 % !test syntax errors) # syntax errors fail properly
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
779 % !shared garbage in # variables must be comma separated
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
780 % !error syntax++error # error test fails on syntax errors
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
781 % !error "succeeds."; # error test fails if code succeeds
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
782 % !error <wrong pattern> error("message") # error pattern must match
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
783 % !demo with syntax error # syntax errors in demo fail properly
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
784 % !shared a,b,c
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
785 % !demo # shared variables not available in demo
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
786 % ! assert(exist("a"))
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
787 % !error
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
788 % ! test('/etc/passwd');
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
789 % ! test("nonexistent file");
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
790 % ! ## These don't signal an error, so the test for an error fails. Note
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
791 % ! ## 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
792 % ! ## so of course the informational message is not printed in the log.