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 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

13.1.1. The test function

Synopsis
#include <report.h>

void test (const char * name , const char * description );

Description

The test function is called to initialize the test. The arguments name and description are copied into static memory, and used in the reports written by the other functions.

13.1.2. The comment function

Synopsis
#include <report.h>

void comment (const char * s , ... );

Description

The comment function is use to write comments to the test output log. Comments have a distinctive prefix.

13.1.3. The failed function

Synopsis
#include <report.h>

void failed (const char * reason , ... );

Description

The failed function is called to indicate that a test has failed, and gives the reason for the failure.

13.1.4. The result function

Synopsis
#include <report.h>

void result ( );

Description

The result function is called at the end of a test program to print the test result.