X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Ftest-getopt.c;h=6811a020585bf7c22767fe7ad571567e1bf26d8e;hb=3c8bb39bef81eb88a2aa9bdfd8af00ca151b86fd;hp=591cf0b459ca530fe56f01c4f3153b963c029d0c;hpb=a8ec28b6975fc065b84c511b8108dc3658d2ccd4;p=pspp diff --git a/tests/test-getopt.c b/tests/test-getopt.c index 591cf0b459..6811a02058 100644 --- a/tests/test-getopt.c +++ b/tests/test-getopt.c @@ -18,6 +18,13 @@ #include +/* None of the files accessed by this test are large, so disable the + ftell link warning if we are not using the gnulib ftell module. */ +#if !GNULIB_FTELL +# undef GL_LINK_WARNING +# define GL_LINK_WARNING(ignored) ((void) 0) +#endif + #if GNULIB_GETOPT_GNU # include #endif @@ -27,13 +34,20 @@ #include #include +/* This test intentionally remaps stderr. So, we arrange to have fd 10 + (outside the range of interesting fd's during the test) set up to + duplicate the original stderr. */ + +#define BACKUP_STDERR_FILENO 10 +static FILE *myerr; + #define ASSERT(expr) \ do \ { \ if (!(expr)) \ { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ + fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (myerr); \ abort (); \ } \ } \ @@ -47,6 +61,14 @@ int main (void) { + /* This test validates that stderr is used correctly, so move the + original into fd 10. */ + if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO + || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL) + return 2; + + ASSERT (freopen ("test-getopt.tmp", "w", stderr) == stderr); + /* These default values are required by POSIX. */ ASSERT (optind == 1); ASSERT (opterr != 0); @@ -66,5 +88,8 @@ main (void) test_getopt_long_only (); #endif + ASSERT (fclose (stderr) == 0); + ASSERT (remove ("test-getopt.tmp") == 0); + return 0; }