# HG changeset patch # User Rik # Date 1363025259 25200 # Node ID 4dc4da5970e53cb1a508fb4ad1b21c28177a5780 # Parent 98d8d1f4b7f8b4281909876189803d0850f73f45 doc: Clarify how indentation defines %!test blocks. * doc/interpreter/testfun.txi: Clarify how indentation defines %!test blocks. diff --git a/doc/interpreter/testfun.txi b/doc/interpreter/testfun.txi --- a/doc/interpreter/testfun.txi +++ b/doc/interpreter/testfun.txi @@ -41,8 +41,12 @@ Since @code{eval()} will stop at the first error it encounters, you must divide your tests up into blocks, with anything in a separate -block evaluated separately. Blocks are introduced by the keyword -@code{test} immediately following @samp{%!}. For example: +block evaluated separately. Blocks are introduced by valid keywords like +@code{test}, @code{function}, or @code{assert} immediately following @samp{%!}. +A block is defined by indentation as in Python. Lines beginning with +@samp{%!} are part of the preceeding block. + +For example: @example @group @@ -197,6 +201,24 @@ Note that all previous variables and values are lost when a new shared block is declared. +Remember that @code{%!function} begins a new block and that +@code{%!endfunction} ends this block. Be aware that until a new block +is started, lines starting with @samp{%!} will be discarded as comments. +The following is nearly identical to the example above, but does nothing. + +@example +@group +%!function @var{a} = fn (@var{b}) +%! @var{a} = 2*@var{b}; +%!endfunction +%! assert (fn(2), 4); +@end group +@end example + +@noindent +Because there is a space after @samp{%!} the @code{assert} statement does +not begin a new block and this line is treated as a comment. + Error and warning blocks are like test blocks, but they only succeed if the code generates an error. You can check the text of the error is correct using an optional regular expression @code{}.