Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 5fefd1eb5fc8a4a937aa0ef89bb048c5 > files > 8

ocaml-ounit-devel-1.0.3-3mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="OUnit" rel="Chapter" href="OUnit.html"><link title="Assertions" rel="Section" href="#5_Assertions">
<link title="Skipping tests " rel="Section" href="#5_Skippingtests">
<link title="Compare Functions" rel="Section" href="#5_CompareFunctions">
<link title="Bracket" rel="Section" href="#5_Bracket">
<link title="Constructing Tests" rel="Section" href="#5_ConstructingTests">
<link title="Retrieve Information from Tests" rel="Section" href="#5_RetrieveInformationfromTests">
<link title="Performing Tests" rel="Section" href="#5_PerformingTests">
<title>OUnit</title>
</head>
<body>
<div class="navbar">&nbsp;<a href="index.html">Up</a>
&nbsp;</div>
<center><h1>Module <a href="type_OUnit.html">OUnit</a></h1></center>
<br>
<pre><span class="keyword">module</span> OUnit: <code class="code">sig</code> <a href="OUnit.html">..</a> <code class="code">end</code></pre>The OUnit library can be used to implement unittests
<p>

    To uses this library link with
      <code class="code">ocamlc oUnit.cmo</code>
    or 
      <code class="code">ocamlopt oUnit.cmx</code><br>
<b>Author(s):</b> Maas-Maarten Zeeman<br>
<hr width="100%">
<br>
<a name="5_Assertions"></a>
<h5>Assertions</h5> 
<p>

    Assertions are the basic building blocks of unittests.<br>
<pre><span class="keyword">val</span> <a name="VALassert_failure"></a>assert_failure : <code class="type">string -> 'a</code></pre><div class="info">
Signals a failure. This will raise an exception with the specified
    string.<br>
<b>Raises</b> <code>Failure</code> to signal a failure<br>
</div>
<pre><span class="keyword">val</span> <a name="VALassert_bool"></a>assert_bool : <code class="type">string -> bool -> unit</code></pre><div class="info">
Signals a failure when bool is false. The string identifies the 
    failure.<br>
<b>Raises</b> <code>Failure</code> to signal a failure<br>
</div>
<pre><span class="keyword">val</span> <a name="VAL(@?)"></a>(@?) : <code class="type">string -> bool -> unit</code></pre><div class="info">
Shorthand for assert_bool<br>
<b>Raises</b> <code>Failure</code> to signal a failure<br>
</div>
<pre><span class="keyword">val</span> <a name="VALassert_string"></a>assert_string : <code class="type">string -> unit</code></pre><div class="info">
Signals a failure when the string is non-empty. The string identifies the
    failure.<br>
<b>Raises</b> <code>Failure</code> to signal a failure<br>
</div>
<pre><span class="keyword">val</span> <a name="VALassert_equal"></a>assert_equal : <code class="type">?cmp:('a -> 'a -> bool) -><br>       ?printer:('a -> string) -> ?msg:string -> 'a -> 'a -> unit</code></pre><div class="info">
Compares two values, when they are not equal a failure is signaled.
    The cmp parameter can be used to pass a different compare function. 
    This parameter defaults to ( = ). The optional printer can be used 
    to convert the value to string, so a nice error message can be 
    formatted. When msg is also set it can be used to identify the failure.<br>
<b>Raises</b> <code>Failure</code> description<br>
</div>
<pre><span class="keyword">val</span> <a name="VALassert_raises"></a>assert_raises : <code class="type">?msg:string -> exn -> (unit -> 'a) -> unit</code></pre><div class="info">
Asserts if the expected exception was raised. When msg is set it can 
    be used to identify the failure<br>
<b>Raises</b> <code>Failure</code> description<br>
</div>
<br>
<a name="5_Skippingtests"></a>
<h5>Skipping tests </h5> 
<p>

   In certain condition test can be written but there is no point running it, because they
   are not significant (missing OS features for example). In this case this is not a failure
   nor a success. Following function allow you to escape test, just as assertion but without
   the same error status.
<p>

   A test skipped is counted as success. A test todo is counted as failure.<br>
<pre><span class="keyword">val</span> <a name="VALskip_if"></a>skip_if : <code class="type">bool -> string -> unit</code></pre><div class="info">
<code class="code">skip cond msg</code> If <code class="code">cond</code> is true, skip the test for the reason explain in <code class="code">msg</code>.
  * For example <code class="code">skip_if (Sys.os_type = "Win32") "Test a doesn't run on windows"</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALtodo"></a>todo : <code class="type">string -> unit</code></pre><div class="info">
The associated test is still to be done, for the reason given.<br>
</div>
<br>
<a name="5_CompareFunctions"></a>
<h5>Compare Functions</h5><br>
<pre><span class="keyword">val</span> <a name="VALcmp_float"></a>cmp_float : <code class="type">?epsilon:float -> float -> float -> bool</code></pre><div class="info">
Compare floats up to a given relative error.<br>
</div>
<br>
<a name="5_Bracket"></a>
<h5>Bracket</h5>
<p>

    A bracket is a functional implementation of the commonly used
    setUp and tearDown feature in unittests. It can be used like this:
<p>

    "MyTestCase" &gt;:: (bracket test_set_up test_fun test_tear_down)<br>
<pre><span class="keyword">val</span> <a name="VALbracket"></a>bracket : <code class="type">(unit -> 'a) -> ('a -> 'b) -> ('a -> 'c) -> unit -> 'c</code></pre><div class="info">
</div>
<br>
<a name="5_ConstructingTests"></a>
<h5>Constructing Tests</h5><br>
<pre><span class="keyword">type</span> <a name="TYPEtest_fun"></a><code class="type"></code>test_fun = <code class="type">unit -> unit</code> </pre>
<div class="info">
The type of test function<br>
</div>

<br><code><span class="keyword">type</span> <a name="TYPEtest"></a><code class="type"></code>test = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">TestCase</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEtest_fun">test_fun</a></code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">TestList</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEtest">test</a> list</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">TestLabel</span> <span class="keyword">of</span> <code class="type">string * <a href="OUnit.html#TYPEtest">test</a></code></code></td>

</tr></table>

<div class="info">
The type of tests<br>
</div>

<pre><span class="keyword">val</span> <a name="VAL(>:)"></a>(&gt;:) : <code class="type">string -> <a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEtest">test</a></code></pre><div class="info">
Create a TestLabel for a test<br>
</div>
<pre><span class="keyword">val</span> <a name="VAL(>::)"></a>(&gt;::) : <code class="type">string -> <a href="OUnit.html#TYPEtest_fun">test_fun</a> -> <a href="OUnit.html#TYPEtest">test</a></code></pre><div class="info">
Create a TestLabel for a TestCase<br>
</div>
<pre><span class="keyword">val</span> <a name="VAL(>:::)"></a>(&gt;:::) : <code class="type">string -> <a href="OUnit.html#TYPEtest">test</a> list -> <a href="OUnit.html#TYPEtest">test</a></code></pre><div class="info">
Create a TestLabel for a TestList<br>
</div>
<br>
Some shorthands which allows easy test construction.
<p>

   Examples:
<p>
<ul>
<li><code class="code">"test1" &gt;: TestCase((fun _ -&gt; ()))</code> =&gt;  
   <code class="code">TestLabel("test2", TestCase((fun _ -&gt; ())))</code></li>
<li><code class="code">"test2" &gt;:: (fun _ -&gt; ())</code> =&gt; 
   <code class="code">TestLabel("test2", TestCase((fun _ -&gt; ())))</code></li>
</ul>
<ul>
<li><code class="code">"test-suite" &gt;::: ["test2" &gt;:: (fun _ -&gt; ());]</code> =&gt;
   <code class="code">TestLabel("test-suite", TestSuite([TestLabel("test2", TestCase((fun _ -&gt; ())))]))</code></li>
</ul>
<br>
<pre><span class="keyword">val</span> <a name="VALtest_decorate"></a>test_decorate : <code class="type">(<a href="OUnit.html#TYPEtest_fun">test_fun</a> -> <a href="OUnit.html#TYPEtest_fun">test_fun</a>) -> <a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEtest">test</a></code></pre><div class="info">
<code class="code">test_decorate g tst</code> Apply <code class="code">g</code> to test function contains in <code class="code">tst</code> tree.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALtest_filter"></a>test_filter : <code class="type">string list -> <a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEtest">test</a> option</code></pre><div class="info">
<code class="code">test_filter paths tst</code> Filter test based on their path string representation.<br>
</div>
<br>
<a name="5_RetrieveInformationfromTests"></a>
<h5>Retrieve Information from Tests</h5><br>
<pre><span class="keyword">val</span> <a name="VALtest_case_count"></a>test_case_count : <code class="type"><a href="OUnit.html#TYPEtest">test</a> -> int</code></pre><div class="info">
Returns the number of available test cases<br>
</div>
<br><code><span class="keyword">type</span> <a name="TYPEnode"></a><code class="type"></code>node = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">ListItem</span> <span class="keyword">of</span> <code class="type">int</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">Label</span> <span class="keyword">of</span> <code class="type">string</code></code></td>

</tr></table>

<div class="info">
Types which represent the path of a test<br>
</div>

<pre><span class="keyword">type</span> <a name="TYPEpath"></a><code class="type"></code>path = <code class="type"><a href="OUnit.html#TYPEnode">node</a> list</code> </pre>
<div class="info">
The path to the test (in reverse order).<br>
</div>

<pre><span class="keyword">val</span> <a name="VALstring_of_node"></a>string_of_node : <code class="type"><a href="OUnit.html#TYPEnode">node</a> -> string</code></pre><div class="info">
Make a string from a node<br>
</div>
<pre><span class="keyword">val</span> <a name="VALstring_of_path"></a>string_of_path : <code class="type"><a href="OUnit.html#TYPEpath">path</a> -> string</code></pre><div class="info">
Make a string from a path. The path will be reversed before it is 
    tranlated into a string<br>
</div>
<pre><span class="keyword">val</span> <a name="VALtest_case_paths"></a>test_case_paths : <code class="type"><a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEpath">path</a> list</code></pre><div class="info">
Returns a list with paths of the test<br>
</div>
<br>
<a name="5_PerformingTests"></a>
<h5>Performing Tests</h5><br>
<br><code><span class="keyword">type</span> <a name="TYPEtest_result"></a><code class="type"></code>test_result = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">RSuccess</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a></code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">RFailure</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a> * string</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">RError</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a> * string</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">RSkip</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a> * string</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">RTodo</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a> * string</code></code></td>

</tr></table>

<div class="info">
The possible results of a test<br>
</div>

<br><code><span class="keyword">type</span> <a name="TYPEtest_event"></a><code class="type"></code>test_event = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">EStart</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a></code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">EEnd</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEpath">path</a></code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">EResult</span> <span class="keyword">of</span> <code class="type"><a href="OUnit.html#TYPEtest_result">test_result</a></code></code></td>

</tr></table>

<div class="info">
Events which occur during a test run<br>
</div>

<pre><span class="keyword">val</span> <a name="VALperform_test"></a>perform_test : <code class="type">(<a href="OUnit.html#TYPEtest_event">test_event</a> -> 'a) -> <a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEtest_result">test_result</a> list</code></pre><div class="info">
Perform the test, allows you to build your own test runner<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrun_test_tt"></a>run_test_tt : <code class="type">?verbose:bool -> <a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEtest_result">test_result</a> list</code></pre><div class="info">
A simple text based test runner. It prints out information
    during the test.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrun_test_tt_main"></a>run_test_tt_main : <code class="type"><a href="OUnit.html#TYPEtest">test</a> -> <a href="OUnit.html#TYPEtest_result">test_result</a> list</code></pre><div class="info">
Main version of the text based test runner. It reads the supplied command 
    line arguments to set the verbose level and limit the number of test to run<br>
</div>
</body></html>