]> git.llucax.com Git - personal/website.git/blob - source/proj/mutest/manual.html
Add contents of source/proj/mutest
[personal/website.git] / source / proj / mutest / manual.html
1 <?xml version="1.0" encoding="utf-8" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Docutils 0.10: http://docutils.sourceforge.net/" />
7 <title>mutest - A simple micro unit testing framework for C</title>
8 <meta name="author" content="Leandro Lucarella" />
9 <meta name="date" content="2013-02-17" />
10 <meta name="copyright" content="Leandro Lucarella (2008), released under the BOLA license" />
11 <style type="text/css">
12
13 /*
14 :Author: David Goodger (goodger@python.org)
15 :Id: $Id: html4css1.css 7514 2012-09-14 14:27:12Z milde $
16 :Copyright: This stylesheet has been placed in the public domain.
17
18 Default cascading style sheet for the HTML output of Docutils.
19
20 See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
21 customize this style sheet.
22 */
23
24 /* used to remove borders from tables and images */
25 .borderless, table.borderless td, table.borderless th {
26   border: 0 }
27
28 table.borderless td, table.borderless th {
29   /* Override padding for "table.docutils td" with "! important".
30      The right padding separates the table cells. */
31   padding: 0 0.5em 0 0 ! important }
32
33 .first {
34   /* Override more specific margin styles with "! important". */
35   margin-top: 0 ! important }
36
37 .last, .with-subtitle {
38   margin-bottom: 0 ! important }
39
40 .hidden {
41   display: none }
42
43 a.toc-backref {
44   text-decoration: none ;
45   color: black }
46
47 blockquote.epigraph {
48   margin: 2em 5em ; }
49
50 dl.docutils dd {
51   margin-bottom: 0.5em }
52
53 object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
54   overflow: hidden;
55 }
56
57 /* Uncomment (and remove this text!) to get bold-faced definition list terms
58 dl.docutils dt {
59   font-weight: bold }
60 */
61
62 div.abstract {
63   margin: 2em 5em }
64
65 div.abstract p.topic-title {
66   font-weight: bold ;
67   text-align: center }
68
69 div.admonition, div.attention, div.caution, div.danger, div.error,
70 div.hint, div.important, div.note, div.tip, div.warning {
71   margin: 2em ;
72   border: medium outset ;
73   padding: 1em }
74
75 div.admonition p.admonition-title, div.hint p.admonition-title,
76 div.important p.admonition-title, div.note p.admonition-title,
77 div.tip p.admonition-title {
78   font-weight: bold ;
79   font-family: sans-serif }
80
81 div.attention p.admonition-title, div.caution p.admonition-title,
82 div.danger p.admonition-title, div.error p.admonition-title,
83 div.warning p.admonition-title, .code .error {
84   color: red ;
85   font-weight: bold ;
86   font-family: sans-serif }
87
88 /* Uncomment (and remove this text!) to get reduced vertical space in
89    compound paragraphs.
90 div.compound .compound-first, div.compound .compound-middle {
91   margin-bottom: 0.5em }
92
93 div.compound .compound-last, div.compound .compound-middle {
94   margin-top: 0.5em }
95 */
96
97 div.dedication {
98   margin: 2em 5em ;
99   text-align: center ;
100   font-style: italic }
101
102 div.dedication p.topic-title {
103   font-weight: bold ;
104   font-style: normal }
105
106 div.figure {
107   margin-left: 2em ;
108   margin-right: 2em }
109
110 div.footer, div.header {
111   clear: both;
112   font-size: smaller }
113
114 div.line-block {
115   display: block ;
116   margin-top: 1em ;
117   margin-bottom: 1em }
118
119 div.line-block div.line-block {
120   margin-top: 0 ;
121   margin-bottom: 0 ;
122   margin-left: 1.5em }
123
124 div.sidebar {
125   margin: 0 0 0.5em 1em ;
126   border: medium outset ;
127   padding: 1em ;
128   background-color: #ffffee ;
129   width: 40% ;
130   float: right ;
131   clear: right }
132
133 div.sidebar p.rubric {
134   font-family: sans-serif ;
135   font-size: medium }
136
137 div.system-messages {
138   margin: 5em }
139
140 div.system-messages h1 {
141   color: red }
142
143 div.system-message {
144   border: medium outset ;
145   padding: 1em }
146
147 div.system-message p.system-message-title {
148   color: red ;
149   font-weight: bold }
150
151 div.topic {
152   margin: 2em }
153
154 h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
155 h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
156   margin-top: 0.4em }
157
158 h1.title {
159   text-align: center }
160
161 h2.subtitle {
162   text-align: center }
163
164 hr.docutils {
165   width: 75% }
166
167 img.align-left, .figure.align-left, object.align-left {
168   clear: left ;
169   float: left ;
170   margin-right: 1em }
171
172 img.align-right, .figure.align-right, object.align-right {
173   clear: right ;
174   float: right ;
175   margin-left: 1em }
176
177 img.align-center, .figure.align-center, object.align-center {
178   display: block;
179   margin-left: auto;
180   margin-right: auto;
181 }
182
183 .align-left {
184   text-align: left }
185
186 .align-center {
187   clear: both ;
188   text-align: center }
189
190 .align-right {
191   text-align: right }
192
193 /* reset inner alignment in figures */
194 div.align-right {
195   text-align: inherit }
196
197 /* div.align-center * { */
198 /*   text-align: left } */
199
200 ol.simple, ul.simple {
201   margin-bottom: 1em }
202
203 ol.arabic {
204   list-style: decimal }
205
206 ol.loweralpha {
207   list-style: lower-alpha }
208
209 ol.upperalpha {
210   list-style: upper-alpha }
211
212 ol.lowerroman {
213   list-style: lower-roman }
214
215 ol.upperroman {
216   list-style: upper-roman }
217
218 p.attribution {
219   text-align: right ;
220   margin-left: 50% }
221
222 p.caption {
223   font-style: italic }
224
225 p.credits {
226   font-style: italic ;
227   font-size: smaller }
228
229 p.label {
230   white-space: nowrap }
231
232 p.rubric {
233   font-weight: bold ;
234   font-size: larger ;
235   color: maroon ;
236   text-align: center }
237
238 p.sidebar-title {
239   font-family: sans-serif ;
240   font-weight: bold ;
241   font-size: larger }
242
243 p.sidebar-subtitle {
244   font-family: sans-serif ;
245   font-weight: bold }
246
247 p.topic-title {
248   font-weight: bold }
249
250 pre.address {
251   margin-bottom: 0 ;
252   margin-top: 0 ;
253   font: inherit }
254
255 pre.literal-block, pre.doctest-block, pre.math, pre.code {
256   margin-left: 2em ;
257   margin-right: 2em }
258
259 pre.code .ln { color: grey; } /* line numbers */
260 pre.code, code { background-color: #eeeeee }
261 pre.code .comment, code .comment { color: #5C6576 }
262 pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
263 pre.code .literal.string, code .literal.string { color: #0C5404 }
264 pre.code .name.builtin, code .name.builtin { color: #352B84 }
265 pre.code .deleted, code .deleted { background-color: #DEB0A1}
266 pre.code .inserted, code .inserted { background-color: #A3D289}
267
268 span.classifier {
269   font-family: sans-serif ;
270   font-style: oblique }
271
272 span.classifier-delimiter {
273   font-family: sans-serif ;
274   font-weight: bold }
275
276 span.interpreted {
277   font-family: sans-serif }
278
279 span.option {
280   white-space: nowrap }
281
282 span.pre {
283   white-space: pre }
284
285 span.problematic {
286   color: red }
287
288 span.section-subtitle {
289   /* font-size relative to parent (h1..h6 element) */
290   font-size: 80% }
291
292 table.citation {
293   border-left: solid 1px gray;
294   margin-left: 1px }
295
296 table.docinfo {
297   margin: 2em 4em }
298
299 table.docutils {
300   margin-top: 0.5em ;
301   margin-bottom: 0.5em }
302
303 table.footnote {
304   border-left: solid 1px black;
305   margin-left: 1px }
306
307 table.docutils td, table.docutils th,
308 table.docinfo td, table.docinfo th {
309   padding-left: 0.5em ;
310   padding-right: 0.5em ;
311   vertical-align: top }
312
313 table.docutils th.field-name, table.docinfo th.docinfo-name {
314   font-weight: bold ;
315   text-align: left ;
316   white-space: nowrap ;
317   padding-left: 0 }
318
319 h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
320 h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
321   font-size: 100% }
322
323 ul.auto-toc {
324   list-style-type: none }
325
326 </style>
327 </head>
328 <body>
329 <div class="document" id="mutest-a-simple-micro-unit-testing-framework-for-c">
330 <h1 class="title"><em>mutest</em> - A simple micro unit testing framework for C</h1>
331 <table class="docinfo" frame="void" rules="none">
332 <col class="docinfo-name" />
333 <col class="docinfo-content" />
334 <tbody valign="top">
335 <tr><th class="docinfo-name">Author:</th>
336 <td>Leandro Lucarella</td></tr>
337 <tr><th class="docinfo-name">Contact:</th>
338 <td><a class="first last reference external" href="mailto:llucax&#64;gmail.com">llucax&#64;gmail.com</a></td></tr>
339 <tr><th class="docinfo-name">Version:</th>
340 <td>1.0</td></tr>
341 <tr><th class="docinfo-name">Date:</th>
342 <td>2013-02-17</td></tr>
343 <tr><th class="docinfo-name">Copyright:</th>
344 <td>Leandro Lucarella (2008), released under the <a class="reference external" href="http://blitiri.com.ar/p/bola/">BOLA</a> license</td></tr>
345 </tbody>
346 </table>
347 <div class="abstract topic">
348 <p class="topic-title first">Abstract</p>
349 <p><em>mutest</em> is a micro <a class="reference external" href="http://en.wikipedia.org/wiki/Unit_testing">unit testing</a> framework for C (with some
350 <a class="reference internal" href="#c-support">C++ support</a>). It's mostly an idea (it even comes with
351 2 <a class="reference internal" href="#implementations">implementations</a> of the idea!) with the goal of being easy to use
352 (just write your <a class="reference internal" href="#test-case">test cases</a> grouped in <a class="reference internal" href="#test-suite">test suites</a> and you're
353 set) and so small and simple that you don't mind to copy the files to
354 your project and just use it (i.e., no dependencies).</p>
355 <p>The idea is simple: a source file is a <a class="reference internal" href="#test-suite">test suite</a>, a function is
356 a <a class="reference internal" href="#test-case">test case</a> (special functions can be used for <a class="reference internal" href="#test-suite">test suite</a>
357 <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a>), which can can have several <a class="reference internal" href="#checks">checks</a>.
358 <a class="reference internal" href="#checks">Checks</a> comes in 2 flavors, one that only prints an error, and one that
359 terminates the current <a class="reference internal" href="#test-case">test case</a> too. A (normally) automated <a class="reference internal" href="#test-program">test
360 program</a> run all the <a class="reference internal" href="#test-suite">test suites</a> and print some stats. It fails
361 (returns non-zero) if any <a class="reference internal" href="#test-suite">test suite</a> fails.</p>
362 <p><div style="width: 220px; height: 270px; float: right; margin-left: 1em; margin-top: 1em">
363 <iframe width="220" height="270" style="border: none; outline: none" src="http://tools.flattr.net/widgets/thing.html?thing=1141711"></iframe>
364 </div></p>
365 </div>
366 <div class="contents topic" id="contents">
367 <p class="topic-title first">Contents</p>
368 <ul class="auto-toc simple">
369 <li><a class="reference internal" href="#installation" id="id9">1.&nbsp;&nbsp;&nbsp;Installation</a></li>
370 <li><a class="reference internal" href="#quick-sample" id="id10">2.&nbsp;&nbsp;&nbsp;Quick Sample</a><ul class="auto-toc">
371 <li><a class="reference internal" href="#factorial-c" id="id11">2.1.&nbsp;&nbsp;&nbsp;factorial.c</a></li>
372 <li><a class="reference internal" href="#factorial-test-c" id="id12">2.2.&nbsp;&nbsp;&nbsp;factorial_test.c</a></li>
373 <li><a class="reference internal" href="#exception-test-cpp" id="id13">2.3.&nbsp;&nbsp;&nbsp;exception_test.cpp</a></li>
374 </ul>
375 </li>
376 <li><a class="reference internal" href="#concepts" id="id14">3.&nbsp;&nbsp;&nbsp;Concepts</a><ul class="auto-toc">
377 <li><a class="reference internal" href="#test-program" id="id15">3.1.&nbsp;&nbsp;&nbsp;Test Program</a></li>
378 <li><a class="reference internal" href="#test-suite" id="id16">3.2.&nbsp;&nbsp;&nbsp;Test Suite</a></li>
379 <li><a class="reference internal" href="#test-case" id="id17">3.3.&nbsp;&nbsp;&nbsp;Test Case</a></li>
380 <li><a class="reference internal" href="#checks" id="id18">3.4.&nbsp;&nbsp;&nbsp;Checks</a></li>
381 <li><a class="reference internal" href="#initialization" id="id19">3.5.&nbsp;&nbsp;&nbsp;Initialization</a></li>
382 <li><a class="reference internal" href="#termination" id="id20">3.6.&nbsp;&nbsp;&nbsp;Termination</a></li>
383 </ul>
384 </li>
385 <li><a class="reference internal" href="#c-support" id="id21">4.&nbsp;&nbsp;&nbsp;C++ Support</a></li>
386 <li><a class="reference internal" href="#implementations" id="id22">5.&nbsp;&nbsp;&nbsp;Implementations</a><ul class="auto-toc">
387 <li><a class="reference internal" href="#static-implementations" id="id23">5.1.&nbsp;&nbsp;&nbsp;Static Implementations</a><ul class="auto-toc">
388 <li><a class="reference internal" href="#c-implementation" id="id24">5.1.1.&nbsp;&nbsp;&nbsp;C implementation</a><ul class="auto-toc">
389 <li><a class="reference internal" href="#mkmutest-invocation" id="id25">5.1.1.1.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mkmutest</tt> Invocation</a></li>
390 <li><a class="reference internal" href="#test-program-invocation" id="id26">5.1.1.2.&nbsp;&nbsp;&nbsp;Test Program Invocation</a></li>
391 <li><a class="reference internal" href="#dependencies" id="id27">5.1.1.3.&nbsp;&nbsp;&nbsp;Dependencies</a></li>
392 </ul>
393 </li>
394 </ul>
395 </li>
396 <li><a class="reference internal" href="#dynamic-implementations" id="id28">5.2.&nbsp;&nbsp;&nbsp;Dynamic Implementations</a><ul class="auto-toc">
397 <li><a class="reference internal" href="#python-implementation" id="id29">5.2.1.&nbsp;&nbsp;&nbsp;Python implementation</a><ul class="auto-toc">
398 <li><a class="reference internal" href="#mutest-invocation" id="id30">5.2.1.1.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mutest</tt> Invocation</a></li>
399 <li><a class="reference internal" href="#id8" id="id31">5.2.1.2.&nbsp;&nbsp;&nbsp;Dependencies</a></li>
400 </ul>
401 </li>
402 </ul>
403 </li>
404 </ul>
405 </li>
406 <li><a class="reference internal" href="#reference" id="id32">6.&nbsp;&nbsp;&nbsp;Reference</a><ul class="auto-toc">
407 <li><a class="reference internal" href="#mu-check" id="id33">6.1.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_check()</tt></a></li>
408 <li><a class="reference internal" href="#mu-ensure" id="id34">6.2.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_ensure()</tt></a></li>
409 <li><a class="reference internal" href="#mu-echeck" id="id35">6.3.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_echeck()</tt></a></li>
410 <li><a class="reference internal" href="#mu-eensure" id="id36">6.4.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_eensure()</tt></a></li>
411 </ul>
412 </li>
413 <li><a class="reference internal" href="#about" id="id37">7.&nbsp;&nbsp;&nbsp;About</a></li>
414 </ul>
415 </div>
416 <div class="section" id="installation">
417 <h1><a class="toc-backref" href="#id9">1.&nbsp;&nbsp;&nbsp;Installation</a></h1>
418 <p>Download the <a class="reference external" href="http://proj.llucax.com.ar/home/mutest/releases/mutest.tar.gz">latest distribution tarball</a> and uncompress it.</p>
419 <p>You can also download any release from the <a class="reference external" href="http://proj.llucax.com.ar/home/mutest/releases/">releases directory</a> or get it
420 using <a class="reference external" href="http://git.or.cz/">Git</a> directly from the <a class="reference external" href="http://git.llucax.com.ar/w/software/mutest.git">Git repository</a>.</p>
421 <p>You can get <a class="reference external" href="http://proj.llucax.com.ar/home/mutest/manual.html">this manual</a> too, or a <a class="reference external" href="http://proj.llucax.com.ar/home/mutest/manual.pdf">PDF version</a> of it.</p>
422 <p>To actually install <em>mutest</em> run:</p>
423 <pre class="literal-block">
424 $ make install
425 </pre>
426 <p>Default installation path is <tt class="docutils literal">/usr/local</tt> (because of that, you'll probably
427 need superuser privileges to install to the default location). You can override
428 that by passing the <tt class="docutils literal">prefix</tt> make variable, for example:</p>
429 <pre class="literal-block">
430 $ make prefix=/opt/mutest install
431 </pre>
432 <p>If you want to install just the docs, you can do:</p>
433 <pre class="literal-block">
434 $ make install-doc
435 </pre>
436 <p>Or even <tt class="docutils literal"><span class="pre">install-readme</span></tt>, <tt class="docutils literal"><span class="pre">install-html</span></tt> or <tt class="docutils literal"><span class="pre">install-pdf</span></tt> if you are too
437 picky.</p>
438 <p>If you want to install just one particular <a class="reference internal" href="#implementations">implementation</a>, to can use the
439 <tt class="docutils literal"><span class="pre">install-c</span></tt> and <tt class="docutils literal"><span class="pre">install-py</span></tt> targets.</p>
440 </div>
441 <div class="section" id="quick-sample">
442 <h1><a class="toc-backref" href="#id10">2.&nbsp;&nbsp;&nbsp;Quick Sample</a></h1>
443 <p>You can find some samples in the <a class="reference external" href="http://git.llucax.com.ar/w/software/mutest.git?a=tree;f=sample;h=d8ad4dd9c3428fef5963107c82ab6a5e34ec6e00;hb=HEAD">sample</a> directory.</p>
444 <p>This is an example taken from there. A simple <em>module</em> called <a class="reference internal" href="#factorial-c">factorial.c</a>
445 with its corresponding <a class="reference internal" href="#test-suite">test suite</a> (<a class="reference internal" href="#factorial-test-c">factorial_test.c</a>).</p>
446 <p>You can see some <a class="reference internal" href="#c-support">C++ support</a> in the <a class="reference internal" href="#exception-test-cpp">exception_test.cpp</a> <a class="reference internal" href="#test-suite">test suite</a>.</p>
447 <div class="section" id="factorial-c">
448 <h2><a class="toc-backref" href="#id11">2.1.&nbsp;&nbsp;&nbsp;factorial.c</a></h2>
449 <pre class="code c literal-block">
450 <span class="comment multiline">/*
451  * This file is part of mutest, a simple micro unit testing framework for C.
452  *
453  * mutest was written by Leandro Lucarella &lt;llucax&#64;gmail.com&gt; and is released
454  * under the BOLA license, please see the LICENSE file or visit:
455  * http://blitiri.com.ar/p/bola/
456  *
457  * This is an example module that calculates a factorial.
458  *
459  * Please, read the README file for more details.
460  */</span>
461
462 <span class="keyword type">unsigned</span> <span class="name function">factorial</span><span class="punctuation">(</span><span class="keyword type">unsigned</span> <span class="name">x</span><span class="punctuation">)</span> <span class="punctuation">{</span>
463         <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">x</span> <span class="operator">&lt;=</span> <span class="literal number integer">1</span><span class="punctuation">)</span>
464                 <span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
465         <span class="keyword">return</span> <span class="name">x</span> <span class="operator">*</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="name">x</span><span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">);</span>
466 <span class="punctuation">}</span>
467 </pre>
468 </div>
469 <div class="section" id="factorial-test-c">
470 <h2><a class="toc-backref" href="#id12">2.2.&nbsp;&nbsp;&nbsp;factorial_test.c</a></h2>
471 <pre class="code c literal-block">
472 <span class="comment multiline">/*
473  * This file is part of mutest, a simple micro unit testing framework for C.
474  *
475  * mutest was written by Leandro Lucarella &lt;llucax&#64;gmail.com&gt; and is released
476  * under the BOLA license, please see the LICENSE file or visit:
477  * http://blitiri.com.ar/p/bola/
478  *
479  * This is the factorial module test suite. Each (public) function starting
480  * with mu_test will be picked up by mkmutest as a test case.
481  *
482  * Please, read the README file for more details.
483  */</span>
484
485 <span class="comment preproc">#include &quot;factorial.h&quot;
486 </span>
487 <span class="comment preproc">#include &quot;../mutest.h&quot;
488 </span>
489 <span class="keyword type">void</span> <span class="name function">mu_test_factorial_zero</span><span class="punctuation">()</span> <span class="punctuation">{</span>
490         <span class="keyword type">unsigned</span> <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">);</span>
491         <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">1</span><span class="punctuation">);</span>
492 <span class="punctuation">}</span>
493
494 <span class="keyword type">void</span> <span class="name function">mu_test_factorial_one</span><span class="punctuation">()</span> <span class="punctuation">{</span>
495         <span class="keyword type">unsigned</span> <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="literal number integer">1</span><span class="punctuation">);</span>
496         <span class="comment multiline">/* this test is wrong on purpose, to see how it fails */</span>
497         <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">2</span><span class="punctuation">);</span>
498 <span class="punctuation">}</span>
499
500 <span class="keyword type">void</span> <span class="name function">mu_test_factorial_positive</span><span class="punctuation">()</span> <span class="punctuation">{</span>
501         <span class="keyword type">unsigned</span> <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="literal number integer">2</span><span class="punctuation">);</span>
502         <span class="comment multiline">/* this test is wrong on purpose, to see how it fails */</span>
503         <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">3</span><span class="punctuation">);</span>
504
505         <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="literal number integer">3</span><span class="punctuation">);</span>
506         <span class="comment multiline">/* we don't want to continue if this fails, because the next result
507          * depends on this one. This one will succeed. */</span>
508         <span class="name">mu_ensure</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">6</span><span class="punctuation">);</span>
509
510         <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="name">x</span><span class="punctuation">);</span>
511         <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">720</span><span class="punctuation">);</span>
512
513         <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="literal number integer">4</span><span class="punctuation">);</span>
514         <span class="name">mu_ensure</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">6</span><span class="punctuation">);</span> <span class="comment multiline">/* same as before, but this one will fail. */</span>
515
516         <span class="name">x</span> <span class="operator">=</span> <span class="name">factorial</span><span class="punctuation">(</span><span class="name">x</span><span class="operator">-</span><span class="literal number integer">15</span><span class="punctuation">);</span> <span class="comment multiline">/* and this will never be executed */</span>
517         <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">x</span> <span class="operator">==</span> <span class="literal number integer">362881</span><span class="punctuation">);</span> <span class="comment multiline">/* but if excecuted, will fail */</span>
518 <span class="punctuation">}</span>
519 </pre>
520 </div>
521 <div class="section" id="exception-test-cpp">
522 <h2><a class="toc-backref" href="#id13">2.3.&nbsp;&nbsp;&nbsp;exception_test.cpp</a></h2>
523 <pre class="code c++ literal-block">
524 <span class="comment multiline">/*
525  * This file is part of mutest, a simple micro unit testing framework for C.
526  *
527  * mutest was written by Leandro Lucarella &lt;llucax&#64;gmail.com&gt; and is released
528  * under the BOLA license, please see the LICENSE file or visit:
529  * http://blitiri.com.ar/p/bola/
530  *
531  * This is a C++ module test suite. It shows how to use checks involving
532  * exceptions.
533  *
534  * Please, read the README file for more details.
535  */</span>
536
537 <span class="comment preproc">#include &lt;stdexcept&gt; </span><span class="comment single">// std::out_of_range
538 </span><span class="comment preproc">#include &lt;vector&gt; </span><span class="comment single">// std::vector
539 </span>
540 <span class="comment preproc">#include &quot;../mutest.h&quot;
541 </span>
542 <span class="keyword">extern</span> <span class="literal string">&quot;C&quot;</span> <span class="punctuation">{</span>
543
544 <span class="keyword type">void</span> <span class="name">mu_test_exceptions</span><span class="punctuation">()</span> <span class="punctuation">{</span>
545         <span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator">&lt;</span><span class="keyword type">int</span><span class="operator">&gt;</span> <span class="name">v</span><span class="punctuation">(</span><span class="literal number integer">1</span><span class="punctuation">);</span>
546         <span class="comment single">// ok
547 </span>        <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">v</span><span class="punctuation">.</span><span class="name">at</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">)</span> <span class="operator">==</span> <span class="literal number integer">0</span><span class="punctuation">);</span>
548         <span class="comment single">// throws! This fails
549 </span>        <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">v</span><span class="punctuation">.</span><span class="name">at</span><span class="punctuation">(</span><span class="literal number integer">1</span><span class="punctuation">)</span> <span class="operator">==</span> <span class="literal number integer">0</span><span class="punctuation">);</span>
550         <span class="comment single">// ok, we expect the exception to be thrown, and it does
551 </span>        <span class="name">mu_echeck</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">out_of_range</span><span class="punctuation">,</span> <span class="name">v</span><span class="punctuation">.</span><span class="name">at</span><span class="punctuation">(</span><span class="literal number integer">1</span><span class="punctuation">));</span>
552         <span class="comment single">// fails! We expect this to throw, but it doesn't
553 </span>        <span class="name">mu_echeck</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">out_of_range</span><span class="punctuation">,</span> <span class="name">v</span><span class="punctuation">.</span><span class="name">at</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">));</span>
554         <span class="comment single">// fails again, but this time the show is over (note the &quot;ensure&quot;)
555 </span>        <span class="name">mu_eensure</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">out_of_range</span><span class="punctuation">,</span> <span class="name">v</span><span class="punctuation">.</span><span class="name">at</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">));</span>
556         <span class="comment single">// this will never be executed (it should fail if it is)
557 </span>        <span class="name">mu_check</span><span class="punctuation">(</span><span class="name">v</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">());</span>
558 <span class="punctuation">}</span>
559
560 <span class="punctuation">}</span> <span class="comment single">// extern &quot;C&quot;</span>
561 </pre>
562 </div>
563 </div>
564 <div class="section" id="concepts">
565 <h1><a class="toc-backref" href="#id14">3.&nbsp;&nbsp;&nbsp;Concepts</a></h1>
566 <p><em>mutest</em> is about 4 simple concepts: <a class="reference internal" href="#test-program">test program</a>, <a class="reference internal" href="#test-suite">test suite</a>, <a class="reference internal" href="#test-case">test
567 case</a> and <a class="reference internal" href="#checks">checks</a>. Well, to be honest you probably will need <a class="reference internal" href="#test-suite">test suite</a>
568 <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a> too =)</p>
569 <div class="section" id="test-program">
570 <h2><a class="toc-backref" href="#id15">3.1.&nbsp;&nbsp;&nbsp;Test Program</a></h2>
571 <p>A <strong>test program</strong> is the higher level unit of <em>mutest</em>. The test program is
572 the one in charge of running all your tests. Probably one of the more important
573 features of <em>mutest</em> is that you are not supposed to bother about the test
574 program. So, different <a class="reference internal" href="#implementations">implementations</a> have different ways to tackle this.
575 Some need more or less interactions from your part, and each have their pros
576 and cons.</p>
577 <p>But this is all you need to know for now, for more details see how the test
578 program is implemented by your <a class="reference internal" href="#implementations">implementation</a> of choice.</p>
579 </div>
580 <div class="section" id="test-suite">
581 <h2><a class="toc-backref" href="#id16">3.2.&nbsp;&nbsp;&nbsp;Test Suite</a></h2>
582 <p>A <strong>test suite</strong> is the higher level unit of <em>mutest</em> that you should
583 care about =). Is not much more than a way to group <a class="reference internal" href="#test-case">test cases</a>. Code-wise,
584 a test suite is a C (or C++) module (or compilation unit). Not clear enough?
585 A unit test is an object file (could be a shared object depending on the
586 <a class="reference internal" href="#implementations">implementation</a>). This module should have one or more <a class="reference internal" href="#test-case">test cases</a> and it
587 could have any number (including zero) of <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a>
588 functions.</p>
589 <p>A test suite, is inspected by the <a class="reference internal" href="#test-program">test program</a> for <a class="reference internal" href="#test-case">test cases</a> and
590 <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a> functions, and run them.</p>
591 <p>A test suite fail if one or more <a class="reference internal" href="#test-case">test cases</a> fail, and it's skipped if one or
592 more <a class="reference internal" href="#initialization">initialization</a> functions fail (or, depending on the implementation, if
593 the test suite can't be loaded at all).</p>
594 </div>
595 <div class="section" id="test-case">
596 <h2><a class="toc-backref" href="#id17">3.3.&nbsp;&nbsp;&nbsp;Test Case</a></h2>
597 <p>A <strong>test case</strong> is just a plain function with a special signature and name.
598 A test case function name must start with <tt class="docutils literal">mu_test</tt>, and take no arguments
599 and return nothing. For example:</p>
600 <pre class="literal-block">
601 void mu_test_something(void);
602 </pre>
603 <p>A test case (probably) only make sense if it has <a class="reference internal" href="#checks">checks</a>. A test case succeed
604 only if all its checks succeed too.</p>
605 <p>Test are executed in an <a class="reference internal" href="#implementations">implementation</a>-dependant order, but usually the
606 default order is alphabetical.</p>
607 </div>
608 <div class="section" id="checks">
609 <h2><a class="toc-backref" href="#id18">3.4.&nbsp;&nbsp;&nbsp;Checks</a></h2>
610 <p>Checks are assertions that a <a class="reference internal" href="#test-case">test case</a> must pass (a boolean expression that
611 must evaluate to <em>true</em>). There are 2 big flavors of checks: <strong>check</strong> and
612 <strong>ensure</strong>. <strong>check</strong> just print an error (and <em>mark</em> the <a class="reference internal" href="#test-case">test case</a> as
613 failed) and <strong>ensure</strong> halt the <a class="reference internal" href="#test-case">test case</a> execution, jumping to the next
614 one.</p>
615 <p>For better <a class="reference internal" href="#c-support">C++ support</a> there are check macros that assert that a specified
616 exception is thrown (instead of check for a boolean expression to evaluate to
617 <em>true</em>).</p>
618 <p>You can take a look at the <a class="reference internal" href="#reference">reference</a> to see the different flavors of check
619 macros in more detail.</p>
620 </div>
621 <div class="section" id="initialization">
622 <h2><a class="toc-backref" href="#id19">3.5.&nbsp;&nbsp;&nbsp;Initialization</a></h2>
623 <p>Sometimes you need to setup some environment shared between all the <a class="reference internal" href="#test-case">test
624 cases</a> in a <a class="reference internal" href="#test-suite">test suite</a>. You can use <strong>initialization functions</strong> for this.</p>
625 <p>An initialization function, like a <a class="reference internal" href="#test-case">test case</a>, is a plain C function with
626 a special name and signature. The name must start with <tt class="docutils literal">mu_init</tt> and it must
627 take no arguments, and return an <em>error code</em> (<tt class="docutils literal">0</tt> being success). For
628 example:</p>
629 <pre class="literal-block">
630 int mu_init_something(void);
631 </pre>
632 <p>All initialization functions are executed before any <a class="reference internal" href="#test-case">test case</a>, in an
633 <a class="reference internal" href="#implementations">implementation</a>-dependant order, and if one of them fail (returns non-zero),
634 the whole <a class="reference internal" href="#test-suite">test suite</a> is skipped immediately.</p>
635 </div>
636 <div class="section" id="termination">
637 <h2><a class="toc-backref" href="#id20">3.6.&nbsp;&nbsp;&nbsp;Termination</a></h2>
638 <p><strong>Termination functions</strong> are just like <a class="reference internal" href="#initialization">initialization</a> functions, but they're
639 executed <strong>after</strong> the <a class="reference internal" href="#test-case">test cases</a>, their names start with <tt class="docutils literal">mu_term</tt> and
640 they return nothing. For example:</p>
641 <pre class="literal-block">
642 void mu_term_something(void);
643 </pre>
644 </div>
645 </div>
646 <div class="section" id="c-support">
647 <h1><a class="toc-backref" href="#id21">4.&nbsp;&nbsp;&nbsp;C++ Support</a></h1>
648 <p>You can use <em>mutest</em> with C++, the only care you must take is that, because of
649 C++ <a class="reference external" href="http://en.wikipedia.org/wiki/Name_mangling">name mangling</a> (and <em>mutest</em> relaying on function names), you must
650 declare your <a class="reference internal" href="#test-case">test cases</a> and <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a> functions as
651 <tt class="docutils literal">extern &quot;C&quot;</tt> (see <a class="reference internal" href="#exception-test-cpp">exception_test.cpp</a> for an example).</p>
652 <p><a class="reference internal" href="#checks">Checks</a> become <em>exception-safe</em> when using <em>mutest</em> with a C++ compiler, and
653 2 extra <a class="reference internal" href="#checks">checks</a> designed for C++ get defined (<a class="reference internal" href="#mu-echeck">mu_echeck()</a> and
654 <a class="reference internal" href="#mu-eensure">mu_eensure()</a>). They assert that an expression throws a particular exception.</p>
655 </div>
656 <div class="section" id="implementations">
657 <h1><a class="toc-backref" href="#id22">5.&nbsp;&nbsp;&nbsp;Implementations</a></h1>
658 <p>There are 2 big groups of possible implementations that I can think
659 of: <em>static</em> and <em>dynamic</em>.</p>
660 <p><em>mutest</em> comes with one implementation of each group.</p>
661 <div class="section" id="static-implementations">
662 <h2><a class="toc-backref" href="#id23">5.1.&nbsp;&nbsp;&nbsp;Static Implementations</a></h2>
663 <p>Static implementations can be only written in C/C++ (or other language that is
664 link-compatible with C, like the <a class="reference external" href="http://www.digitalmars.com/d/">D Programming Language</a>, but since one of
665 the main goals of <em>mutest</em> is avoid unnecessary dependencies, you probably
666 don't want to depend on an extra language/compiler to run your tests =).</p>
667 <p>The main advantage is better debugging support, because you can run the <a class="reference internal" href="#test-program">test
668 program</a> in a standard debugger and see what happens with <a class="reference internal" href="#test-case">test cases</a> very
669 naturally.</p>
670 <p>The main disadvantage is, the <a class="reference internal" href="#test-suite">test suites</a> must be figured out in
671 <em>compile-time</em>, usually using some kind of code generation (if you want to
672 avoid writing repetitive code yourself). There's also a limitation in the <a class="reference internal" href="#test-case">test
673 case</a>, <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a> functions names: they should be unique
674 for all the <a class="reference internal" href="#test-program">test program</a>.</p>
675 <div class="section" id="c-implementation">
676 <h3><a class="toc-backref" href="#id24">5.1.1.&nbsp;&nbsp;&nbsp;C implementation</a></h3>
677 <p><em>mutest</em> comes with a C static implementation. Only 3 files are needed:
678 <tt class="docutils literal">mutest.c</tt> (the <em>user-independent</em> part of the <a class="reference internal" href="#test-program">test program</a>), <tt class="docutils literal">mkmutest</tt>
679 (a bash script for generating the <em>user-dependent</em> part of the <a class="reference internal" href="#test-program">test program</a>)
680 and <tt class="docutils literal">mutest.h</tt> (the header file that <a class="reference internal" href="#test-suite">test suites</a> should include).</p>
681 <p>You can copy this 3 files to your project or install them at system-level and
682 use them globally.</p>
683 <p>The procedure is simple, You should compile you <a class="reference internal" href="#test-suite">test suites</a>, <tt class="docutils literal">mutest.c</tt>
684 and the generated output of <tt class="docutils literal">mkmutest</tt> as object files and link them
685 together.</p>
686 <p>For example:</p>
687 <pre class="literal-block">
688 $ cc -c -o mutest.o mutest.c
689 $ cc -c -o test1.o test1.c
690 $ cc -c -o test2.o test2.c
691 $ mkmutest mutest.h test1.o test2.o | cc -xc -c -o runmutest.o -
692 $ cc -o testprg mutest.o test1.o test2.o runmutest.o
693 </pre>
694 <p>Then you can run the <a class="reference internal" href="#test-program">test program</a> invoking it with no arguments:</p>
695 <pre class="literal-block">
696 $ ./testprg
697 </pre>
698 <div class="section" id="mkmutest-invocation">
699 <h4><a class="toc-backref" href="#id25">5.1.1.1.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mkmutest</tt> Invocation</a></h4>
700 <p>This small script take 1 mandatory positional argument: the path to the
701 <tt class="docutils literal">mutest.h</tt> file. All remaining positional arguments should be object files
702 representing <a class="reference internal" href="#test-suite">test suites</a>.</p>
703 </div>
704 <div class="section" id="test-program-invocation">
705 <h4><a class="toc-backref" href="#id26">5.1.1.2.&nbsp;&nbsp;&nbsp;Test Program Invocation</a></h4>
706 <p>The test program can be invoked without arguments, but can take some extra
707 options:</p>
708 <dl class="docutils">
709 <dt><tt class="docutils literal"><span class="pre">-v</span></tt></dt>
710 <dd><p class="first">Be verbose. This is accumulative, when you add extra <tt class="docutils literal"><span class="pre">-v</span></tt> you will
711 get extra verbosity.</p>
712 <p class="last">By default, you just get failed <a class="reference internal" href="#checks">checks</a> printed. If you use a single
713 <tt class="docutils literal"><span class="pre">-v</span></tt>, a summary of failed/passed <a class="reference internal" href="#test-suite">test suites</a>, <a class="reference internal" href="#test-case">test cases</a> and
714 <a class="reference internal" href="#checks">checks</a> will be printed. If an extra <tt class="docutils literal"><span class="pre">-v</span></tt> is used, you'll see the current
715 <a class="reference internal" href="#test-suite">test suite</a> being executed. Another <tt class="docutils literal"><span class="pre">-v</span></tt> and you'll get the current
716 <a class="reference internal" href="#test-case">test case</a>, and another one, and you'll get each <a class="reference internal" href="#checks">check</a>.</p>
717 </dd>
718 </dl>
719 </div>
720 <div class="section" id="dependencies">
721 <h4><a class="toc-backref" href="#id27">5.1.1.3.&nbsp;&nbsp;&nbsp;Dependencies</a></h4>
722 <p>Even when dependencies are kept minimal, there always be a few ;)</p>
723 <p>To use this implementation you just need:</p>
724 <ul class="simple">
725 <li>A C compiler (you already needed that, so...)</li>
726 <li>The <tt class="docutils literal">nm</tt> program (from <a class="reference external" href="http://www.gnu.org/software/binutils/">GNU Binutils</a>, included in virtually any *NIX)</li>
727 <li>The <a class="reference external" href="http://www.gnu.org/software/bash/">GNU Bash</a> shell interpreter (also included in virtually any *NIX)</li>
728 </ul>
729 </div>
730 </div>
731 </div>
732 <div class="section" id="dynamic-implementations">
733 <h2><a class="toc-backref" href="#id28">5.2.&nbsp;&nbsp;&nbsp;Dynamic Implementations</a></h2>
734 <p>Dynamic implementations, on the other hand, can be written in any language that
735 can access to shared objects. The idea is to inspect a shared object for <a class="reference internal" href="#test-suite">test
736 suites</a> and run them, without requiring any information about <a class="reference internal" href="#test-suite">test suites</a>
737 at compile time.</p>
738 <p>There are several advantages in this kind of implementations. The dynamic
739 nature let you completely separate the <a class="reference internal" href="#test-program">test program</a> from the user-written
740 <a class="reference internal" href="#test-suite">test suites</a> and you can choose at <em>run-time</em> what <a class="reference internal" href="#test-suite">test suites</a> to execute
741 by just selecting the correct shared objects. Also, <a class="reference internal" href="#test-case">test case</a>,
742 <a class="reference internal" href="#initialization">initialization</a> and <a class="reference internal" href="#termination">termination</a> functions names only have to be unique in the
743 scope of the <a class="reference internal" href="#test-suite">test suites</a>, because <a class="reference internal" href="#test-suite">test suites</a> are completely isolated in
744 separate shared objects.</p>
745 <p>But everything comes at a price, and the higher price to pay is
746 <em>debuggability</em>. It's a little harder to plug a debugger to a shared object.</p>
747 <div class="section" id="python-implementation">
748 <h3><a class="toc-backref" href="#id29">5.2.1.&nbsp;&nbsp;&nbsp;Python implementation</a></h3>
749 <p>This implementation is much simpler and elegant than the <a class="reference internal" href="#c-implementation">C implementation</a>.
750 Only 2 files are needed: <tt class="docutils literal">mutest</tt> (<a class="reference internal" href="#test-program">test program</a> written in <a class="reference external" href="http://www.python.org/">Python</a> using
751 <a class="reference external" href="http://docs.python.org/library/ctypes.html">ctypes</a> module to access the shared object symbols) and <tt class="docutils literal">mutest.h</tt> (the
752 header file that <a class="reference internal" href="#test-suite">test suites</a> should include).</p>
753 <p>Since both implementations provided by <em>mutest</em> share the same <tt class="docutils literal">mutest.h</tt>,
754 you should define the <tt class="docutils literal">MUTEST_PY</tt> macro when compiling the <a class="reference internal" href="#test-suite">test suites</a> if
755 you will run them using this implementation.</p>
756 <p>As with the <a class="reference internal" href="#c-implementation">C implementation</a>, you can copy this 2 files to your project or
757 install them at system-level and use them globally.</p>
758 <p>The procedure is even simpler than the <a class="reference internal" href="#c-implementation">C implementation</a>: compile and link
759 you <a class="reference internal" href="#test-suite">test suites</a> as shared objects and then run the <tt class="docutils literal">mutest</tt> program
760 passing the shared objects as arguments. For example:</p>
761 <pre class="literal-block">
762 $ cc -c -fPIC -DMUTEST_PY -o test1.o test1.c
763 $ cc -shared -o test1.so test1.o
764 $ cc -c -fPIC -DMUTEST_PY -o test2.o test2.c
765 $ cc -shared -o test2.so test2.o
766 $ mutest test1.so test2.so
767 </pre>
768 <p>That's it.</p>
769 <div class="section" id="mutest-invocation">
770 <h4><a class="toc-backref" href="#id30">5.2.1.1.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mutest</tt> Invocation</a></h4>
771 <p><tt class="docutils literal">mutest</tt> program takes <a class="reference internal" href="#test-suite">test suites</a> shared objects to run as positional
772 arguments. It accepts the same options as the <a class="reference internal" href="#test-program-invocation">C implementation's test
773 program</a> and some extra options are accepted too:</p>
774 <dl class="docutils">
775 <dt><tt class="docutils literal"><span class="pre">--verbose</span></tt></dt>
776 <dd>Alias for <tt class="docutils literal"><span class="pre">-v</span></tt>.</dd>
777 <dt><tt class="docutils literal"><span class="pre">-q</span></tt>, <tt class="docutils literal"><span class="pre">--quiet</span></tt></dt>
778 <dd>Be quiet (no output is shown at all).</dd>
779 <dt><tt class="docutils literal"><span class="pre">-s</span></tt>, <tt class="docutils literal"><span class="pre">--search</span></tt></dt>
780 <dd>Search for <a class="reference internal" href="#test-suite">test suites</a> (*.so) in the current directory and add them
781 to the list of <a class="reference internal" href="#test-suite">test suites</a> to run.</dd>
782 <dt><tt class="docutils literal"><span class="pre">-h</span></tt>, <tt class="docutils literal"><span class="pre">--help</span></tt></dt>
783 <dd>Show a help message and exit.</dd>
784 </dl>
785 </div>
786 <div class="section" id="id8">
787 <h4><a class="toc-backref" href="#id31">5.2.1.2.&nbsp;&nbsp;&nbsp;Dependencies</a></h4>
788 <p>As with the <a class="reference internal" href="#c-implementation">C implementation</a>, some minor dependencies are needed:</p>
789 <ul class="simple">
790 <li><a class="reference external" href="http://www.python.org/">Python</a> (2.5 or later)</li>
791 <li>The <tt class="docutils literal">nm</tt> program (from <a class="reference external" href="http://www.gnu.org/software/binutils/">GNU Binutils</a>, included in virtually any *NIX)</li>
792 </ul>
793 <p>You will need a C compiler for building the <a class="reference internal" href="#test-suite">test suites</a> too, but technically
794 is not needed by <em>mutest</em> itself ;)</p>
795 </div>
796 </div>
797 </div>
798 </div>
799 <div class="section" id="reference">
800 <h1><a class="toc-backref" href="#id32">6.&nbsp;&nbsp;&nbsp;Reference</a></h1>
801 <div class="section" id="mu-check">
802 <h2><a class="toc-backref" href="#id33">6.1.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_check()</tt></a></h2>
803 <dl class="docutils">
804 <dt>Synopsis</dt>
805 <dd><tt class="docutils literal">mu_check(expression)</tt></dd>
806 <dt>Description</dt>
807 <dd>Check that the <tt class="docutils literal">expression</tt> evaluates to <em>true</em>. Continue with the
808 <a class="reference internal" href="#test-case">test case</a> if fail.</dd>
809 <dt>Availability</dt>
810 <dd>Always</dd>
811 <dt>Example</dt>
812 <dd><pre class="first last literal-block">
813 void mu_test(void)
814 {
815     mu_check(5 == 4); /* fail */
816     mu_check(5 == 5); /* excecuted, pass */
817 }
818 </pre>
819 </dd>
820 </dl>
821 </div>
822 <div class="section" id="mu-ensure">
823 <h2><a class="toc-backref" href="#id34">6.2.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_ensure()</tt></a></h2>
824 <dl class="docutils">
825 <dt>Synopsis</dt>
826 <dd><tt class="docutils literal">mu_ensure(expression)</tt></dd>
827 <dt>Description</dt>
828 <dd>Check that the <tt class="docutils literal">expression</tt> evaluates to <em>true</em>. Interrupt the <a class="reference internal" href="#test-case">test
829 case</a> if fail.</dd>
830 <dt>Availability</dt>
831 <dd>Always</dd>
832 <dt>Example</dt>
833 <dd><pre class="first last literal-block">
834 void mu_test(void)
835 {
836     mu_ensure(5 == 4); /* fail */
837     mu_check(5 == 5); /* not excecuted */
838 }
839 </pre>
840 </dd>
841 </dl>
842 </div>
843 <div class="section" id="mu-echeck">
844 <h2><a class="toc-backref" href="#id35">6.3.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_echeck()</tt></a></h2>
845 <dl class="docutils">
846 <dt>Synopsis</dt>
847 <dd><tt class="docutils literal">mu_echeck(class, expression)</tt></dd>
848 <dt>Description</dt>
849 <dd>Check that the <tt class="docutils literal">expression</tt> throws a specific exception <tt class="docutils literal">class</tt> (or
850 subclass). Continue with the <a class="reference internal" href="#test-case">test case</a> if fail.</dd>
851 <dt>Availability</dt>
852 <dd>C++ only</dd>
853 <dt>Example</dt>
854 <dd><pre class="first last literal-block">
855 #include &lt;stdexcept&gt;
856
857 extern &quot;C&quot;
858 {
859     void mu_test(void)
860     {
861         mu_echeck(std::exception, true); /* fail */
862         mu_echeck(std::exception,
863                 throw std::runtime_error(&quot;!&quot;)); /* excecuted, pass */
864     }
865 }
866 </pre>
867 </dd>
868 </dl>
869 </div>
870 <div class="section" id="mu-eensure">
871 <h2><a class="toc-backref" href="#id36">6.4.&nbsp;&nbsp;&nbsp;<tt class="docutils literal">mu_eensure()</tt></a></h2>
872 <dl class="docutils">
873 <dt>Synopsis</dt>
874 <dd><tt class="docutils literal">mu_eensure(class, expression)</tt></dd>
875 <dt>Description</dt>
876 <dd>Check that the <tt class="docutils literal">expression</tt> throws a specific exception <tt class="docutils literal">class</tt> (or
877 subclass). Interrupt the <a class="reference internal" href="#test-case">test case</a> if fail.</dd>
878 <dt>Availability</dt>
879 <dd>C++ only</dd>
880 <dt>Example</dt>
881 <dd><pre class="first last literal-block">
882 #include &lt;stdexcept&gt;
883
884 extern &quot;C&quot;
885 {
886     void mu_test(void)
887     {
888         mu_eensure(std::exception, true); /* fail */
889         mu_echeck(std::exception,
890                 throw std::runtime_error(&quot;!&quot;)); /* not excecuted */
891     }
892 }
893 </pre>
894 </dd>
895 </dl>
896 </div>
897 </div>
898 <div class="section" id="about">
899 <h1><a class="toc-backref" href="#id37">7.&nbsp;&nbsp;&nbsp;About</a></h1>
900 <p>This manual was written using <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>.</p>
901 <!-- Use section numbers -->
902 <!-- Internal Links (aliases): -->
903 <!-- External Links: -->
904 <!-- Substitutions: -->
905 <!-- vim: set filetype=rst expandtab shiftwidth=4 softtabstop=4 : -->
906 </div>
907 </div>
908 </body>
909 </html>