From 864b46a1b1bcbd11b2e92ca30b59110617c75206 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 11 Mar 2013 22:58:13 -0400 Subject: [PATCH] Unit Tests - Improved two tests that always fail around summer time clock changes, by eliminating the dependence on 86,400. - Fixed feature.891.t tests that fail on certain fortuitous random UUID permutations. Now hard-coded UUID. --- test/date.t.cpp | 19 ++++++++++--------- test/feature.891.t | 20 +++++++++++++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/test/date.t.cpp b/test/date.t.cpp index cec979457..db75cb3b1 100644 --- a/test/date.t.cpp +++ b/test/date.t.cpp @@ -35,13 +35,15 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (181); + UnitTest t (184); try { Date now; Date yesterday; yesterday -= 86400; + Date tomorrow; + tomorrow += 86400; t.ok (yesterday <= now, "yesterday <= now"); t.ok (yesterday < now, "yesterday < now"); @@ -50,6 +52,13 @@ int main (int argc, char** argv) t.ok (now >= yesterday, "now >= yesterday"); t.ok (now > yesterday, "now > yesterday"); + t.ok (tomorrow >= now, "tomorrow >= now"); + t.ok (tomorrow > now, "tomorrow > now"); + t.notok (tomorrow == now, "!(tomorrow == now)"); + t.ok (tomorrow != now, "tomorrow != now"); + t.ok (now <= tomorrow, "now <= tomorrow"); + t.ok (now < tomorrow, "now < tomorrow"); + // Date::Date ("now") Date relative_now ("now"); t.ok (relative_now.sameHour (now), "Date ().sameHour (Date (now))"); @@ -143,8 +152,6 @@ int main (int argc, char** argv) t.is (happyNewYear.day (), 1, "1/1/2008 == 1"); t.is (happyNewYear.year (), 2008, "1/1/2008 == 2008"); - t.is (now - yesterday, 86400, "today - yesterday == 1"); - t.is (happyNewYear.toString (), "1/1/2008", "toString 1/1/2008"); int m, d, y; @@ -273,12 +280,6 @@ int main (int argc, char** argv) Date r1 ("today"); t.ok (r1.sameDay (now), "today = now"); - Date r2 ("tomorrow"); - t.ok (r2.sameDay (now + 86400), "tomorrow = now + 1d"); - - Date r3 ("yesterday"); - t.ok (r3.sameDay (now - 86400), "yesterday = now - 1d"); - Date r4 ("sunday"); if (now.dayOfWeek () >= 0) t.ok (r4.sameDay (now + (0 - now.dayOfWeek () + 7) * 86400), "next sunday"); diff --git a/test/feature.891.t b/test/feature.891.t index bf0804b81..2250eb557 100755 --- a/test/feature.891.t +++ b/test/feature.891.t @@ -28,7 +28,8 @@ use strict; use warnings; -use Test::More tests => 36; +use Time::Local; +use Test::More tests => 37; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -39,8 +40,21 @@ if (open my $fh, '>', 'bug.rc') } # Feature 891: UUID filter should be uuid.endswith by default -qx{../src/task rc:bug.rc add one 2>&1}; -qx{../src/task rc:bug.rc add two 2>&1}; +# Create some example data directly. This is so that we have complete control +# over the UUID. +if (open my $fh, '>', 'pending.data') +{ + my $timeA = timegm (00,00,12,22,11,2008); + my $timeB = timegm (00,00,12,17,03,2009); + print $fh <&1}; my ($uuid) = $output =~ /UUID\s+(\S{36})/ms;