aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--g10/t-keydb.c7
-rw-r--r--g10/test.c29
2 files changed, 27 insertions, 9 deletions
diff --git a/g10/t-keydb.c b/g10/t-keydb.c
index 0f176431c..634cb05a7 100644
--- a/g10/t-keydb.c
+++ b/g10/t-keydb.c
@@ -80,8 +80,11 @@ do_test (int argc, char *argv[])
ABORT ("1E42B367 has no user id packet");
uid2 = kb2->pkt->pkt.user_id->name;
- printf ("user id for DBFC6AD9: %s\n", uid1);
- printf ("user id for 1E42B367: %s\n", uid2);
+ if (verbose)
+ {
+ printf ("user id for DBFC6AD9: %s\n", uid1);
+ printf ("user id for 1E42B367: %s\n", uid2);
+ }
TEST_P ("cache consistency", strcmp (uid1, uid2) != 0);
}
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;
}