X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-getlogin.c;h=54e48e9d53216b60e6f04b105caa423de127e867;hb=b0f648cf3ba46b06c44bf84ec74480a42f8666ba;hp=65892890da98c0373e9d82320d0be9fbc6a5c28c;hpb=39331312abd1f8eb8578ef30f7cb5d3ea8e0f4fd;p=gnulib.git diff --git a/tests/test-getlogin.c b/tests/test-getlogin.c index 65892890d..54e48e9d5 100644 --- a/tests/test-getlogin.c +++ b/tests/test-getlogin.c @@ -1,5 +1,5 @@ /* Test of getting user name. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ #include "signature.h" SIGNATURE_CHECK (getlogin, char *, (void)); +#include +#include #include #include @@ -35,7 +37,26 @@ main (void) /* Test value. */ buf = getlogin (); - ASSERT (buf != NULL); + if (buf == NULL) + { + if (errno == ENOENT) + { + /* This can happen on GNU/Linux. */ + fprintf (stderr, "Skipping test: no entry in utmp file.\n"); + return 77; + } + + /* getlogin() fails when stdin is not connected to a tty. */ + ASSERT (errno == ENOTTY + || errno == EINVAL /* seen on Linux/SPARC */ + || errno == ENXIO + ); +#if !defined __hpux /* On HP-UX 11.11 it fails anyway. */ + ASSERT (! isatty (0)); +#endif + 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__)