mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
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.
This commit is contained in:
parent
da8258256d
commit
864b46a1b1
2 changed files with 27 additions and 12 deletions
|
@ -35,13 +35,15 @@ Context context;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (181);
|
UnitTest t (184);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Date now;
|
Date now;
|
||||||
Date yesterday;
|
Date yesterday;
|
||||||
yesterday -= 86400;
|
yesterday -= 86400;
|
||||||
|
Date tomorrow;
|
||||||
|
tomorrow += 86400;
|
||||||
|
|
||||||
t.ok (yesterday <= now, "yesterday <= now");
|
t.ok (yesterday <= now, "yesterday <= now");
|
||||||
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 (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::Date ("now")
|
||||||
Date relative_now ("now");
|
Date relative_now ("now");
|
||||||
t.ok (relative_now.sameHour (now), "Date ().sameHour (Date (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.day (), 1, "1/1/2008 == 1");
|
||||||
t.is (happyNewYear.year (), 2008, "1/1/2008 == 2008");
|
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");
|
t.is (happyNewYear.toString (), "1/1/2008", "toString 1/1/2008");
|
||||||
|
|
||||||
int m, d, y;
|
int m, d, y;
|
||||||
|
@ -273,12 +280,6 @@ int main (int argc, char** argv)
|
||||||
Date r1 ("today");
|
Date r1 ("today");
|
||||||
t.ok (r1.sameDay (now), "today = now");
|
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");
|
Date r4 ("sunday");
|
||||||
if (now.dayOfWeek () >= 0)
|
if (now.dayOfWeek () >= 0)
|
||||||
t.ok (r4.sameDay (now + (0 - now.dayOfWeek () + 7) * 86400), "next sunday");
|
t.ok (r4.sameDay (now + (0 - now.dayOfWeek () + 7) * 86400), "next sunday");
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 36;
|
use Time::Local;
|
||||||
|
use Test::More tests => 37;
|
||||||
|
|
||||||
# Create the rc file.
|
# Create the rc file.
|
||||||
if (open my $fh, '>', 'bug.rc')
|
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
|
# Feature 891: UUID filter should be uuid.endswith by default
|
||||||
qx{../src/task rc:bug.rc add one 2>&1};
|
# Create some example data directly. This is so that we have complete control
|
||||||
qx{../src/task rc:bug.rc add two 2>&1};
|
# 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 <<EOF;
|
||||||
|
[description:"one" entry:"$timeA" status:"pending" uuid:"a7097693-91c2-4cbe-ba89-ddcc87e5582c"]
|
||||||
|
[description:"two" entry:"$timeB" status:"pending" uuid:"e8f72d91-964c-424b-8fd5-556434648b6b"]
|
||||||
|
EOF
|
||||||
|
|
||||||
|
close $fh;
|
||||||
|
ok (-r 'pending.data', 'Created pending.data');
|
||||||
|
}
|
||||||
|
|
||||||
my $output = qx{../src/task rc:bug.rc 1 info 2>&1};
|
my $output = qx{../src/task rc:bug.rc 1 info 2>&1};
|
||||||
my ($uuid) = $output =~ /UUID\s+(\S{36})/ms;
|
my ($uuid) = $output =~ /UUID\s+(\S{36})/ms;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue