1 /* $Id: libtest.c 5955 2002-12-08 09:28:32Z rra $
3 ** Some utility routines for writing tests.
5 ** Herein are a variety of utility routines for writing tests. All
6 ** routines of the form ok*() take a test number and some number of
7 ** appropriate arguments, check to be sure the results match the expected
8 ** output using the arguments, and print out something appropriate for that
9 ** test number. Other utility routines help in constructing more complex
16 #include "inn/messages.h"
20 /* A global buffer into which message_log_buffer stores error messages. */
25 ** Takes a boolean success value and assumes the test passes if that value
26 ** is true and fails if that value is false.
29 ok(int n, int success)
31 printf("%sok %d\n", success ? "" : "not ", n);
36 ** Takes an expected integer and a seen integer and assumes the test passes
37 ** if those two numbers match.
40 ok_int(int n, int wanted, int seen)
45 printf("not ok %d\n wanted: %d\n seen: %d\n", n, wanted, seen);
50 ** Takes a string and what the string should be, and assumes the test
51 ** passes if those strings match (using strcmp).
54 ok_string(int n, const char *wanted, const char *seen)
60 if (strcmp(wanted, seen) != 0)
61 printf("not ok %d\n wanted: %s\n seen: %s\n", n, wanted, seen);
68 ** An error handler that appends all errors to the errors global. Used by
72 message_log_buffer(int len, const char *fmt, va_list args, int error UNUSED)
76 message = xmalloc(len + 1);
77 vsnprintf(message, len + 1, fmt, args);
79 errors = concat(message, "\n", (char *) 0);
83 new_errors = concat(errors, message, "\n", (char *) 0);
92 ** Turn on the capturing of errors. Errors will be stored in the global
93 ** errors variable where they can be checked by the test suite. Capturing is
94 ** turned off with errors_uncapture.
103 message_handlers_warn(1, message_log_buffer);
108 ** Turn off the capturing of errors again.
111 errors_uncapture(void)
113 message_handlers_warn(1, message_log_stderr);