Mercurial > octave
annotate doc/interpreter/testfun.txi @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 050bc580cb60 |
children | c3fd61c59e9c 7fe4ea72ba4d |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14093
diff
changeset
|
1 @c Copyright (C) 2005-2012 David Bateman |
11523 | 2 @c Copyright (C) 2002-2005 Paul Kienzle |
7018 | 3 @c |
4 @c This file is part of Octave. | |
5 @c | |
6 @c Octave is free software; you can redistribute it and/or modify it | |
7 @c under the terms of the GNU General Public License as published by the | |
8 @c Free Software Foundation; either version 3 of the License, or (at | |
9 @c your option) any later version. | |
10 @c | |
11 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
12 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 @c for more details. | |
15 @c | |
16 @c You should have received a copy of the GNU General Public License | |
17 @c along with Octave; see the file COPYING. If not, see | |
18 @c <http://www.gnu.org/licenses/>. | |
5582 | 19 |
20 @node Test and Demo Functions | |
21 @appendix Test and Demo Functions | |
22 @cindex test functions | |
23 | |
24 Octave includes a number of functions to allow the integration of testing | |
25 and demonstration code in the source code of the functions themselves. | |
26 | |
27 @menu | |
28 * Test Functions:: | |
29 * Demonstration Functions:: | |
30 @end menu | |
31 | |
32 @node Test Functions | |
33 @section Test Functions | |
34 | |
35 @DOCSTRING(test) | |
36 | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
37 @code{test} scans the named script file looking for lines which start |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
38 with the identifier @samp{%!}. The prefix is stripped off and the rest |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
39 of the line is processed through the Octave interpreter. If the code |
5582 | 40 generates an error, then the test is said to fail. |
41 | |
42 Since @code{eval()} will stop at the first error it encounters, you must | |
43 divide your tests up into blocks, with anything in a separate | |
44 block evaluated separately. Blocks are introduced by the keyword | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
45 @code{test} immediately following @samp{%!}. For example: |
5582 | 46 |
47 @example | |
48 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
49 %!test error ("this test fails!"); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
50 %!test "test doesn't fail. it doesn't generate an error"; |
5582 | 51 @end group |
52 @end example | |
53 | |
54 When a test fails, you will see something like: | |
55 | |
56 @example | |
57 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
58 ***** test error ("this test fails!") |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
59 !!!!! test failed |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
60 this test fails! |
5582 | 61 @end group |
62 @end example | |
63 | |
64 Generally, to test if something works, you want to assert that it | |
65 produces a correct value. A real test might look something like | |
66 | |
67 @example | |
68 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
69 %!test |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
70 %! @var{a} = [1, 2, 3; 4, 5, 6]; B = [1; 2]; |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
71 %! expect = [ @var{a} ; 2*@var{a} ]; |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
72 %! get = kron (@var{b}, @var{a}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
73 %! if (any (size (expect) != size (get))) |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
74 %! error ("wrong size: expected %d,%d but got %d,%d", |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
75 %! size(expect), size(get)); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
76 %! elseif (any (any (expect != get))) |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
77 %! error ("didn't get what was expected."); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
78 %! endif |
5582 | 79 @end group |
80 @end example | |
81 | |
82 To make the process easier, use the @code{assert} function. For example, | |
83 with @code{assert} the previous test is reduced to: | |
84 | |
85 @example | |
86 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
87 %!test |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
88 %! @var{a} = [1, 2, 3; 4, 5, 6]; @var{b} = [1; 2]; |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
89 %! assert (kron (@var{b}, @var{a}), [ @var{a}; 2*@var{a} ]); |
5582 | 90 @end group |
91 @end example | |
92 | |
93 @code{assert} can accept a tolerance so that you can compare results | |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
94 absolutely or relatively. For example, the following all succeed: |
5582 | 95 |
96 @example | |
97 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
98 %!test assert (1+eps, 1, 2*eps) # absolute error |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
99 %!test assert (100+100*eps, 100, -2*eps) # relative error |
5582 | 100 @end group |
101 @end example | |
102 | |
103 You can also do the comparison yourself, but still have assert | |
104 generate the error: | |
105 | |
106 @example | |
107 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
108 %!test assert (isempty ([])) |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
109 %!test assert ([1, 2; 3, 4] > 0) |
5582 | 110 @end group |
111 @end example | |
112 | |
113 Because @code{assert} is so frequently used alone in a test block, there | |
114 is a shorthand form: | |
115 | |
116 @example | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
117 %!assert (@dots{}) |
5582 | 118 @end example |
119 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
120 @noindent |
5582 | 121 which is equivalent to: |
122 | |
123 @example | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
124 %!test assert (@dots{}) |
5582 | 125 @end example |
126 | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
127 Occasionally a block of tests will depend on having optional |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
128 functionality in Octave. Before testing such blocks the availability of |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
129 the required functionality must be checked. A @code{%!testif HAVE_XXX} |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
130 block will only be run if Octave was compiled with functionality |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
131 @samp{HAVE_XXX}. For example, the sparse single value decomposition, |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
132 @code{svds()}, depends on having the @sc{arpack} library. All of the tests |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
133 for @code{svds} begin with |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
134 |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
135 @example |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
136 %!testif HAVE_ARPACK |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
137 @end example |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
138 |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
139 @noindent |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
140 Review @file{config.h} or @code{octave_config_info ("DEFS")} to see some |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
141 of the possible values to check. |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
142 |
6728 | 143 Sometimes during development there is a test that should work but is |
144 known to fail. You still want to leave the test in because when the | |
145 final code is ready the test should pass, but you may not be able to | |
7001 | 146 fix it immediately. To avoid unnecessary bug reports for these known |
6728 | 147 failures, mark the block with @code{xtest} rather than @code{test}: |
148 | |
149 @example | |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
150 @group |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
151 %!xtest assert (1==0) |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
152 %!xtest fail ("success=1", "error") |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
153 @end group |
6728 | 154 @end example |
155 | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
156 @noindent |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
157 In this case, the test will run and any failure will be reported. |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
158 However, testing is not aborted and subsequent test blocks will be |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
159 processed normally. Another use of @code{xtest} is for statistical |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
160 tests which should pass most of the time but are known to fail |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
161 occasionally. |
6728 | 162 |
5582 | 163 Each block is evaluated in its own function environment, which means |
164 that variables defined in one block are not automatically shared | |
165 with other blocks. If you do want to share variables, then you | |
166 must declare them as @code{shared} before you use them. For example, the | |
167 following declares the variable @var{a}, gives it an initial value (default | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
168 is empty), and then uses it in several subsequent tests. |
5582 | 169 |
170 @example | |
171 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
172 %!shared @var{a} |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
173 %! @var{a} = [1, 2, 3; 4, 5, 6]; |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
174 %!assert (kron ([1; 2], @var{a}), [ @var{a}; 2*@var{a} ]); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
175 %!assert (kron ([1, 2], @var{a}), [ @var{a}, 2*@var{a} ]); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
176 %!assert (kron ([1,2; 3,4], @var{a}), [ @var{a},2*@var{a}; 3*@var{a},4*@var{a} ]); |
5582 | 177 @end group |
178 @end example | |
179 | |
180 You can share several variables at the same time: | |
181 | |
182 @example | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
183 %!shared @var{a}, @var{b} |
5582 | 184 @end example |
185 | |
186 You can also share test functions: | |
187 | |
188 @example | |
189 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
190 %!function @var{a} = fn (@var{b}) |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
191 %! @var{a} = 2*@var{b}; |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
192 %!endfunction |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
193 %!assert (fn(2), 4); |
5582 | 194 @end group |
195 @end example | |
196 | |
197 Note that all previous variables and values are lost when a new | |
198 shared block is declared. | |
199 | |
200 Error and warning blocks are like test blocks, but they only succeed | |
201 if the code generates an error. You can check the text of the error | |
202 is correct using an optional regular expression @code{<pattern>}. | |
203 For example: | |
204 | |
205 @example | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
206 %!error <passes!> error ("this test passes!"); |
5582 | 207 @end example |
208 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
209 If the code doesn't generate an error, the test fails. For example: |
5582 | 210 |
211 @example | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
212 %!error "this is an error because it succeeds."; |
5582 | 213 @end example |
214 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
215 @noindent |
5582 | 216 produces |
217 | |
218 @example | |
219 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
220 ***** error "this is an error because it succeeds."; |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
221 !!!!! test failed: no error |
5582 | 222 @end group |
223 @end example | |
224 | |
225 It is important to automate the tests as much as possible, however | |
226 some tests require user interaction. These can be isolated into | |
227 demo blocks, which if you are in batch mode, are only run when | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
228 called with @code{demo} or the @code{verbose} option to @code{test}. |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
229 The code is displayed before it is executed. For example, |
5582 | 230 |
231 @example | |
232 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
233 %!demo |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
234 %! @var{t} = [0:0.01:2*pi]; @var{x} = sin (@var{t}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
235 %! plot (@var{t}, @var{x}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
236 %! # you should now see a sine wave in your figure window |
5582 | 237 @end group |
238 @end example | |
239 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
240 @noindent |
5582 | 241 produces |
242 | |
243 @example | |
244 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
245 funcname example 1: |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
246 @var{t} = [0:0.01:2*pi]; @var{x} = sin (@var{t}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
247 plot (@var{t}, @var{x}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
248 # you should now see a sine wave in your figure window |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
249 |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
250 Press <enter> to continue: |
5582 | 251 @end group |
252 @end example | |
253 | |
254 Note that demo blocks cannot use any shared variables. This is so | |
255 that they can be executed by themselves, ignoring all other tests. | |
256 | |
257 If you want to temporarily disable a test block, put @code{#} in place | |
258 of the block type. This creates a comment block which is echoed | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
259 in the log file but not executed. For example: |
5582 | 260 |
261 @example | |
262 @group | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
263 %!#demo |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
264 %! @var{t} = [0:0.01:2*pi]; @var{x} = sin (@var{t}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
265 %! plot (@var{t}, @var{x}); |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
266 %! # you should now see a sine wave in your figure window |
5582 | 267 @end group |
268 @end example | |
269 | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
270 @subsubheading Block type summary: |
5582 | 271 |
272 @table @code | |
273 @item %!test | |
274 check that entire block is correct | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
275 |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
276 @item %!testif HAVE_XXX |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
277 check block only if Octave was compiled with feature HAVE_XXX. |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
278 |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
279 @item %!xtest |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
280 check block, report a test failure but do not abort testing. |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
281 |
5582 | 282 @item %!error |
283 check for correct error message | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
284 |
5582 | 285 @item %!warning |
286 check for correct warning message | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
287 |
5582 | 288 @item %!demo |
289 demo only executes in interactive mode | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
290 |
5582 | 291 @item %!# |
292 comment: ignore everything within the block | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
293 |
5582 | 294 @item %!shared x,y,z |
13920
9cf8bd0e13d2
doc: Document %!endfunction keyword
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
295 declare variables for use in multiple tests |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
296 |
5582 | 297 @item %!function |
13920
9cf8bd0e13d2
doc: Document %!endfunction keyword
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
298 define a function for use in multiple tests |
9cf8bd0e13d2
doc: Document %!endfunction keyword
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
299 |
9cf8bd0e13d2
doc: Document %!endfunction keyword
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
300 @item %!endfunction |
9cf8bd0e13d2
doc: Document %!endfunction keyword
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
301 close a function definition |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10496
diff
changeset
|
302 |
5582 | 303 @item %!assert (x, y, tol) |
13920
9cf8bd0e13d2
doc: Document %!endfunction keyword
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
304 shorthand for @code{%!test assert (x, y, tol)} |
5582 | 305 @end table |
306 | |
307 You can also create test scripts for builtins and your own C++ | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
308 functions. To do so put a file with the bare function name (no .m |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
309 extension) in a directory in the load path and it will be discovered by |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
310 the @code{test} function. Alternatively, you can embed tests directly in your |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
311 C++ code: |
5582 | 312 |
313 @example | |
314 @group | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14051
diff
changeset
|
315 /* |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
316 %!test disp ("this is a test") |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14051
diff
changeset
|
317 */ |
5582 | 318 @end group |
319 @end example | |
320 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
321 @noindent |
5582 | 322 or |
323 | |
324 @example | |
325 @group | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14051
diff
changeset
|
326 #if 0 |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
327 %!test disp ("this is a test") |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14051
diff
changeset
|
328 #endif |
5582 | 329 @end group |
330 @end example | |
331 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
332 @noindent |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
333 However, in this case the raw source code will need to be on the load |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
334 path and the user will have to remember to type |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
335 @code{test ("funcname.cc")}. |
5582 | 336 |
337 @DOCSTRING(assert) | |
338 | |
339 @DOCSTRING(fail) | |
340 | |
341 @node Demonstration Functions | |
342 @section Demonstration Functions | |
343 | |
344 @DOCSTRING(demo) | |
345 | |
14051
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
346 @DOCSTRING(example) |
f07f7dd0d4df
doc: Update documentation chapter on test functions
Rik <octave@nomad.inbox5.com>
parents:
13920
diff
changeset
|
347 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8481
diff
changeset
|
348 @DOCSTRING(rundemos) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8481
diff
changeset
|
349 |
10496
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
9080
diff
changeset
|
350 @DOCSTRING(runtests) |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
9080
diff
changeset
|
351 |
5582 | 352 @DOCSTRING(speed) |