Add count of leftover temporary files to validate-formats-in-memory.log

diff --git a/MagickCore/resource.c b/MagickCore/resource.c
index 9f206dc..23f534e 100644
--- a/MagickCore/resource.c
+++ b/MagickCore/resource.c
@@ -337,7 +337,7 @@
   return((void *) NULL);
 }
 
-static MagickBooleanType GetPathTemplate(char *path)
+MagickExport MagickBooleanType GetPathTemplate(char *path)
 {
   char
     *directory,
diff --git a/MagickCore/resource_.h b/MagickCore/resource_.h
index abf1dbf..6226e39 100644
--- a/MagickCore/resource_.h
+++ b/MagickCore/resource_.h
@@ -42,6 +42,7 @@
 
 extern MagickExport MagickBooleanType
   AcquireMagickResource(const ResourceType,const MagickSizeType),
+  GetPathTemplate(char *),
   ListMagickResourceInfo(FILE *,ExceptionInfo *),
   RelinquishUniqueFileResource(const char *),
   SetMagickResourceLimit(const ResourceType,const MagickSizeType);
diff --git a/tests/validate.c b/tests/validate.c
index 6769e34..8263c5a 100644
--- a/tests/validate.c
+++ b/tests/validate.c
@@ -47,6 +47,7 @@
 #include <math.h>
 #include "MagickWand/MagickWand.h"
 #include "MagickCore/colorspace-private.h"
+#include "MagickCore/resource_.h"
 #include "MagickCore/string-private.h"
 #include "validate.h"
 
@@ -449,11 +450,21 @@
 %    o exception: return any errors or warnings in this structure.
 %
 */
+
+/* Enable this to count remaining $TMPDIR/magick-* files.
+ * Note that the count includes any files left over from other runs.
+ */
+#define MagickCountTempFiles
+
 static size_t ValidateImageFormatsInMemory(ImageInfo *image_info,
   const char *reference_filename,const char *output_filename,size_t *fail,
   ExceptionInfo *exception)
 {
   char
+#ifdef MagickCountTempFiles
+    SystemCommand[MaxTextExtent],
+    path[MaxTextExtent],
+#endif
     size[MaxTextExtent];
 
   const MagickInfo
@@ -485,6 +496,14 @@
 
   test=0;
   (void) FormatLocaleFile(stdout,"validate image formats in memory:\n");
+
+#ifdef MagickCountTempFiles
+  (void)GetPathTemplate(path);
+  /* Remove file template except for the leading "magick-" */
+  path[strlen(path)-17]='\0';
+  (void) FormatLocaleFile(stdout," tmp path is '%s*'\n",path);
+#endif
+
   for (i=0; reference_formats[i].magick != (char *) NULL; i++)
   {
     magick_info=GetMagickInfo(reference_formats[i].magick,exception);
@@ -653,7 +672,19 @@
           (*fail)++;
           continue;
         }
-      (void) FormatLocaleFile(stdout,"... pass.\n");
+
+#ifdef MagickCountTempFiles
+      (void) FormatLocaleFile(stdout,"... pass, ");
+      (void) fflush(stdout);
+      SystemCommand[0]='\0';
+      (void)strncat(SystemCommand,"echo `ls ",9);
+      (void)strncat(SystemCommand,path,MaxTextExtent-31);
+      (void)strncat(SystemCommand,"* | wc -w` tmp files.",20);
+      (void)system(SystemCommand);
+      (void) fflush(stdout);
+#else
+      (void) FormatLocaleFile(stdout,"... pass\n");
+#endif
     }
   }
   (void) FormatLocaleFile(stdout,