testutil: always print errors on failure
[openssl.git] / test / testutil.c
index a16ef0fa0779920a47a93bf13abbc3adb4f1e3f3..c783b4a98a898a249053413ecd78665897235665 100644 (file)
@@ -15,6 +15,8 @@
 #include <string.h>
 #include "e_os.h"
 
+#include <openssl/err.h>
+
 /*
  * Declares the structures needed to register each test case function.
  */
@@ -55,6 +57,14 @@ void add_all_tests(const char *test_case_name, int(*test_fn)(int idx),
     num_test_cases += num;
 }
 
+static void finalize(int success)
+{
+    if (success)
+        ERR_clear_error();
+    else
+        ERR_print_errors_fp(stderr);
+}
+
 int run_tests(const char *test_prog_name)
 {
     int num_failed = 0;
@@ -66,18 +76,22 @@ int run_tests(const char *test_prog_name)
 
     for (i = 0; i != num_tests; ++i) {
         if (all_tests[i].num == -1) {
-            if (!all_tests[i].test_fn()) {
+            int ret = all_tests[i].test_fn();
+            if (!ret) {
                 printf("** %s failed **\n--------\n",
                        all_tests[i].test_case_name);
                 ++num_failed;
             }
+            finalize(ret);
         } else {
             for (j = 0; j < all_tests[i].num; j++) {
-                if (!all_tests[i].param_test_fn(j)) {
+                int ret = all_tests[i].param_test_fn(j);
+                if (!ret) {
                     printf("** %s failed test %d\n--------\n",
                            all_tests[i].test_case_name, j);
                     ++num_failed;
                 }
+                finalize(ret);
             }
         }
     }