From 7521ea075f22293b395517a5d2f4ea213b63d4a9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 12 Jan 2010 09:51:24 +0100 Subject: getlogin, getlogin_r: Avoid test failure. --- tests/test-getlogin.c | 9 ++++++++- tests/test-getlogin_r.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test-getlogin.c b/tests/test-getlogin.c index 65892890da..136510832a 100644 --- a/tests/test-getlogin.c +++ b/tests/test-getlogin.c @@ -23,6 +23,7 @@ #include "signature.h" SIGNATURE_CHECK (getlogin, char *, (void)); +#include #include #include @@ -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__) diff --git a/tests/test-getlogin_r.c b/tests/test-getlogin_r.c index f566e038c8..68c681232b 100644 --- a/tests/test-getlogin_r.c +++ b/tests/test-getlogin_r.c @@ -24,6 +24,7 @@ SIGNATURE_CHECK (getlogin_r, int, (char *, size_t)); #include +#include #include #include @@ -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__) -- cgit v1.2.1