comparison doc/interpreter/testfun.txi @ 19630:0e1f5a750d00

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:24:46 -0500
parents 9ac2357f19bc 446c46af4b42
children 4197fc428c7d
comparison
equal deleted inserted replaced
19626:37d37297acf8 19630:0e1f5a750d00
5 @c 5 @c
6 @c Octave is free software; you can redistribute it and/or modify it 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 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 8 @c Free Software Foundation; either version 3 of the License, or (at
9 @c your option) any later version. 9 @c your option) any later version.
10 @c 10 @c
11 @c Octave is distributed in the hope that it will be useful, but WITHOUT 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 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 13 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 @c for more details. 14 @c for more details.
15 @c 15 @c
16 @c You should have received a copy of the GNU General Public License 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 17 @c along with Octave; see the file COPYING. If not, see
18 @c <http://www.gnu.org/licenses/>. 18 @c <http://www.gnu.org/licenses/>.
19 19
20 @node Test and Demo Functions 20 @node Test and Demo Functions
43 divide your tests up into blocks, with anything in a separate 43 divide your tests up into blocks, with anything in a separate
44 block evaluated separately. Blocks are introduced by valid keywords like 44 block evaluated separately. Blocks are introduced by valid keywords like
45 @code{test}, @code{function}, or @code{assert} immediately following @samp{%!}. 45 @code{test}, @code{function}, or @code{assert} immediately following @samp{%!}.
46 A block is defined by indentation as in Python. Lines beginning with 46 A block is defined by indentation as in Python. Lines beginning with
47 @samp{%!<whitespace>} are part of the preceeding block. 47 @samp{%!<whitespace>} are part of the preceeding block.
48 48
49 For example: 49 For example:
50 50
51 @example 51 @example
52 @group 52 @group
53 %!test error ("this test fails!"); 53 %!test error ("this test fails!");
196 %!endfunction 196 %!endfunction
197 %!assert (fn(2), 4); 197 %!assert (fn(2), 4);
198 @end group 198 @end group
199 @end example 199 @end example
200 200
201 Note that all previous variables and values are lost when a new 201 Note that all previous variables and values are lost when a new
202 shared block is declared. 202 shared block is declared.
203 203
204 Remember that @code{%!function} begins a new block and that 204 Remember that @code{%!function} begins a new block and that
205 @code{%!endfunction} ends this block. Be aware that until a new block 205 @code{%!endfunction} ends this block. Be aware that until a new block
206 is started, lines starting with @samp{%!<space>} will be discarded as comments. 206 is started, lines starting with @samp{%!<space>} will be discarded as comments.
207 The following is nearly identical to the example above, but does nothing. 207 The following is nearly identical to the example above, but does nothing.
208 208
209 @example 209 @example
217 217
218 @noindent 218 @noindent
219 Because there is a space after @samp{%!} the @code{assert} statement does 219 Because there is a space after @samp{%!} the @code{assert} statement does
220 not begin a new block and this line is treated as a comment. 220 not begin a new block and this line is treated as a comment.
221 221
222 Error and warning blocks are like test blocks, but they only succeed 222 Error and warning blocks are like test blocks, but they only succeed
223 if the code generates an error. You can check the text of the error 223 if the code generates an error. You can check the text of the error
224 is correct using an optional regular expression @code{<pattern>}. 224 is correct using an optional regular expression @code{<pattern>}.
225 For example: 225 For example:
226 226
227 @example 227 @example
228 %!error <passes!> error ("this test passes!"); 228 %!error <passes!> error ("this test passes!");
229 @end example 229 @end example
244 @end group 244 @end group
245 @end example 245 @end example
246 246
247 It is important to automate the tests as much as possible, however 247 It is important to automate the tests as much as possible, however
248 some tests require user interaction. These can be isolated into 248 some tests require user interaction. These can be isolated into
249 demo blocks, which if you are in batch mode, are only run when 249 demo blocks, which if you are in batch mode, are only run when
250 called with @code{demo} or the @code{verbose} option to @code{test}. 250 called with @code{demo} or the @code{verbose} option to @code{test}.
251 The code is displayed before it is executed. For example, 251 The code is displayed before it is executed. For example,
252 252
253 @example 253 @example
254 @group 254 @group
267 funcname example 1: 267 funcname example 1:
268 @var{t} = [0:0.01:2*pi]; @var{x} = sin (@var{t}); 268 @var{t} = [0:0.01:2*pi]; @var{x} = sin (@var{t});
269 plot (@var{t}, @var{x}); 269 plot (@var{t}, @var{x});
270 # you should now see a sine wave in your figure window 270 # you should now see a sine wave in your figure window
271 271
272 Press <enter> to continue: 272 Press <enter> to continue:
273 @end group 273 @end group
274 @end example 274 @end example
275 275
276 Note that demo blocks cannot use any shared variables. This is so 276 Note that demo blocks cannot use any shared variables. This is so
277 that they can be executed by themselves, ignoring all other tests. 277 that they can be executed by themselves, ignoring all other tests.