Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

6.2.1 Guidelines for Test Programs

The most important rule to follow when writing testing samples is:

Look for realism.

This motto means that testing samples must be written with the same strictness as real programs are written. In particular, you should avoid “shortcuts” and simplifications.

Don't just play with the preprocessor if you want to prepare a compilation. For instance, using cpp to check whether a header is functional might let your configure accept a header which causes some compiler error. Do not hesitate to check a header with other headers included before, especially required headers.

Make sure the symbols you use are properly defined, i.e., refrain for simply declaring a function yourself instead of including the proper header.

Test programs should not write to standard output. They should exit with status 0 if the test succeeds, and with status 1 otherwise, so that success can be distinguished easily from a core dump or other failure; segmentation violations and other failures produce a nonzero exit status. Unless you arrange for exit to be declared, test programs should return, not exit, from main, because on many systems exit is not declared by default.

Test programs can use #if or #ifdef to check the values of preprocessor macros defined by tests that have already run. For example, if you call AC_HEADER_STDBOOL, then later on in configure.ac you can have a test program that includes stdbool.h conditionally:

     #if HAVE_STDBOOL_H
     # include <stdbool.h>
     #endif

If a test program needs to use or create a data file, give it a name that starts with conftest, such as conftest.data. The configure script cleans up by running ‘rm -f -r conftest*’ after running test programs and if the script is interrupted.


 
 
  Published under the terms of the GNU General Public License Design by Interspire