From 3662d5f8651c7a49dc35a08df70265d3c7537d70 Mon Sep 17 00:00:00 2001
From: Fred Wright <fw@fwright.net>
Date: Sun, 17 Nov 2024 14:51:13 -0800
Subject: [PATCH] test_fdopendir: Add verbose mode.

This simply turns the old 'FEEDBACK' compile-time option into a
runtime option.

Also adds a one-line message on success.
---
 test/test_fdopendir.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/test/test_fdopendir.c b/test/test_fdopendir.c
index 9e340ea..1f761ff 100644
--- a/test/test_fdopendir.c
+++ b/test/test_fdopendir.c
@@ -16,15 +16,17 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <stdlib.h>
 #include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <unistd.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+
+#include <sys/errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 /* Test expected failure case */
 
@@ -45,7 +47,10 @@ int check_failure(int fd, const char *name, const char *exp_sym, int exp_val)
     return 0;
 }
 
-int main() {
+int
+main(int argc, char *argv[])
+{
+    int verbose = 0;
     struct stat st;
     struct dirent *entry;
     int dfd = -1;
@@ -54,6 +59,8 @@ int main() {
     int err;
     int pipefds[2];
 
+    if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1;
+
     /* Test fdopendir with a valid directory fd, then use readdir */
 
     dfd = open(".", O_RDONLY);
@@ -85,9 +92,7 @@ int main() {
             return 1;
         }
 
-#ifdef FEEDBACK
-        printf("%s\n", entry->d_name);
-#endif
+        if (verbose) printf("%s\n", entry->d_name);
     }
 
     /*
@@ -235,6 +240,7 @@ int main() {
     err = check_failure(pipefds[0], "closed", "EBADF", EBADF);
     if (err) return 1;
 
+    printf("%s succeeded.\n", basename(argv[0]));
     return 0;
 }
 
-- 
GitLab