test-inttostr: avoid spurious failure on Solaris 9
authorJim Meyering <meyering@redhat.com>
Sat, 12 Jun 2010 12:47:43 +0000 (14:47 +0200)
committerJim Meyering <meyering@redhat.com>
Sat, 12 Jun 2010 15:36:58 +0000 (17:36 +0200)
* tests/test-inttostr.c (main): Skip the test when snprintf fails
to accept "%ju".  Reported by Bruno Haible.

ChangeLog
tests/test-inttostr.c

index 7b6394d..88e01ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-06-12  Jim Meyering  <meyering@redhat.com>
+
+       test-inttostr: avoid spurious failure on Solaris 9
+       * tests/test-inttostr.c (main): Skip the test when snprintf fails
+       to accept "%ju".  Reported by Bruno Haible.
+
 2010-06-11  Jim Meyering  <meyering@redhat.com>
 
        test-sys_socket: mark variables as used more readably
index e53d22a..bf18621 100644 (file)
 int
 main (void)
 {
-  CK (int,          inttostr);
-  CK (unsigned int, uinttostr);
-  CK (off_t,        offtostr);
-  CK (uintmax_t,    umaxtostr);
-  CK (intmax_t,     imaxtostr);
-  return 0;
+  char buf[2];
+
+  /* Ideally we would rely on the snprintf-posix module, in which case
+     this guard would not be required, but due to limitations in gnulib's
+     implementation (see modules/snprintf-posix), we cannot.  */
+  if (snprintf (buf, sizeof buf, "%ju", (uintmax_t) 3) == 1
+      && buf[0] == '3' && buf[1] == '\0')
+    {
+      CK (int,          inttostr);
+      CK (unsigned int, uinttostr);
+      CK (off_t,        offtostr);
+      CK (uintmax_t,    umaxtostr);
+      CK (intmax_t,     imaxtostr);
+      return 0;
+    }
+
+  /* snprintf doesn't accept %ju; skip this test.  */
+  return 77;
 }