changeset 11215:92a6ab18ea18

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.
author Eric Blake <ebb9@byu.net>
date Wed, 25 Feb 2009 07:42:31 -0700
parents f4a1e8947c50
children 990c0f0a5097
files ChangeLog m4/ungetc.m4 modules/fseek-tests modules/fseeko-tests modules/ftell-tests modules/ftello-tests tests/test-fseek.c tests/test-fseek2.sh tests/test-fseeko.c tests/test-fseeko2.sh tests/test-ftell.c tests/test-ftell2.sh tests/test-ftello.c tests/test-ftello2.sh
diffstat 14 files changed, 157 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- 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
@@ -248,7 +266,7 @@
 	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.
 
new file mode 100644
--- /dev/null
+++ b/m4/ungetc.m4
@@ -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
+])
--- a/modules/fseek-tests
+++ b/modules/fseek-tests
@@ -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
--- a/modules/fseeko-tests
+++ b/modules/fseeko-tests
@@ -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
--- a/modules/ftell-tests
+++ b/modules/ftell-tests
@@ -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
--- a/modules/ftello-tests
+++ b/modules/ftello-tests
@@ -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
--- a/tests/test-fseek.c
+++ b/tests/test-fseek.c
@@ -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
@@ -33,6 +33,10 @@
     }									     \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -47,10 +51,19 @@
       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.  */
new file mode 100755
--- /dev/null
+++ b/tests/test-fseek2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-fseek${EXEEXT} 1 2 < "$srcdir/test-fseek2.sh"
--- a/tests/test-fseeko.c
+++ b/tests/test-fseeko.c
@@ -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
@@ -33,6 +33,10 @@
     }									     \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -50,10 +54,19 @@
       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.  */
new file mode 100755
--- /dev/null
+++ b/tests/test-fseeko2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-fseeko${EXEEXT} 1 2 < "$srcdir/test-fseeko2.sh"
--- a/tests/test-ftell.c
+++ b/tests/test-ftell.c
@@ -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
@@ -35,6 +35,10 @@
     }									     \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -80,15 +84,22 @@
   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
+  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);
+      ch = ungetc ('~', stdin);
+      ASSERT (ch == '~');
+      ASSERT (ftell (stdin) == 2);
+    }
 
   /* Test ftell beyond end of file.  */
   ASSERT (fseek (stdin, 0, SEEK_END) == 0);
new file mode 100755
--- /dev/null
+++ b/tests/test-ftell2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftell${EXEEXT} 1 2 < "$srcdir/test-ftell2.sh"
--- a/tests/test-ftello.c
+++ b/tests/test-ftello.c
@@ -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
@@ -35,6 +35,10 @@
     }									     \
   while (0)
 
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -88,17 +92,24 @@
   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
+  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);
+      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);
new file mode 100755
--- /dev/null
+++ b/tests/test-ftello2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftello${EXEEXT} 1 2 < "$srcdir/test-ftello2.sh"