|
| 1 | +--- |
| 2 | +title: OUnit |
| 3 | +language: ocaml |
| 4 | + |
| 5 | +basic_setup: |- |
| 6 | + ```ocaml |
| 7 | + (* TODO *) |
| 8 | + ``` |
| 9 | + |
| 10 | +assertions: |
| 11 | + - name: assert_failure |
| 12 | + id: assert-failure |
| 13 | + desc: |- |
| 14 | + ```ocaml |
| 15 | + val assert_failure : string -> 'a |
| 16 | + ``` |
| 17 | + Signals a failure. |
| 18 | + This will raise an exception with the specified string. |
| 19 | + |
| 20 | + - name: assert_bool |
| 21 | + id: assert-bool |
| 22 | + desc: |- |
| 23 | + ```ocaml |
| 24 | + val assert_bool : string -> bool -> unit |
| 25 | + ``` |
| 26 | + Signals a failure when bool is false. |
| 27 | + The string identifies the failure. |
| 28 | + |
| 29 | + - name: assert_string |
| 30 | + id: assert-string |
| 31 | + desc: |- |
| 32 | + ```ocaml |
| 33 | + val assert_string : string -> unit |
| 34 | + ``` |
| 35 | + Signals a failure when the string is non-empty. |
| 36 | + The string identifies the failure. |
| 37 | + |
| 38 | + - name: assert_equal |
| 39 | + id: assert-equal |
| 40 | + desc: |- |
| 41 | + ```ocaml |
| 42 | + val assert_equal : |
| 43 | + ?ctxt:test_ctxt -> |
| 44 | + ?cmp:('a -> 'a -> bool) -> |
| 45 | + ?printer:('a -> string) -> |
| 46 | + ?pp_diff:(Format.formatter -> 'a * 'a -> unit) -> |
| 47 | + ?msg:string -> |
| 48 | + 'a -> 'a -> unit |
| 49 | + ``` |
| 50 | + |
| 51 | + Compares two values, when they are not equal a failure is signaled. |
| 52 | + |
| 53 | + `assert_equal expected real` |
| 54 | + |
| 55 | + `ctxt` : if provided, always print expected and real value |
| 56 | + |
| 57 | + `cmp` : customize function to compare, default is `=` |
| 58 | + |
| 59 | + `printer` : value printer, don't print value otherwise |
| 60 | + |
| 61 | + `pp_diff` : if not equal, ask a custom display of the difference using |
| 62 | + `diff fmt exp real` where `fmt` is the formatter to use |
| 63 | + |
| 64 | + `msg` : custom message to identify the failure |
| 65 | + |
| 66 | + - name: assert_raises |
| 67 | + desc: |- |
| 68 | + ```ocaml |
| 69 | + val assert_raises : |
| 70 | + ?msg:string -> |
| 71 | + exn -> (unit -> 'a) -> unit |
| 72 | + ``` |
| 73 | + Asserts if the expected exception was raised. |
| 74 | + |
| 75 | + `msg` : identify the failure |
| 76 | + |
| 77 | +compare_functions: |
| 78 | + - name: cmp_float |
| 79 | + id: cmp-float |
| 80 | + desc: |- |
| 81 | + ```ocaml |
| 82 | + val cmp_float : ?epsilon:float -> float -> float -> bool |
| 83 | + ``` |
| 84 | + Compare floats up to a given relative error. |
| 85 | + |
| 86 | + `epsilon`: if the difference is smaller epsilon values are equal |
| 87 | + |
| 88 | +constructing: |
| 89 | + - name: '>:' |
| 90 | + id: label-test |
| 91 | + desc: |- |
| 92 | + ```ocaml |
| 93 | + val (>:) : string -> test -> test |
| 94 | + ``` |
| 95 | + Create a TestLabel for a test |
| 96 | + - name: '>::' |
| 97 | + id: label-test-case |
| 98 | + desc: |- |
| 99 | + ```ocaml |
| 100 | + val (>::) : string -> test_fun -> test |
| 101 | + ``` |
| 102 | + Create a TestLabel for a TestCase |
| 103 | + - name: '>:::' |
| 104 | + id: label-test-list |
| 105 | + desc: |- |
| 106 | + ```ocaml |
| 107 | + val (>:::) : string -> test list -> test |
| 108 | + ``` |
| 109 | + Create a TestLabel for a TestList |
| 110 | + - name: test_case |
| 111 | + id: test-case |
| 112 | + desc: |- |
| 113 | + ```ocaml |
| 114 | + val test_case : ?length:test_length -> test_fun -> test |
| 115 | + ``` |
| 116 | + Generic function to create a test case. |
| 117 | + - name: test_list |
| 118 | + id: test-list |
| 119 | + desc: |- |
| 120 | + ```ocaml |
| 121 | + val test_list : test list -> test |
| 122 | + ``` |
| 123 | + Generic function to create a test list. |
| 124 | +--- |
| 125 | + |
| 126 | +<h1>{{ page.title }}</h1> |
| 127 | +<p><a href="http://ounit.forge.ocamlcore.org/api-ounit/">OUnit</a> can be used to test OCaml code.</p> |
| 128 | + |
| 129 | +<h2>Basic Setup</h2> |
| 130 | +{{ page.basic_setup | markdownify }} |
| 131 | + |
| 132 | +<h2>Assertions</h2> |
| 133 | +<dl> |
| 134 | +{% for a in page.assertions %} |
| 135 | +<dt id="{{ a.id }}" class="f4"><code>{{ a.name }}</code></dt><dd>{{ a.desc | markdownify }}</dd> |
| 136 | +{% endfor %} |
| 137 | +</dl> |
| 138 | + |
| 139 | +<h2>Compare Functions</h2> |
| 140 | +<dl> |
| 141 | +{% for a in page.compare_functions %} |
| 142 | +<dt id="{{ a.id }}" class="f4"><code>{{ a.name }}</code></dt><dd>{{ a.desc | markdownify }}</dd> |
| 143 | +{% endfor %} |
| 144 | +</dl> |
| 145 | + |
| 146 | + |
| 147 | +<h2>Constructing</h2> |
| 148 | +<dl> |
| 149 | +{% for a in page.constructing %} |
| 150 | +<dt id="{{ a.id }}" class="f4"><code>{{ a.name }}</code></dt><dd>{{ a.desc | markdownify }}</dd> |
| 151 | +{% endfor %} |
| 152 | +</dl> |
0 commit comments