build: Update config.{guess,sub} to {2016-05-15,2016-06-20}.
[gnupg.git] / g10 / test.c
index e9e6b23..e9e2074 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "gpg.h"
 
@@ -62,20 +63,24 @@ static int verbose;
     int expected_result;                       \
                                                \
     tests ++;                                  \
-                                               \
-    printf ("%d. Checking %s...",              \
-           tests, (description) ?: "");        \
-    fflush (stdout);                           \
-                                               \
+    if (verbose)                                \
+      {                                         \
+         printf ("%d. Checking %s...",         \
+               tests, (description) ?: "");    \
+         fflush (stdout);                      \
+      }                                         \
     test_result = (test);                      \
     expected_result = (expected);              \
                                                \
     if (test_result == expected_result)                \
       {                                                \
-        printf (" ok.\n");                     \
+        if (verbose) printf (" ok.\n");         \
       }                                                \
     else                                       \
       {                                                \
+        if (!verbose)                           \
+          printf ("%d. Checking %s...",         \
+                  tests, (description) ?: "");  \
        printf (" failed.\n");                  \
        printf ("  %s == %s failed.\n",         \
                STRINGIFY(test),                \
@@ -123,7 +128,8 @@ exit_tests (int force)
 {
   if (tests_failed == 0)
     {
-      printf ("All %d tests passed.\n", tests);
+      if (verbose)
+        printf ("All %d tests passed.\n", tests);
       exit (!!force);
     }
   else
@@ -138,6 +144,35 @@ exit_tests (int force)
     }
 }
 
+
+/* Prepend FNAME with the srcdir environment variable's value and
+   return a malloced filename.  Caller must release the returned
+   string using test_free.  */
+char *
+prepend_srcdir (const char *fname)
+{
+  static const char *srcdir;
+  char *result;
+
+  if (!srcdir && !(srcdir = getenv ("srcdir")))
+    srcdir = ".";
+
+  result = malloc (strlen (srcdir) + 1 + strlen (fname) + 1);
+  strcpy (result, srcdir);
+  strcat (result, "/");
+  strcat (result, fname);
+  return result;
+}
+
+
+void
+test_free (void *a)
+{
+  if (a)
+    free (a);
+}
+
+
 int
 main (int argc, char *argv[])
 {