Fix minor type warnings and risk of memory leak in testutil/driver.c
[openssl.git] / test / testutil / tests.c
index 7a923889d609bdbc9ee1a5ce9918af2084585531..b2d95db8593b08472e74344e558eeef5bf8c4492 100644 (file)
@@ -11,6 +11,7 @@
 #include "output.h"
 #include "tu_local.h"
 
+#include <errno.h>
 #include <string.h>
 #include <ctype.h>
 #include "../../e_os.h"
@@ -26,8 +27,7 @@ void test_fail_message_prefix(const char *prefix, const char *file,
                               const char *left, const char *right,
                               const char *op)
 {
-    test_printf_stderr("%*s# %s: ", subtest_level(), "",
-                       prefix != NULL ? prefix : "ERROR");
+    test_printf_stderr("%s: ", prefix != NULL ? prefix : "ERROR");
     if (type)
         test_printf_stderr("(%s) ", type);
     if (op != NULL) {
@@ -78,7 +78,6 @@ static void test_fail_message_va(const char *prefix, const char *file,
 {
     test_fail_message_prefix(prefix, file, line, type, left, right, op);
     if (fmt != NULL) {
-        test_printf_stderr("%*s# ", subtest_level(), "");
         test_vprintf_stderr(fmt, ap);
         test_printf_stderr("\n");
     }
@@ -135,12 +134,20 @@ void test_error(const char *file, int line, const char *desc, ...)
     test_printf_stderr("\n");
 }
 
+void test_perror(const char *s)
+{
+    /*
+     * Using openssl_strerror_r causes linking issues since it isn't
+     * exported from libcrypto.so
+     */
+    TEST_error("%s: %s", s, strerror(errno));
+}
+
 void test_note(const char *fmt, ...)
 {
     if (fmt != NULL) {
         va_list ap;
 
-        test_printf_stderr("%*s# ", subtest_level(), "");
         va_start(ap, fmt);
         test_vprintf_stderr(fmt, ap);
         va_end(ap);
@@ -152,6 +159,7 @@ void test_note(const char *fmt, ...)
 void test_openssl_errors(void)
 {
     ERR_print_errors_cb(openssl_error_cb, NULL);
+    ERR_clear_error();
 }
 
 /*