diff doc/interpreter/testfun.txi @ 16190:7fe4ea72ba4d stable

doc: Update 'test' and "fail" documentation With thanks to Iain Cunningham <iain.cunningham@eese.co.uk> * testfun.txi: Add more examples on how to use fail, assert, error, and xtest. * fail.m: Explain more the kind of input that fail needs and how it behaves.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 04 Mar 2013 16:47:22 -0500
parents 72c96de7a403
children 70c47da7e02b
line wrap: on
line diff
--- a/doc/interpreter/testfun.txi	Thu Feb 21 15:18:02 2013 -0500
+++ b/doc/interpreter/testfun.txi	Mon Mar 04 16:47:22 2013 -0500
@@ -267,6 +267,45 @@
 @end group
 @end example
 
+@noindent
+The following trivial code snippet provides examples for the use of
+fail, assert, error and xtest:
+
+@example
+@group
+function output = must_be_zero (@var{input})
+  if (@var{input} != 0)
+    error ("Non-zero input!")
+  endif
+  output = input;
+endfunction
+
+%!fail ("must_be_zero (1)");
+%!assert (must_be_zero (0), 0);
+%!error <Non-zero> must_be_zero (1);
+%!xtest error ("This code generates an error");
+@end group
+@end example
+
+@noindent
+When putting this a file @file{must_be_zero.m}, and running the test, we see
+
+@example
+@group
+test must_be_zero verbose
+
+@result{}
+>>>>> /path/to/must_be_zero.m
+  ***** fail ("must_be_zero (1)");
+  ***** assert (must_be_zero (0), 0);
+  ***** error <Non-zero> must_be_zero (1);
+  ***** xtest error ("This code generates an error");
+!!!!! known failure
+This code generates an error
+PASSES 4 out of 4 tests (1 expected failures)
+@end group
+@end example
+
 @subsubheading Block type summary:
 
 @table @code