tests: skip fseek/ftell tests if ungetc is broken
authorEric Blake <ebb9@byu.net>
Wed, 25 Feb 2009 14:42:31 +0000 (07:42 -0700)
committerEric Blake <ebb9@byu.net>
Wed, 25 Feb 2009 20:47:14 +0000 (13:47 -0700)
* m4/ungetc.m4: New file.
* modules/fseek-tests: Split test, so ungetc dependency is
separate from rest of test.
* modules/fseeko-tests: Likewise.
* modules/ftell-tests: Likewise.
* modules/ftello-tests: Likewise.
* tests/test-fseek.c (main): Isolate ungetc dependency.
* tests/test-fseeko.c (main): Likewise.
* tests/test-ftell.c (main): Likewise.
* tests/test-ftello.c (main): Likewise.
* tests/test-fseek2.sh: New file.
* tests/test-fseeko2.sh: Likewise.
* tests/test-ftell2.sh: Likewise.
* tests/test-ftello2.sh: Likewise.

14 files changed:
ChangeLog
m4/ungetc.m4 [new file with mode: 0644]
modules/fseek-tests
modules/fseeko-tests
modules/ftell-tests
modules/ftello-tests
tests/test-fseek.c
tests/test-fseek2.sh [new file with mode: 0755]
tests/test-fseeko.c
tests/test-fseeko2.sh [new file with mode: 0755]
tests/test-ftell.c
tests/test-ftell2.sh [new file with mode: 0755]
tests/test-ftello.c
tests/test-ftello2.sh [new file with mode: 0755]

index beff539..5976300 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-02-25  Eric Blake  <ebb9@byu.net>
+
+       tests: skip fseek/ftell tests if ungetc is broken
+       * m4/ungetc.m4: New file.
+       * modules/fseek-tests: Split test, so ungetc dependency is
+       separate from rest of test.
+       * modules/fseeko-tests: Likewise.
+       * modules/ftell-tests: Likewise.
+       * modules/ftello-tests: Likewise.
+       * tests/test-fseek.c (main): Isolate ungetc dependency.
+       * tests/test-fseeko.c (main): Likewise.
+       * tests/test-ftell.c (main): Likewise.
+       * tests/test-ftello.c (main): Likewise.
+       * tests/test-fseek2.sh: New file.
+       * tests/test-fseeko2.sh: Likewise.
+       * tests/test-ftell2.sh: Likewise.
+       * tests/test-ftello2.sh: Likewise.
+
 2009-02-25  Ondřej Vašík  <ovasik@redhat.com>
 
        test-getaddrinfo: fix usage of skip return code 77
        the parent of a directory specified on the command-line.
 
 2009-02-17  James Youngman  <jay@gnu.org>
-            Bruno Haible  <bruno@clisp.org>
+           Bruno Haible  <bruno@clisp.org>
 
        * m4/include_next.m4: Reformulate comment.
 
diff --git a/m4/ungetc.m4 b/m4/ungetc.m4
new file mode 100644 (file)
index 0000000..9236d4c
--- /dev/null
@@ -0,0 +1,36 @@
+# ungetc.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+
+  AC_CACHE_CHECK([whether ungetc works on arbitrary bytes],
+    [gl_cv_func_ungetc_works],
+    [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <stdio.h>
+      ]], [FILE *f; long l;
+          if (!(f = fopen ("conftest.tmp", "w+"))) return 1;
+          if (fputs ("abc", f) < 0) return 2;
+          rewind (f);
+          if (fgetc (f) != 'a') return 3;
+          if (fgetc (f) != 'b') return 4;
+          if (ungetc ('d', f) != 'd') return 5;
+          if (ftell (f) != 1) return 6;
+          if (fgetc (f) != 'd') return 7;
+          if (ftell (f) != 2) return 8;
+          if (fseek (f, 0, SEEK_CUR) != 0) return 9;
+          if (ftell (f) != 2) return 10;
+          if (fgetc (f) != 'c') return 11;
+          fclose (f); remove ("conftest.tmp");])],
+       [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
+       [gl_cv_func_ungetc_works='guessing no'])
+    ])
+  if test "$gl_cv_func_ungetc_works" != yes; then
+    AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
+      [Define to 1 if ungetc is broken when used on arbitrary bytes.])
+  fi
+])
index a1c97fe..7f10d48 100644 (file)
@@ -1,12 +1,15 @@
 Files:
 tests/test-fseek.c
 tests/test-fseek.sh
+tests/test-fseek2.sh
+m4/ungetc.m4
 
 Depends-on:
 
 configure.ac:
+gl_FUNC_UNGETC_WORKS
 
 Makefile.am:
-TESTS += test-fseek.sh
+TESTS += test-fseek.sh test-fseek2.sh
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
 check_PROGRAMS += test-fseek
index 8e077ec..b01ed58 100644 (file)
@@ -1,12 +1,15 @@
 Files:
 tests/test-fseeko.c
 tests/test-fseeko.sh
+tests/test-fseeko2.sh
+m4/ungetc.m4
 
 Depends-on:
 
 configure.ac:
+gl_FUNC_UNGETC_WORKS
 
 Makefile.am:
-TESTS += test-fseeko.sh
+TESTS += test-fseeko.sh test-fseeko2.sh
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
 check_PROGRAMS += test-fseeko
index ad82ded..ce5f479 100644 (file)
@@ -1,13 +1,16 @@
 Files:
 tests/test-ftell.c
 tests/test-ftell.sh
+tests/test-ftell2.sh
+m4/ungetc.m4
 
 Depends-on:
 binary-io
 
 configure.ac:
+gl_FUNC_UNGETC_WORKS
 
 Makefile.am:
-TESTS += test-ftell.sh
+TESTS += test-ftell.sh test-ftell2.sh
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
 check_PROGRAMS += test-ftell
index 48179bc..cc7f46e 100644 (file)
@@ -1,13 +1,16 @@
 Files:
 tests/test-ftello.c
 tests/test-ftello.sh
+tests/test-ftello2.sh
+m4/ungetc.m4
 
 Depends-on:
 binary-io
 
 configure.ac:
+gl_FUNC_UNGETC_WORKS
 
 Makefile.am:
-TESTS += test-ftello.sh
+TESTS += test-ftello.sh test-ftello2.sh
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
 check_PROGRAMS += test-ftello
index 24cf3b8..6ba3788 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of fseek() function.
-   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009 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
     }                                                                       \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -47,10 +51,19 @@ main (int argc, char **argv)
       ASSERT (ch == '#');
       ASSERT (ungetc (ch, stdin) == ch);
       ASSERT (fseek (stdin, 2, SEEK_SET) == 0);
-      /* Test that fseek discards random ungetc data.  */
       ch = fgetc (stdin);
       ASSERT (ch == '/');
-      ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+      if (2 < argc)
+        {
+          if (FUNC_UNGETC_BROKEN)
+            {
+              fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+                     stderr);
+              return 77;
+            }
+          /* Test that fseek discards random ungetc data.  */
+          ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+        }
       ASSERT (fseek (stdin, 0, SEEK_END) == 0);
       ASSERT (fgetc (stdin) == EOF);
       /* Test that fseek resets end-of-file marker.  */
diff --git a/tests/test-fseek2.sh b/tests/test-fseek2.sh
new file mode 100755 (executable)
index 0000000..a4c9cb7
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-fseek${EXEEXT} 1 2 < "$srcdir/test-fseek2.sh"
index 3a1383b..9c284da 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of fseeko() function.
-   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009 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
     }                                                                       \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -50,10 +54,19 @@ main (int argc, char **argv)
       ASSERT (ch == '#');
       ASSERT (ungetc (ch, stdin) == ch);
       ASSERT (fseeko (stdin, 2, SEEK_SET) == 0);
-      /* Test that fseek discards random ungetc data.  */
       ch = fgetc (stdin);
       ASSERT (ch == '/');
-      ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+      if (2 < argc)
+        {
+          if (FUNC_UNGETC_BROKEN)
+            {
+              fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+                     stderr);
+              return 77;
+            }
+          /* Test that fseek discards random ungetc data.  */
+          ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+        }
       ASSERT (fseeko (stdin, 0, SEEK_END) == 0);
       ASSERT (fgetc (stdin) == EOF);
       /* Test that fseek resets end-of-file marker.  */
diff --git a/tests/test-fseeko2.sh b/tests/test-fseeko2.sh
new file mode 100755 (executable)
index 0000000..6e1130c
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-fseeko${EXEEXT} 1 2 < "$srcdir/test-fseeko2.sh"
index 092be19..845d944 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of ftell() function.
-   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009 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
     }                                                                       \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -80,15 +84,22 @@ main (int argc, char **argv)
   ASSERT (ch == '@');
   ASSERT (ftell (stdin) == 3);
 
-#if !defined __hpux /* HP-UX 11 has a known bug here */
-  /* Test ftell after ungetc without read.  */
-  ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
-  ASSERT (ftell (stdin) == 3);
-#endif
-
-  ch = ungetc ('~', stdin);
-  ASSERT (ch == '~');
-  ASSERT (ftell (stdin) == 2);
+  if (2 < argc)
+    {
+      if (FUNC_UNGETC_BROKEN)
+        {
+          fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+                 stderr);
+          return 77;
+        }
+      /* Test ftell after ungetc without read.  */
+      ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
+      ASSERT (ftell (stdin) == 3);
+
+      ch = ungetc ('~', stdin);
+      ASSERT (ch == '~');
+      ASSERT (ftell (stdin) == 2);
+    }
 
   /* Test ftell beyond end of file.  */
   ASSERT (fseek (stdin, 0, SEEK_END) == 0);
diff --git a/tests/test-ftell2.sh b/tests/test-ftell2.sh
new file mode 100755 (executable)
index 0000000..3b645b8
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftell${EXEEXT} 1 2 < "$srcdir/test-ftell2.sh"
index 87f4966..621ceda 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of ftello() function.
-   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009 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
     }                                                                       \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -88,17 +92,24 @@ main (int argc, char **argv)
   ASSERT (ftell (stdin) == 3);
   ASSERT (ftello (stdin) == 3);
 
-#if !defined __hpux /* HP-UX 11 has a known bug here */
-  /* Test ftell after ungetc without read.  */
-  ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
-  ASSERT (ftell (stdin) == 3);
-  ASSERT (ftello (stdin) == 3);
-#endif
-
-  ch = ungetc ('~', stdin);
-  ASSERT (ch == '~');
-  ASSERT (ftell (stdin) == 2);
-  ASSERT (ftello (stdin) == 2);
+  if (2 < argc)
+    {
+      if (FUNC_UNGETC_BROKEN)
+        {
+          fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+                 stderr);
+          return 77;
+        }
+      /* Test ftell after ungetc without read.  */
+      ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
+      ASSERT (ftell (stdin) == 3);
+      ASSERT (ftello (stdin) == 3);
+
+      ch = ungetc ('~', stdin);
+      ASSERT (ch == '~');
+      ASSERT (ftell (stdin) == 2);
+      ASSERT (ftello (stdin) == 2);
+    }
 
   /* Test ftell beyond end of file.  */
   ASSERT (fseek (stdin, 0, SEEK_END) == 0);
diff --git a/tests/test-ftello2.sh b/tests/test-ftello2.sh
new file mode 100755 (executable)
index 0000000..ba750b0
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftello${EXEEXT} 1 2 < "$srcdir/test-ftello2.sh"