getlogin, getlogin_r: Avoid test failure.
authorBruno Haible <bruno@clisp.org>
Tue, 12 Jan 2010 08:51:24 +0000 (09:51 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 12 Jan 2010 08:51:24 +0000 (09:51 +0100)
ChangeLog
tests/test-getlogin.c
tests/test-getlogin_r.c

index 143056e..fac2f33 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-01-12  Simon Josefsson  <simon@josefsson.org>
+            Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2010-01-11  Eric Blake  <ebb9@byu.net>
 
        tests: avoid more large file warnings
index 6589289..1365108 100644 (file)
@@ -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 @@ main (void)
 
   /* 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__)
index f566e03..68c6812 100644 (file)
@@ -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 @@ main (void)
   /* 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__)