Chapter 13. Test Output <report.h>

The header <report.h> defines several functions that are useful in test programs. These are based on similar functions in the Ada Validation suite (the ACVC Tests) in the package Report.

Briefly, a test program begins by calling the function test. The first parameter gives the name of the test, the second parameter gives a brief description of the test. A test ends with a call to result. This will print the result of the the test in a standard (and machine readable) format, and will typically report PASSED or FAILED.

Between the calls of test and result, are the tests. Any test that fails should call failed with a parameter giving the reason for the failure. Comments may be output using the function comment. Both failed and comment take a format string parameter optionally followed by a number of values to print, and are compatible with printf.

Example 13-1. Test Program


#include <report.h>
int 
main ()
{
  int ans = 1 + 2;
  test ("t1", "Example test program");
  if (ans != 3)
    failed ("error in arithmetic, got %d, expected 3", ans);
  result ();
}

If the test passes, then the output will be as follows:

Example 13-2. Output from Test Program


,.,. t1 GTS Version 0.1
---- t1 Example test program.
==== t1  PASSED ============================.

If the test fails (by changing "1 + 2" to "2 + 2" for example), then we get the following output:

Example 13-3. Output from Failed Test Program


,.,. t1 XTS Version 0.2
---- t1 Example test program.
   * t1 error in arithmetic, got 4, expected 3.
**** t1  FAILED ****************************.

13.1. Test Support Functions