From a0d6b3198e9bc4142e124110ecefa5eeac62bfea Mon Sep 17 00:00:00 2001 From: Louis-Claude Canon Date: Sat, 19 Jan 2013 12:38:25 -0500 Subject: [PATCH] Unit Tests - More robust tests strategy: captured outputs are always compared to some expected result. - Clearer and more consistent test. Signed-off-by: Paul Beckingham --- test/append.t | 10 ++++++---- test/args.1.t | 7 ++++--- test/bug.1006.t | 7 ++++--- test/bug.1023.t | 8 +++++++- test/bug.1043.t | 4 +++- test/bug.327.t | 3 ++- test/bug.360.t | 21 ++++++++++++--------- test/bug.414.t | 5 +++-- test/bug.480.t | 5 ++++- test/bug.555.t | 3 ++- test/bug.634.t | 5 +++-- test/bug.656.t | 5 +++-- test/bug.668.t | 4 +++- test/bug.837.t | 4 ++-- test/bug.956.t | 8 +++++++- test/bug.991.t | 3 ++- 16 files changed, 67 insertions(+), 35 deletions(-) diff --git a/test/append.t b/test/append.t index a5fb3a762..3830dc107 100755 --- a/test/append.t +++ b/test/append.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 6; # Create the rc file. if (open my $fh, '>', 'append.rc') @@ -41,13 +41,15 @@ if (open my $fh, '>', 'append.rc') # Add a task, then append more description. qx{../src/task rc:append.rc add foo 2>&1}; -qx{../src/task rc:append.rc 1 append bar 2>&1}; -my $output = qx{../src/task rc:append.rc info 1 2>&1}; +my $output = qx{../src/task rc:append.rc 1 append bar 2>&1}; +like ($output, qr/^Appended 1 task.$/m, 'append worked'); +$output = qx{../src/task rc:append.rc info 1 2>&1}; like ($output, qr/Description\s+foo\sbar\n/, 'append worked'); # Should cause an error when nothing is appended. $output = qx{../src/task rc:append.rc 1 append 2>&1}; -unlike ($output, qr/Appended 0 tasks/, 'blank append failed'); +like ($output, qr/^Additional text must be provided.$/m, 'blank append failed'); +unlike ($output, qr/^Appended 1 task.$/, 'blank append failed'); # Cleanup. unlink qw(pending.data completed.data undo.data backlog.data synch.key append.rc); diff --git a/test/args.1.t b/test/args.1.t index e04990ac7..2e235c3fa 100755 --- a/test/args.1.t +++ b/test/args.1.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 8; # Create the rc file. if (open my $fh, '>', 'args.rc') @@ -49,10 +49,11 @@ like ($output, qr/two/, 'task 2 added'); like ($output, qr/three/, 'task 3 added'); $output = qx{../src/task rc:args.rc 1 done 2>&1}; -like ($output, qr/^Completed 1 /ms, 'COMMAND after ID'); +like ($output, qr/^Completed 1 task.$/ms, 'COMMAND after ID'); $output = qx{../src/task rc:args.rc done 2 2>&1}; -unlike ($output, qr/^Completed 2 /ms, 'ID after COMMAND'); +like ($output, qr/^Command prevented from running.$/ms, 'ID after COMMAND'); +unlike ($output, qr/^Completed 1 task.$/ms, 'ID after COMMAND'); # Cleanup. unlink qw(pending.data completed.data undo.data backlog.data synch.key args.rc); diff --git a/test/bug.1006.t b/test/bug.1006.t index 2395f940e..42fef3a22 100755 --- a/test/bug.1006.t +++ b/test/bug.1006.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 6; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -47,13 +47,14 @@ if (open my $fh, '>', 'bug.rc') qx{../src/task rc:bug.rc add des 2>&1}; qx{../src/task rc:bug.rc 1 annotate des 2>&1}; my $output = qx{../src/task rc:bug.rc 1 info 2>&1}; +like ($output, qr/^Description\s+des$/ms, 'Attribute not completed in description'); unlike ($output, qr/description/ms, 'Attribute not completed in description'); # Check that the completion works when needed $output = qx{../src/task rc:bug.rc des:des 2>&1}; -unlike ($output, qr/No matches./ms, 'Task found using its description'); +like ($output, qr/^1 task.$/ms, 'Task found using its description'); -$output = qx{../src/task rc:bug.rc add entrée interdite 2>&1}; +qx{../src/task rc:bug.rc add entrée interdite 2>&1}; $output = qx{../src/task rc:bug.rc list interdite 2>&1}; like ($output, qr/entrée interdite/, "'entrée' left intact"); diff --git a/test/bug.1023.t b/test/bug.1023.t index 44e52de9f..eefa9453d 100755 --- a/test/bug.1023.t +++ b/test/bug.1023.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 11; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -50,11 +50,17 @@ like ($output, qr/Project\s*garden/, "default project not applied when otherwise $output = qx{../src/task rc:bug.rc 2 info 2>&1}; like ($output, qr/Project\s*home/, "default project applied when blank."); +$output = qx{../src/task rc:bug.rc 3 info 2>&1}; +like ($output, qr/^Description\s+baz$/m, "task baz shown."); +unlike ($output, qr/Project\s*home/, "no project applied when default project is blank."); + $output = qx{../src/task rc:bug.rc 3 modify +tag 2>&1}; +like ($output, qr/^Modified 1 task.$/m, "task modified."); unlike ($output, qr/Project\s*home/, "default project not applied on modification."); qx{../src/task rc:bug.rc 1 modify project: 2>&1}; $output = qx{../src/task rc:bug.rc 1 info 2>&1}; +like ($output, qr/^Description\s+foo$/m, "task foo shown."); unlike ($output, qr/Project\s*garden/, "default project not re-applied on attribute removal."); unlike ($output, qr/Project\s*home/, "default project not re-applied on attribute removal."); diff --git a/test/bug.1043.t b/test/bug.1043.t index 69046f672..f6c828209 100755 --- a/test/bug.1043.t +++ b/test/bug.1043.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 7; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -45,9 +45,11 @@ my $output = qx{../src/task rc:bug.rc _aliases 2>&1}; like ($output, qr/samplealias/, 'aliases are listed in _aliases'); $output = qx{../src/task rc:bug.rc _commands 2>&1}; +like ($output, qr/^information$/m, 'info is listed in _commands'); unlike ($output, qr/samplealias/, 'aliases are not listed in _commands'); $output = qx{../src/task rc:bug.rc _zshcommands 2>&1}; +like ($output, qr/^information:/m, 'info is listed in _zshcommands'); unlike ($output, qr/samplealias/, 'aliases are not listed in _zshcommands'); # Cleanup. diff --git a/test/bug.327.t b/test/bug.327.t index 73512d45a..2d0313c3e 100755 --- a/test/bug.327.t +++ b/test/bug.327.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 4; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -47,6 +47,7 @@ qx{../src/task rc:bug.rc 2 modify due: 2>&1}; # Result: Somehow the due date is incremented and wraps around to 12/31/1969, # then keeps going back to today. my $output = qx{../src/task rc:bug.rc li 2>&1}; +like ($output, qr/^1 task$/ms, 'task foo shown'); unlike ($output, qr/1969/ms, 'Should not display 12/31/1969'); # Cleanup. diff --git a/test/bug.360.t b/test/bug.360.t index efe7ccbcf..9b501ed32 100755 --- a/test/bug.360.t +++ b/test/bug.360.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 10; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -45,29 +45,32 @@ qx{../src/task rc:bug.rc ls 2>&1}; # Result: trying to add the project generates an error about removing # recurrence from a task. -my $output = qx{echo 'y' | ../src/task rc:bug.rc 1 modify project:bar 2>&1 >/dev/null}; -unlike ($output, qr/You cannot remove the recurrence from a recurring task./ms, 'No recurrence removal error'); +my $output = qx{echo 'y' | ../src/task rc:bug.rc 1 modify project:bar 2>&1}; +like ($output, qr/^Modified 2 tasks.$/ms, '2 tasks modified'); +unlike ($output, qr/^You cannot remove the recurrence from a recurring task.$/ms, 'No recurrence removal error'); # Now try to generate the error above via regular means - ie, is it actually # doing what it should? # TODO Removing recur: from a recurring task should also remove imask and parent. $output = qx{../src/task rc:bug.rc 2 modify recur: 2>&1 >/dev/null}; -like ($output, qr/You cannot remove the recurrence from a recurring task./ms, 'Recurrence removal error'); +like ($output, qr/^You cannot remove the recurrence from a recurring task.$/ms, 'Recurrence removal error'); # Prevent removal of the due date from a recurring task. # TODO Removing due: from a recurring task should also remove recur, imask and parent $output = qx{../src/task rc:bug.rc 2 modify due: 2>&1 >/dev/null}; -like ($output, qr/You cannot remove the due date from a recurring task./ms, 'Cannot remove due date from a recurring task'); +like ($output, qr/^You cannot remove the due date from a recurring task.$/ms, 'Cannot remove due date from a recurring task'); # Allow removal of the due date from a non-recurring task. -qx{../src/task rc:bug.rc add nonrecurring 2>&1}; +qx{../src/task rc:bug.rc add nonrecurring due:today 2>&1}; $output = qx{../src/task rc:bug.rc ls 2>&1}; +like ($output, qr/^2 task.$/ms, '2 tasks shown'); my ($id) = $output =~ /(\d+)\s+nonrecurring/; -$output = qx{../src/task rc:bug.rc $id modify due: 2>&1 >/dev/null}; -unlike ($output, qr/You cannot remove the due date from a recurring task./ms, 'Can remove due date from a non-recurring task'); +$output = qx{../src/task rc:bug.rc $id modify due: 2>&1}; +like ($output, qr/^Modified 1 task.$/ms, 'no task modified'); +unlike ($output, qr/^You cannot remove the due date from a recurring task.$/ms, 'Can remove due date from a non-recurring task'); $output = qx{../src/task rc:bug.rc diag 2>&1}; -like ($output, qr/No duplicates found/, 'No duplicate UUIDs detected'); +like ($output, qr/^\s+No duplicates found$/m, 'No duplicate UUIDs detected'); # Cleanup. unlink qw(pending.data completed.data undo.data backlog.data synch.key bug.rc); diff --git a/test/bug.414.t b/test/bug.414.t index f44923364..93983e4cd 100755 --- a/test/bug.414.t +++ b/test/bug.414.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 7; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -46,7 +46,7 @@ my $output = qx{../src/task rc:bug.rc ls +osobní 2>&1}; like ($output, qr/one/, 'found UTF8 tag osobní'); $output = qx{../src/task rc:bug.rc ls -osobní 2>&1}; -unlike ($output, qr/one/, 'not found UTF8 tag osobní'); +like ($output, qr/^No matches.$/m, 'not found UTF8 tag osobní'); # And a different one qx{../src/task rc:bug.rc add two +föo 2>&1}; @@ -54,6 +54,7 @@ $output = qx{../src/task rc:bug.rc ls +föo 2>&1}; like ($output, qr/two/, 'found UTF8 tag föo'); $output = qx{../src/task rc:bug.rc ls -föo 2>&1}; +like ($output, qr/one/, 'found UTF8 tag osobní'); unlike ($output, qr/two/, 'not found UTF8 tag föo'); # Cleanup. diff --git a/test/bug.480.t b/test/bug.480.t index 2f3b9e85e..b533e49b7 100755 --- a/test/bug.480.t +++ b/test/bug.480.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 37; +use Test::More tests => 40; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -78,6 +78,7 @@ unlike ($output, qr/two/, 'Double: no t2'); like ($output, qr/three/, 'Double: yes t3'); $output = qx{../src/task rc:bug.rc list -t1 -t2 -t3 2>&1}; +like ($output, qr/^No matches.$/m, 'No task listed'); unlike ($output, qr/one/, 'Triple: no t1'); unlike ($output, qr/two/, 'Triple: no t2'); unlike ($output, qr/three/, 'Triple: no t3'); @@ -98,6 +99,7 @@ unlike ($output, qr/two/, 'Double: no @2'); like ($output, qr/three/, 'Double: yes @3'); $output = qx{../src/task rc:bug.rc list -\@1 -\@2 -\@3 2>&1}; +like ($output, qr/^No matches.$/m, 'No task listed'); unlike ($output, qr/one/, 'Triple: no @1'); unlike ($output, qr/two/, 'Triple: no @2'); unlike ($output, qr/three/, 'Triple: no @3'); @@ -118,6 +120,7 @@ unlike ($output, qr/two/, 'Double: no @foo.2'); like ($output, qr/three/, 'Double: yes @foo.3'); $output = qx{../src/task rc:bug.rc list -\@foo.1 -\@foo.2 -\@foo.3 2>&1}; +like ($output, qr/^No matches.$/m, 'No task listed'); unlike ($output, qr/one/, 'Triple: no @foo.1'); unlike ($output, qr/two/, 'Triple: no @foo.2'); unlike ($output, qr/three/, 'Triple: no @foo.3'); diff --git a/test/bug.555.t b/test/bug.555.t index 0f18720eb..f038ecc30 100755 --- a/test/bug.555.t +++ b/test/bug.555.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 4; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -41,6 +41,7 @@ if (open my $fh, '>', 'bug.rc') # Bug #555 - log with a project segfaults. my $output = qx{../src/task rc:bug.rc log description project:p 2>&1}; +like ($output, qr/^Logged task.$/m, 'task logged'); unlike ($output, qr/Segmentation fault/, 'no segfault from log with project'); # Cleanup. diff --git a/test/bug.634.t b/test/bug.634.t index ecef4d78c..3395d6c64 100755 --- a/test/bug.634.t +++ b/test/bug.634.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 4; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -45,7 +45,8 @@ if (open my $fh, '>', 'bug.rc') qx{../src/task rc:bug.rc add Test 2>&1}; # Result: Attempt to undo add with confirmation=off -my $output = qx{echo 'n' |../src/task rc:bug.rc rc.confirmation=off undo 2>&1}; +my $output = qx{echo 'n' | ../src/task rc:bug.rc rc.confirmation=off undo 2>&1}; +like ($output, qr/^Task removed.$/ms, 'Task removed.'); unlike ($output, qr/Are you sure/ms, 'Undo honours confirmation=off.'); # Cleanup. diff --git a/test/bug.656.t b/test/bug.656.t index 05eb6b7c5..41aca246b 100755 --- a/test/bug.656.t +++ b/test/bug.656.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 4; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -53,7 +53,8 @@ qx{../src/task rc:bug.rc ls 2>&1}; # Result: Check for an extra task the second time task ls is executed my $output = qx{../src/task rc:bug.rc ls 2>&1}; -unlike ($output, qr/^\s3\s*Second recurring task\s*$/ms, 'Extra task detected.'); +like ($output, qr/^2 tasks$/ms, '2 tasks shown.'); +unlike ($output, qr/^\s3\s*Second recurring task\s*$/ms, 'Extra task detected.'); # Cleanup. unlink qw(pending.data completed.data undo.data backlog.data synch.key bug.rc); diff --git a/test/bug.668.t b/test/bug.668.t index b2ee1d6cc..fff0d1f16 100755 --- a/test/bug.668.t +++ b/test/bug.668.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 8; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -41,10 +41,12 @@ if (open my $fh, '>', 'bug.rc') # Bug 668: URL should allow users with dot character my $output = qx{../src/task rc:bug.rc merge user.name\@taskwarrior.org:undo.data 2>&1}; +like ($output, qr/^Could not run ssh. Is it installed, and available in \$PATH\?$/m, 'ssh does not connect'); unlike ($output, qr/not a valid modifier/, 'scp syntax with dots'); unlike ($output, qr/not in the expected format/, 'scp syntax with dots'); $output = qx{../src/task rc:bug.rc merge ssh://user.name\@taskwarrior.org/undo.data 2>&1}; +like ($output, qr/^Could not run ssh. Is it installed, and available in \$PATH\?$/m, 'ssh does not connect'); unlike ($output, qr/not a valid modifier/, 'standard syntax with dots'); unlike ($output, qr/not in the expected format/, 'standard syntax with dots'); diff --git a/test/bug.837.t b/test/bug.837.t index 642f5618b..58951c20d 100755 --- a/test/bug.837.t +++ b/test/bug.837.t @@ -42,9 +42,9 @@ if (open my $fh, '>', 'bug.rc') # correct urgency and depend on 0 when edited qx{../src/task rc:bug.rc add one 2>&1}; qx{../src/task rc:bug.rc add two dep:1 2>&1}; -my $output = qx{../src/task rc:bug.rc long 2>&1}; +qx{../src/task rc:bug.rc long 2>&1}; -$output = qx{../src/task rc:bug.rc 1 _urgency 2>&1}; +my $output = qx{../src/task rc:bug.rc 1 _urgency 2>&1}; like ($output, qr/ 8\n/, 'blocking urgency == 8'); $output = qx{../src/task rc:bug.rc 2 _urgency 2>&1}; diff --git a/test/bug.956.t b/test/bug.956.t index ae997c54e..34e7a211f 100755 --- a/test/bug.956.t +++ b/test/bug.956.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 14; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -45,22 +45,28 @@ qx{../src/task rc:bug.rc add test 2>&1}; # Solution 1: rc.verbose=nothing my $output = qx{TASKRC=bug.rc ../src/task rc:bug.rc rc.verbose=nothing ids 2>&1}; +like ($output, qr/^1$/m, 'ID 1 shown'); unlike ($output, qr/TASKRC/ms, 'The header does not appear with "ids" (rc.verbose=nothing)'); $output = qx{TASKRC=bug.rc ../src/task rc.verbose=nothing uuids 2>&1}; +like ($output, qr/^[0-9a-f-]*$/m, 'UUID shown'); unlike ($output, qr/TASKRC/ms, 'The header does not appear with "uuids" (rc.verbose=nothing)'); $output = qx{TASKRC=bug.rc ../src/task rc.verbose=nothing uuids 2>&1}; +like ($output, qr/^[0-9a-f-]*$/m, 'UUID shown'); unlike ($output, qr/TASKRC/ms, 'The header does not appear with "uuids" (rc.verbose=nothing)'); # Solution 2: task ... 2>/dev/null $output = qx{TASKRC=bug.rc ../src/task rc:bug.rc ids 2>/dev/null}; +like ($output, qr/^1$/m, 'ID 1 shown'); unlike ($output, qr/TASKRC/ms, 'The header does not appear with "ids" (2>/dev/null)'); $output = qx{TASKRC=bug.rc ../src/task _ids 2>/dev/null}; +like ($output, qr/^[0-9a-f-]*$/m, 'UUID shown'); unlike ($output, qr/TASKRC/ms, 'The header does not appear with "_ids" (2>/dev/null)'); $output = qx{TASKRC=bug.rc ../src/task _ids 2>/dev/null}; +like ($output, qr/^[0-9a-f-]*$/m, 'UUID shown'); unlike ($output, qr/TASKRC/ms, 'The header does not appear with "_ids" (2>/dev/null)'); ### Cleanup. diff --git a/test/bug.991.t b/test/bug.991.t index 35f16d266..5457db445 100755 --- a/test/bug.991.t +++ b/test/bug.991.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 6; # Create the rc file. if (open my $fh, '>', 'bug.rc') @@ -45,6 +45,7 @@ if (open my $fh, '>', 'bug.rc') qx{../src/task rc:bug.rc add foo 2>&1}; my $output = qx{../src/task rc:bug.rc show 2>&1}; +like ($output, qr/^Config Variable\s+Value$/m, 'Variables shown'); unlike ($output, qr/Configuration error/ms, 'No configuration error'); unlike ($output, qr/deprecated/ms, 'No deprecated variable'); unlike ($output, qr/unrecognized/ms, 'No unrecognized variable');