1 /* testlib.c --- reporting test results
2 Jim Blandy <jimb@red-bean.com> --- August 1999 */
16 fprintf (stderr, "%s\n", message);
23 /* If it gets deeper than this, that's probably an error, right? */
24 #define MAX_NESTING 10
27 char *context_name_stack[MAX_NESTING];
29 int context_marker_stack[MAX_NESTING];
32 test_enter_context (char *name)
34 if (depth >= MAX_NESTING)
35 fatal ("test contexts nested too deeply");
37 /* Generate a unique marker value for this context. */
40 context_name_stack[depth] = name;
41 context_marker_stack[depth] = marker;
49 test_restore_context (test_context_t context)
52 fatal ("attempt to leave outermost context");
56 /* Make sure that we're exiting the same context we last entered. */
57 if (context_marker_stack[depth] != context)
58 fatal ("contexts not nested properly");
62 /* Reporting results. */
64 int count_passes, count_fails;
67 print_test_name (char *name)
71 for (i = 0; i < depth; i++)
72 printf ("%s: ", context_name_stack[i]);
78 print_result (char *result, char *name)
80 printf ("%s: ", result);
81 print_test_name (name);
86 test_pass (char *name)
88 print_result ("PASS", name);
93 test_fail (char *name)
95 print_result ("FAIL", name);
100 test_pass_if (char *name, int condition)
102 (condition ? test_pass : test_fail) (name);
106 /* Printing a summary. */
108 /* Print a summary of the reported test results. Return zero if
109 no failures occurred, one otherwise. */
116 printf ("passes: %d\n", count_passes);
117 printf ("failures: %d\n", count_fails);
118 printf ("total tests: %d\n", count_passes + count_fails);
120 return (count_fails != 0);