Channels ▼
RSS

Design

Static Testing C++ Code


Static Testing Programs

More Insights

White Papers

More >>

Reports

More >>

Webcasts

More >>

The assert macro is useless in production code. In fact, in addition to being valuable for internal documentation, its main purpose is to be evaluated in a testing run. In the same logic, Loki and Boost static assertions are most useful while evaluated in a testing compilation.

But what is a testing compilation? It is a test consisting in compiling a test program written for the sole purpose of determining if the compilation is successful or not.

Let's call such a program, whose syntactic correctness is to be checked, a "static testing program." Furthermore, let's call a traditional program, surely syntactically correct, whose runtime correctness is to be checked, a "dynamic testing program."

A dynamic testing program contains a series of dynamic tests, each one of them declaring the result expected from the evaluation of an expression while running the program. Analogously, a static testing program contains a series of tests, each one of them declaring the result expected from the compilation of an expression; that is, whether the expression is syntactically correct (legal) or incorrect (illegal).

The static testing consists in trying to compile each test and observe if any compilation error is output.

A test is considered failed, meaning that an error in the library (or in the test) has been detected, if a code snippet declared as legal generates some compilation errors, or if a code snippet declared as illegal doesn't generate any compilation errors.

Conversely, a test is considered successful, meaning that the behavior has been the expected one, if a code snippet declared as legal doesn't generate any compilation errors, or if a code snippet declared as illegal does generate some compilation errors.

For exception-specification testing, it is possible to specify that a certain operation should cause the raising of a specific exception. Instead, it is not feasible to specify that the compilation of a certain statement should cause a specific compilation error, as compilation errors are not standardized, and vary even with the versions of the same compiler. Therefore, we will be satisfied in distinguishing between legal code and illegal code.


Related Reading






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video