]> Savannah Git Hosting - gnulib.git/commitdiff
login_tty tests: Be more verbose when the test fails.
authorBruno Haible <bruno@clisp.org>
Fri, 13 Jan 2023 14:15:17 +0000 (15:15 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 13 Jan 2023 14:15:17 +0000 (15:15 +0100)
* tests/test-login_tty.c (main): When the test fails, write a message
into a file.

ChangeLog
tests/test-login_tty.c

index 973596ac7535db237fb89578292f17db0ca822fe..2485ffc9199d098efc76290cb22437ab0d0c074c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-13  Bruno Haible  <bruno@clisp.org>
+
+       login_tty tests: Be more verbose when the test fails.
+       * tests/test-login_tty.c (main): When the test fails, write a message
+       into a file.
+
 2023-01-13  Bruno Haible  <bruno@clisp.org>
 
        qcopy-acl: Make last patch more robust.
index 7ed09f048b3c96c316fa82d189e74d659aa0ece1..294b46d63c55362fa1f071f87950d26d7364d398 100644 (file)
@@ -53,7 +53,8 @@ main ()
   }
 
   /* From here on, we cannot use stderr for error messages any more.
-     If a test fails, just abort.  */
+     If a test fails, write error information into a file named 'err',
+     then abort.  */
 
   /* Check that fd = 0, 1, 2 are now open to the controlling terminal for the
      current process and that it is a session of its own.  */
@@ -61,12 +62,38 @@ main ()
     int fd;
     for (fd = 0; fd < 3; fd++)
       if (!(tcgetpgrp (fd) == getpid ()))
-        abort ();
+        {
+          freopen ("err", "w+", stderr);
+          fprintf (stderr, "tcgetpgrp(%d) = %ld whereas getpid() = %ld\n",
+                   fd, (long) tcgetpgrp (fd), (long) getpid ());
+          fflush (stderr);
+          abort ();
+        }
     for (fd = 0; fd < 3; fd++)
       {
         pid_t sid = tcgetsid (fd);
-        if (!(sid == -1 ? errno == ENOSYS : sid == getpid ()))
-          abort ();
+        if (sid == -1)
+          {
+            if (!(errno == ENOSYS))
+              {
+                freopen ("err", "w+", stderr);
+                fprintf (stderr, "tcgetsid(%d) = -1 and errno = %d\n",
+                         fd, errno);
+                fflush (stderr);
+                abort ();
+              }
+          }
+        else
+          {
+            if (!(sid == getpid ()))
+              {
+                freopen ("err", "w+", stderr);
+                fprintf (stderr, "tcgetsid(%d) = %ld whereas getpid() = %ld\n",
+                         fd, (long) tcgetsid (fd), (long) getpid ());
+                fflush (stderr);
+                abort ();
+              }
+          }
       }
   }