From ef7c5dc4eb4ac4cd4fcf8893c6a298b890779ec3 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 3 Jul 2009 00:51:25 -0400 Subject: [PATCH] Unit Tests - The unit tests needed a little love after "undelete" went away, and "undo" changed. - Fixed a few tests that were broken. --- src/tests/add.t | 8 +------- src/tests/cal.t | 2 +- src/tests/cmd.t.cpp | 14 +++++++++----- src/tests/delete.t | 23 ++++++++++------------- src/tests/import.csv.t | 6 ------ src/tests/sequence.t | 10 ++++++---- src/tests/shadow.t | 2 +- src/tests/undo.t | 8 ++------ src/tests/util.t.cpp | 14 +++++++------- 9 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/tests/add.t b/src/tests/add.t index 703a0249f..916b96106 100755 --- a/src/tests/add.t +++ b/src/tests/add.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 13; # Create the rc file. if (open my $fh, '>', 'add.rc') @@ -60,12 +60,6 @@ $output = qx{../task rc:add.rc info 1}; like ($output, qr/ID\s+1\n/, 'add ID'); like ($output, qr/Status\s+Deleted\n/, 'add Deleted'); -# Test undelete. -qx{../task rc:add.rc undelete 1}; -$output = qx{../task rc:add.rc info 1}; -like ($output, qr/ID\s+1\n/, 'add ID'); -like ($output, qr/Status\s+Pending\n/, 'add Pending'); - # Cleanup. unlink 'pending.data'; ok (!-r 'pending.data', 'Removed pending.data'); diff --git a/src/tests/cal.t b/src/tests/cal.t index fe1892ef6..93ee9a705 100755 --- a/src/tests/cal.t +++ b/src/tests/cal.t @@ -43,7 +43,7 @@ if (open my $fh, '>', 'cal.rc') ok (-r 'cal.rc', 'Created cal.rc'); } -(my $day,my $nmon,my $nyear) = (localtime)[3,4,5]; +my ($day, $nmon, $nyear) = (localtime)[3,4,5]; my $nextmonth = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[($nmon+1) % 12]; my $month = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[($nmon) % 12]; my $prevmonth = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[($nmon-1) % 12]; diff --git a/src/tests/cmd.t.cpp b/src/tests/cmd.t.cpp index d1042afd9..bb01fad8c 100644 --- a/src/tests/cmd.t.cpp +++ b/src/tests/cmd.t.cpp @@ -33,7 +33,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (76); + UnitTest t (78); context.config.set ("report.foo.columns", "id"); @@ -106,6 +106,14 @@ int main (int argc, char** argv) t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand version"); t.notok (cmd.isWriteCommand (), "not isWriteCommand version"); + cmd.command = "_projects"; + t.ok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand _projects"); + t.notok (cmd.isWriteCommand (), "isWriteCommand _projects"); + + cmd.command = "_tags"; + t.ok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand _tags"); + t.notok (cmd.isWriteCommand (), "isWriteCommand _tags"); + cmd.command = "add"; t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand add"); t.ok (cmd.isWriteCommand (), "isWriteCommand add"); @@ -146,10 +154,6 @@ int main (int argc, char** argv) t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand stop"); t.ok (cmd.isWriteCommand (), "isWriteCommand stop"); - cmd.command = "undelete"; - t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand undelete"); - t.ok (cmd.isWriteCommand (), "isWriteCommand undelete"); - cmd.command = "undo"; t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand undo"); t.ok (cmd.isWriteCommand (), "isWriteCommand undo"); diff --git a/src/tests/delete.t b/src/tests/delete.t index daaff3afd..401b9145f 100755 --- a/src/tests/delete.t +++ b/src/tests/delete.t @@ -28,38 +28,35 @@ use strict; use warnings; -use Test::More tests => 18; +use Test::More tests => 17; # Create the rc file. -if (open my $fh, '>', 'undelete.rc') +if (open my $fh, '>', 'delete.rc') { print $fh "data.location=.\n", "echo.command=no\n"; close $fh; - ok (-r 'undelete.rc', 'Created undelete.rc'); + ok (-r 'delete.rc', 'Created delete.rc'); } # Add a task, delete it, undelete it. -my $output = qx{../task rc:undelete.rc add one; ../task rc:undelete.rc info 1}; +my $output = qx{../task rc:delete.rc add one; ../task rc:delete.rc info 1}; ok (-r 'pending.data', 'pending.data created'); like ($output, qr/Status\s+Pending\n/, 'Pending'); -$output = qx{../task rc:undelete.rc delete 1; ../task rc:undelete.rc info 1}; +$output = qx{../task rc:delete.rc delete 1; ../task rc:delete.rc info 1}; like ($output, qr/Status\s+Deleted\n/, 'Deleted'); ok (-r 'completed.data', 'completed.data created'); -$output = qx{../task rc:undelete.rc undelete 1; ../task rc:undelete.rc info 1}; +$output = qx{echo 'y' | ../task rc:delete.rc undo; ../task rc:delete.rc info 1}; like ($output, qr/Status\s+Pending\n/, 'Pending'); ok (-r 'completed.data', 'completed.data created'); -$output = qx{../task rc:undelete.rc delete 1; ../task rc:undelete.rc list}; +$output = qx{../task rc:delete.rc delete 1; ../task rc:delete.rc list}; like ($output, qr/No matches./, 'No matches'); ok (-r 'completed.data', 'completed.data created'); -$output = qx{../task rc:undelete.rc undelete 1}; -like ($output, qr/Task 1 not found/, 'Task 1 not found'); - -$output = qx{../task rc:undelete.rc info 1}; +$output = qx{../task rc:delete.rc info 1}; like ($output, qr/Task 1 not found/, 'No matches'); # Cleanup. @@ -75,8 +72,8 @@ ok (-r 'undo.data', 'Need to remove undo.data'); unlink 'undo.data'; ok (!-r 'undo.data', 'Removed undo.data'); -unlink 'undelete.rc'; -ok (!-r 'undelete.rc', 'Removed undelete.rc'); +unlink 'delete.rc'; +ok (!-r 'delete.rc', 'Removed delete.rc'); exit 0; diff --git a/src/tests/import.csv.t b/src/tests/import.csv.t index 34d5c4830..62adcc35e 100755 --- a/src/tests/import.csv.t +++ b/src/tests/import.csv.t @@ -54,13 +54,7 @@ like ($output, qr/Imported 2 tasks successfully, with 0 errors./, 'no errors'); $output = qx{../task rc:import.rc list}; like ($output, qr/1.+H.+this is a test/, 't1'); -diag ("---"); -diag ($output); -diag ("---"); like ($output, qr/2.+another task/, 't2'); -diag ("---"); -diag ($output); -diag ("---"); # Cleanup. unlink 'import.txt'; diff --git a/src/tests/sequence.t b/src/tests/sequence.t index fe54a797e..764bf30fa 100755 --- a/src/tests/sequence.t +++ b/src/tests/sequence.t @@ -46,7 +46,8 @@ my $output = qx{../task rc:seq.rc info 1}; like ($output, qr/Status\s+Completed/, 'sequence do 1'); $output = qx{../task rc:seq.rc info 2}; like ($output, qr/Status\s+Completed/, 'sequence do 2'); -qx{../task rc:seq.rc undo 1,2}; +qx{echo 'y'|../task rc:seq.rc undo}; +qx{echo 'y'|../task rc:seq.rc undo}; $output = qx{../task rc:seq.rc info 1}; like ($output, qr/Status\s+Pending/, 'sequence undo 1'); $output = qx{../task rc:seq.rc info 2}; @@ -58,11 +59,12 @@ $output = qx{../task rc:seq.rc info 1}; like ($output, qr/Status\s+Deleted/, 'sequence delete 1'); $output = qx{../task rc:seq.rc info 2}; like ($output, qr/Status\s+Deleted/, 'sequence delete 2'); -qx{../task rc:seq.rc undelete 1,2}; +qx{echo 'y'|../task rc:seq.rc undo}; +qx{echo 'y'|../task rc:seq.rc undo}; $output = qx{../task rc:seq.rc info 1}; -like ($output, qr/Status\s+Pending/, 'sequence undelete 1'); +like ($output, qr/Status\s+Pending/, 'sequence undo 1'); $output = qx{../task rc:seq.rc info 2}; -like ($output, qr/Status\s+Pending/, 'sequence undelete 2'); +like ($output, qr/Status\s+Pending/, 'sequence undo 2'); # Test sequences in start/stop qx{../task rc:seq.rc start 1,2}; diff --git a/src/tests/shadow.t b/src/tests/shadow.t index efcb7a561..3ba7f78a2 100755 --- a/src/tests/shadow.t +++ b/src/tests/shadow.t @@ -51,7 +51,7 @@ $output = qx{../task rc:shadow.rc delete 1}; like ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\]/, 'shadow file updated on delete'); $output = qx{../task rc:shadow.rc list}; -like ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\]/, 'shadow file updated on list'); +unlike ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\]/, 'shadow file not updated on list'); # Inspect the shadow file. my $file = slurp ('./shadow.txt'); diff --git a/src/tests/undo.t b/src/tests/undo.t index 58c6970b7..62e13e367 100755 --- a/src/tests/undo.t +++ b/src/tests/undo.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 15; # Create the rc file. if (open my $fh, '>', 'undo.rc') @@ -48,17 +48,13 @@ $output = qx{../task rc:undo.rc do 1; ../task rc:undo.rc info 1}; ok (-r 'completed.data', 'completed.data created'); like ($output, qr/Status\s+Completed\n/, 'Completed'); -$output = qx{../task rc:undo.rc undo 1; ../task rc:undo.rc info 1}; +$output = qx{echo 'y'|../task rc:undo.rc undo; ../task rc:undo.rc info 1}; ok (-r 'completed.data', 'completed.data created'); like ($output, qr/Status\s+Pending\n/, 'Pending'); $output = qx{../task rc:undo.rc do 1; ../task rc:undo.rc list}; like ($output, qr/No matches/, 'No matches'); -$output = qx{../task rc:undo.rc undo 1; ../task rc:undo.rc info 1}; -like ($output, qr/Task 1 not found/, 'Task 1 not found'); -like ($output, qr/Task 1 not found/, 'No matches'); - # Cleanup. ok (-r 'pending.data', 'Need to remove pending.data'); unlink 'pending.data'; diff --git a/src/tests/util.t.cpp b/src/tests/util.t.cpp index 1d16798c8..56038cef8 100644 --- a/src/tests/util.t.cpp +++ b/src/tests/util.t.cpp @@ -83,15 +83,15 @@ int main (int argc, char** argv) Task rightAgain (right); std::string output = taskDifferences (left, right); - t.ok (taskDiff (left, right), "Detected changes"); - t.ok (output.find ("zero was changed from '0' to '00'.") != std::string::npos, "Detected change zero:0 -> zero:00"); - t.ok (output.find ("one was deleted.") != std::string::npos, "Detected deletion one:1 ->"); - t.ok (output.find ("two") == std::string::npos, "Detected no change two:2 -> two:2"); - t.ok (output.find ("three was set to '3'.") != std::string::npos, "Detected addition -> three:3"); + t.ok (taskDiff (left, right), "Detected changes"); + t.ok (output.find ("zero was changed from '0' to '00'") != std::string::npos, "Detected change zero:0 -> zero:00"); + t.ok (output.find ("one was deleted") != std::string::npos, "Detected deletion one:1 ->"); + t.ok (output.find ("two") == std::string::npos, "Detected no change two:2 -> two:2"); + t.ok (output.find ("three was set to '3'") != std::string::npos, "Detected addition -> three:3"); - t.notok (taskDiff (right, rightAgain), "No changes detected"); + t.notok (taskDiff (right, rightAgain), "No changes detected"); output = taskDifferences (right, rightAgain); - t.ok (output.find ("No changes were made.") != std::string::npos, "No changes detected"); + t.ok (output.find ("No changes were made") != std::string::npos, "No changes detected"); return 0; }