This shows you the differences between two versions of the page.
|
gnucap:manual:tech:test_macros [2015/12/11 15:39] 127.0.0.1 external edit |
gnucap:manual:tech:test_macros [2026/03/16 07:17] (current) felixs add assert, expand on untested |
||
|---|---|---|---|
| Line 6: | Line 6: | ||
| All of these macros do nothing when compiled with default settings. They exist so they can be left in the code and enabled or disabled as needed by developers without burdening end users with their clutter. | All of these macros do nothing when compiled with default settings. They exist so they can be left in the code and enabled or disabled as needed by developers without burdening end users with their clutter. | ||
| + | |||
| + | === assert() === | ||
| + | |||
| + | This is not Gnucap specific -- we use this macro precicely as [[https://sourceware.org/glibc/manual/latest/html_node/Consistency-Checking.html|explained]] elsewhere and to document the code. | ||
| + | |||
| + | In addition, we use //commented out asserts// to guide the reader. The intent of a commented out assert is merely to emphasize the idea behind the code. The argument statement is known not to hold in a corner case such as error handling. | ||
| === unreachable() === | === unreachable() === | ||
| Line 50: | Line 56: | ||
| Such blocks of code are suspect when bugs are reported. | Such blocks of code are suspect when bugs are reported. | ||
| + | Following our convention, it is of special importance whether or not a Block carries an initial "untested();" statement. To make this work, implicit blocks are forbidden. Do not write | ||
| + | |||
| + | if(c) stuff(); | ||
| + | |||
| + | but | ||
| + | |||
| + | if(c) { | ||
| + | stuff(); | ||
| + | }else{ | ||
| + | } | ||
| + | |||
| + | Because the latter version implies reachability from our test suite. Sometimes it is advisable to rephrase ''return c;'' as | ||
| + | |||
| + | if(c) { | ||
| + | return true; | ||
| + | }else{ | ||
| + | return false; | ||
| + | }. | ||
| + | |||
| + | Always remember that the absence of an "untested();" statement at a test hook has a clear meaning and reasoning behind it. | ||
| + | |||
| + | === hit counters === | ||
| + | |||
| + | A number at a block start indicates the number of times the block is reached from executing the test suite. This number is straightforward to obtain using "untested()" statements. | ||
| + | |||
| === itested() === | === itested() === | ||
| Line 83: | Line 114: | ||
| and so on. | and so on. | ||
| - | |||
| - | |||