chiark / gitweb /
Work around buggy FreeBSD strptime()
authorRichard Kettlewell <richard@heceptor.anjou.terraraq.org.uk>
Mon, 2 Jun 2008 15:12:46 +0000 (16:12 +0100)
committerRichard Kettlewell <richard@heceptor.anjou.terraraq.org.uk>
Mon, 2 Jun 2008 15:12:46 +0000 (16:12 +0100)
lib/dateparse.c
libtests/t-dateparse.c
libtests/test.c
libtests/test.h

index 2a25292228a2be673d0f2887a492c30658c75444..f390d0c778186a57433359cb8711df64ca245bad 100644 (file)
@@ -38,6 +38,9 @@
 static const char *const datemsk[] = {
   /* ISO format */
   "%Y-%m-%d %H:%M:%S",
+  /* Generic time, same day */
+  "%H:%M:%S",
+  "%H:%M",
   /* "%Y-%m-%d %H:%M:%S %Z" - no, not sensibly supported anywhere */
   /* Locale-specific date + time */
   "%c",
@@ -45,9 +48,6 @@ static const char *const datemsk[] = {
   /* Locale-specific time, same day */
   "%X",
   "%EX",
-  /* Generic time, same day */
-  "%H:%M",
-  "%H:%M:%S",
   NULL,
 };
 
index a0d8e3120c7e69d4c7d0eebd78facb1d8bebe826..3b1e8195192f1a56bbd02e36a8cd47ca442d9cea 100644 (file)
@@ -48,6 +48,10 @@ static void test_dateparse(void) {
   check_date(now, "%H:%M:%S", localtime);
   /* This one needs a bodge: */
   check_date(now - now % 60, "%H:%M", localtime);
+#if __FreeBSD__
+  fprintf(stderr, "strptime() is broken on FreeBSD - skipping further tests\n");
+  ++skipped;
+#else
   /* Reject invalid formats */
   check_fatal(dateparse("12"));
   check_fatal(dateparse("12:34:56:23"));
@@ -55,6 +59,7 @@ static void test_dateparse(void) {
   check_fatal(dateparse("25:34"));
   check_fatal(dateparse("23:61"));
   check_fatal(dateparse("23:23:62"));
+#endif
 }
 
 TEST(dateparse);
index d37d70fa78a41212e9b99ab49a3701ed825659a4..4fcb00848dfca78edabd75854cd57f95bbbb236e 100644 (file)
@@ -26,6 +26,7 @@
 long long tests, errors;
 int fail_first;
 int verbose;
+int skipped;
 
 void count_error(void) {
   ++errors;
index a4f478e82d5b8b4283c01231388c0421e1318b57..48c8956ca1aa175f2561ba9612ee3ffec1b9b476 100644 (file)
@@ -68,6 +68,7 @@
 extern long long tests, errors;
 extern int fail_first;
 extern int verbose;
+extern int skipped;
 
 /** @brief Checks that @p expr is nonzero */
 #define insist(expr) do {                              \
@@ -153,7 +154,11 @@ void test_exitfn(int) attribute((noreturn));
     if(errors || verbose)                                               \
       fprintf(stderr, "test_"#name": %lld errors out of %lld tests\n",  \
               errors, tests);                                           \
-    return !!errors;                                                    \
+    if(errors)                                                          \
+      return 1;                                                         \
+    if(skipped)                                                         \
+      return 77;                                                        \
+    return 0;                                                           \
   }                                                                     \
                                                                         \
   struct swallow_semicolon