bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getlogin(_r) self-test failures


From: Bruno Haible
Subject: Re: getlogin(_r) self-test failures
Date: Tue, 12 Jan 2010 09:51:15 +0100
User-agent: KMail/1.9.9

Hi Simon,

> These tests are fail unnecessarily easy, I think.  See:
> 
> $ rm -rf m && ./gnulib-tool --create-testdir --dir m --with-tests getlogin_r 
> && cd m && ./configure && nohup make check > log 2>&1

Indeed, I did not think about this situation.

> How about this patch?

Still I'd like to check that if getlogin fails, it is because of the expected
reason. And, as for any skipped test, print a reason why it is being skipped.
Applying this:


2010-01-12  Simon Josefsson  <address@hidden>
            Bruno Haible  <address@hidden>

        getlogin, getlogin_r: Avoid test failure.
        * tests/test-getlogin.c: Include <stdio.h>.
        (main): Skip the test when the function fails because stdin is not a
        tty.
        * tests/test-getlogin_r.c: Include <stdio.h>.
        (main): Skip the test when the function fails because stdin is not a
        tty.

--- tests/test-getlogin.c.orig  Tue Jan 12 09:46:21 2010
+++ tests/test-getlogin.c       Tue Jan 12 09:43:59 2010
@@ -23,6 +23,7 @@
 #include "signature.h"
 SIGNATURE_CHECK (getlogin, char *, (void));
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -35,7 +36,13 @@
 
   /* Test value.  */
   buf = getlogin ();
-  ASSERT (buf != NULL);
+  if (buf == NULL)
+    {
+      /* getlogin() fails when stdin is not connected to a tty.  */
+      ASSERT (! isatty (0));
+      fprintf (stderr, "Skipping test: stdin is not a tty.\n");
+      return 77;
+    }
 
   /* Compare against the value from the environment.  */
 #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
--- tests/test-getlogin_r.c.orig        Tue Jan 12 09:46:21 2010
+++ tests/test-getlogin_r.c     Tue Jan 12 09:46:13 2010
@@ -24,6 +24,7 @@
 SIGNATURE_CHECK (getlogin_r, int, (char *, size_t));
 
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -35,7 +36,13 @@
   /* Test with a large enough buffer.  */
   char buf[1024];
 
-  ASSERT (getlogin_r (buf, sizeof (buf)) == 0);
+  if (getlogin_r (buf, sizeof (buf)) != 0)
+    {
+      /* getlogin_r() fails when stdin is not connected to a tty.  */
+      ASSERT (! isatty (0));
+      fprintf (stderr, "Skipping test: stdin is not a tty.\n");
+      return 77;
+    }
 
   /* Compare against the value from the environment.  */
 #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]