NAME

CHECK_COMMAND, CHECK_EXEC - simple whole-program testing

SYNOPSIS

#include <ipd.h>

void
CHECK_COMMAND( const char * command,
const char * actual_input,
const char * expected_output,
const char * expected_error,
int expected_exit_code );

void
CHECK_EXEC(
const char * argv[],
const char * actual_input,
const char * expected_output,
const char * expected_error,
int expected_exit_code );

extern const char * ANY_OUTPUT;

extern int ANY_EXIT, ANY_EXIT_ERROR;

DESCRIPTION

These macros are for testing whole programs from outside, rather than functions within the same program. For unit testing of functions, see CHECK(3).

The two macro forms differ only in their first argument, which determines the program-under-test. CHECK_COMMAND's first argument is a single string contain a shell command, which will be interpreted by /bin/sh. CHECK_EXEC's first argument is a NULL-terminated array of strings that specifies the program to run as its 0th element, and also provides the argv for the new process.

The second argument, actual_input, provides the program-under-test's standard input.

The third and fourth arguments, expected_output and expected_error, specify the output that we want the program to produce on its standard output and standard error streams, respectively. For either or both of these arguments, you can pass the constant ANY_OUTPUT to say that that any output should be accepted for that stream.

The fifth argument, expected_exit_code, specifies the status code that you expect the program-under-test to exit with. You may provide the constant ANY_EXIT to say that any status code is okay, or the constant ANY_EXIT_ERROR to say that this check should pass with any non-zero exit code.

EXAMPLE

Suppose there is a program named overlapped in the current directory that should have the following behavior. If sent the three lines

0 0 10
5 0 10
100 0 10

to its standard input, then it should print the output

overlapped
not overlapped

to its standard output, and then exit with status 0. You could verify this behavior with a check like this:

CHECK_COMMAND( "./overlapped",
               "0 0 10\n5 0 10\n100 0 10\n",
               "overlapped\nnot overlapped\n",
               "",
               0 );

BUGS

Probably many, but none yet known.

AUTHOR

Jesse Tov <jesse@cs.northwestern.edu>

SEE ALSO

CHECK(3), assert(3), dup2(2), execve(2), fork(2), mkstemp(3), waitpid(2)