aboutsummaryrefslogtreecommitdiffstats
path: root/g10/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/test.c')
-rw-r--r--g10/test.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/g10/test.c b/g10/test.c
index 6910f95ad..e9e6b2342 100644
--- a/g10/test.c
+++ b/g10/test.c
@@ -18,6 +18,9 @@
*/
#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#include "gpg.h"
/* A unit test consists of one or more tests. Tests can be broken
@@ -38,6 +41,10 @@ static int tests;
/* The total number of tests that failed. */
static int tests_failed;
+/* Flag to request verbose diagnostics. This is set if the envvar
+ "verbose" exists and is not the empty string. */
+static int verbose;
+
#define TEST_GROUP(description) \
do { \
test_group = (description); \
@@ -92,7 +99,7 @@ static int tests_failed;
int tests_failed_pre = tests_failed; \
CHECK(description, test, expected); \
if (tests_failed_pre != tests_failed) \
- exit (1); \
+ exit_tests (1); \
} while (0)
/* Call this if something went wrong. */
@@ -102,19 +109,22 @@ static int tests_failed;
if (message) \
printf (" %s\n", (message)); \
\
- exit(1); \
+ exit_tests (1); \
} while (0)
/* You need to fill this function in. */
static void do_test (int argc, char *argv[]);
+
+/* Print stats and call the real exit. If FORCE is set use
+ EXIT_FAILURE even if no test has failed. */
static void
-print_results (void)
+exit_tests (int force)
{
if (tests_failed == 0)
{
printf ("All %d tests passed.\n", tests);
- exit (0);
+ exit (!!force);
}
else
{
@@ -124,7 +134,6 @@ print_results (void)
printf (" (%d of %d groups)",
test_groups_failed, test_groups);
printf ("\n");
-
exit (1);
}
}
@@ -132,10 +141,16 @@ print_results (void)
int
main (int argc, char *argv[])
{
+ const char *s;
+
(void) test_group;
+ s = getenv ("verbose");
+ if (s && *s)
+ verbose = 1;
+
do_test (argc, argv);
- atexit (print_results);
+ exit_tests (0);
- return tests_failed == 0;
+ return !!tests_failed;
}