changeset 31227:6067a86153cb

tests: tighten some getdate tests * tests/test-getdate.c (main): Tighten tests: require equality, not just greater than. Set TZ envvar to UTC0.
author Jim Meyering <meyering@redhat.com>
date Sun, 03 May 2009 09:17:53 +0200
parents b2b0cd756d26
children 1d041d870246
files ChangeLog tests/test-getdate.c
diffstat 2 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri May 01 09:23:20 2009 +0200
+++ b/ChangeLog	Sun May 03 09:17:53 2009 +0200
@@ -1,3 +1,9 @@
+2009-05-03  Jim Meyering  <meyering@redhat.com>
+
+	tests: tighten some getdate tests
+	* tests/test-getdate.c (main): Tighten tests: require equality,
+	not just greater than.  Set TZ envvar to UTC0.
+
 2009-05-03  Giuseppe Scrivano  <gscrivano@gnu.org>
 
 	getdate: correctly interpret "next monday" when run on a Monday
--- a/tests/test-getdate.c	Fri May 01 09:23:20 2009 +0200
+++ b/tests/test-getdate.c	Sun May 03 09:17:53 2009 +0200
@@ -53,12 +53,8 @@
   "SUNDAY",
   "MONDAY",
   "TUESDAY",
-  "TUES",
   "WEDNESDAY",
-  "WEDNES",
   "THURSDAY",
-  "THUR",
-  "THURS",
   "FRIDAY",
   "SATURDAY",
   NULL
@@ -228,25 +224,27 @@
   ASSERT (result.tv_sec == result2.tv_sec
 	  && result.tv_nsec == result2.tv_nsec);
 
-  /* Check that every 'last/next DAY' is in the past/future.  */
+  /* Check that some "next Monday", "last Wednesday", etc. are correct.  */
+  putenv ("TZ=UTC0");
   for (i = 0; day_table[i]; i++)
     {
+      unsigned int thur2 = 7 * 24 * 3600; /* 2nd thursday */
       char tmp[32];
       sprintf (tmp, "NEXT %s", day_table[i]);
-      now.tv_sec = 4711;
+      now.tv_sec = thur2 + 4711;
       now.tv_nsec = 1267;
       ASSERT (get_date (&result, tmp, &now));
       LOG (tmp, now, result);
-      ASSERT (result.tv_sec > now.tv_sec
-              && result.tv_nsec == 0);
+      ASSERT (result.tv_nsec == 0);
+      ASSERT (result.tv_sec == thur2 + (i == 4 ? 7 : (i + 3) % 7) * 24 * 3600);
 
       sprintf (tmp, "LAST %s", day_table[i]);
-      now.tv_sec = 4711;
+      now.tv_sec = thur2 + 4711;
       now.tv_nsec = 1267;
       ASSERT (get_date (&result, tmp, &now));
       LOG (tmp, now, result);
-      ASSERT (result.tv_sec < now.tv_sec
-              && result.tv_nsec == 0);
+      ASSERT (result.tv_nsec == 0);
+      ASSERT (result.tv_sec == thur2 + ((i + 3) % 7 - 7) * 24 * 3600);
     }
 
   p = "THURSDAY UTC+00";  /* The epoch was on Thursday.  */
@@ -262,7 +260,7 @@
   now.tv_nsec = 0;
   ASSERT (get_date (&result, p, &now));
   LOG (p, now, result);
-  ASSERT (result.tv_sec >= now.tv_sec
+  ASSERT (result.tv_sec == 24 * 3600
 	  && result.tv_nsec == now.tv_nsec);
 
   return 0;