mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
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 <paul@beckingham.net>
This commit is contained in:
parent
ee7fd7add0
commit
a0d6b3198e
16 changed files with 67 additions and 35 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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.");
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue