mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Unit Tests
- Updateض to use the new template.
This commit is contained in:
parent
961b4ade9b
commit
02aed51196
1 changed files with 37 additions and 33 deletions
70
test/undo.t
70
test/undo.t
|
@ -33,8 +33,12 @@ use Test::More tests => 19;
|
||||||
delete $ENV{'TASKDATA'};
|
delete $ENV{'TASKDATA'};
|
||||||
delete $ENV{'TASKRC'};
|
delete $ENV{'TASKRC'};
|
||||||
|
|
||||||
|
use File::Basename;
|
||||||
|
my $ut = basename ($0);
|
||||||
|
my $rc = $ut . '.rc';
|
||||||
|
|
||||||
# Create the rc file.
|
# Create the rc file.
|
||||||
if (open my $fh, '>', 'undo.rc')
|
if (open my $fh, '>', $rc)
|
||||||
{
|
{
|
||||||
print $fh "data.location=.\n",
|
print $fh "data.location=.\n",
|
||||||
"confirmation=no\n";
|
"confirmation=no\n";
|
||||||
|
@ -42,35 +46,35 @@ if (open my $fh, '>', 'undo.rc')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test the add/done/undo commands.
|
# Test the add/done/undo commands.
|
||||||
my $output = qx{../src/task rc:undo.rc add one 2>&1; ../src/task rc:undo.rc info 1 2>&1};
|
my $output = qx{../src/task rc:$rc add one 2>&1; ../src/task rc:$rc info 1 2>&1};
|
||||||
ok (-r 'pending.data', 'pending.data created');
|
ok (-r 'pending.data', "$ut: pending.data created");
|
||||||
ok (! -r 'completed.data', 'completed.data not created');
|
ok (! -r 'completed.data', "$ut: completed.data not created");
|
||||||
like ($output, qr/Status\s+Pending\n/, 'Pending');
|
like ($output, qr/Status\s+Pending\n/, "$ut: Pending");
|
||||||
|
|
||||||
$output = qx{../src/task rc:undo.rc 1 done 2>&1; ../src/task rc:undo.rc info 1 2>&1};
|
$output = qx{../src/task rc:$rc 1 done 2>&1; ../src/task rc:$rc info 1 2>&1};
|
||||||
ok (! -r 'completed.data', 'completed.data created');
|
ok (! -r 'completed.data', "$ut: completed.data created");
|
||||||
like ($output, qr/Status\s+Completed\n/, 'Completed');
|
like ($output, qr/Status\s+Completed\n/, "$ut: Completed");
|
||||||
|
|
||||||
$output = qx{../src/task rc:undo.rc undo 2>&1; ../src/task rc:undo.rc info 1 2>&1};
|
$output = qx{../src/task rc:$rc undo 2>&1; ../src/task rc:$rc info 1 2>&1};
|
||||||
ok (-r 'completed.data', 'completed.data created');
|
ok (-r 'completed.data', "$ut: completed.data created");
|
||||||
like ($output, qr/Status\s+Pending\n/, 'Pending');
|
like ($output, qr/Status\s+Pending\n/, "$ut: Pending");
|
||||||
|
|
||||||
$output = qx{../src/task rc:undo.rc 1 done 2>&1; ../src/task rc:undo.rc list 2>&1 >/dev/null};
|
$output = qx{../src/task rc:$rc 1 done 2>&1; ../src/task rc:$rc list 2>&1 >/dev/null};
|
||||||
like ($output, qr/No matches/, 'No matches');
|
like ($output, qr/No matches/, "$ut: No matches");
|
||||||
|
|
||||||
# Bug 1060: Test that if undo is given an argument it catches and reports the correct error.
|
# Bug 1060: Test that if undo is given an argument it catches and reports the correct error.
|
||||||
$output = qx{../src/task rc:undo.rc undo 1 2>&1};
|
$output = qx{../src/task rc:$rc undo 1 2>&1};
|
||||||
unlike ($output, qr/Unknown error/, 'No unknown error');
|
unlike ($output, qr/Unknown error/, "$ut: No unknown error");
|
||||||
like ($output, qr/The undo command does not allow further task modification/, 'Correct error caught and reported');
|
like ($output, qr/The undo command does not allow further task modification/, "$ut: Correct error caught and reported");
|
||||||
|
|
||||||
# Add a new task and undo it.
|
# Add a new task and undo it.
|
||||||
$output = qx{../src/task rc:undo.rc add two 2>&1; ../src/task rc:undo.rc info 1 2>&1};
|
$output = qx{../src/task rc:$rc add two 2>&1; ../src/task rc:$rc info 1 2>&1};
|
||||||
unlike ($output, qr/Unknown error/, 'No unknown error');
|
unlike ($output, qr/Unknown error/, "$ut: No unknown error");
|
||||||
like ($output, qr/Status\s+Pending\n/, 'Pending');
|
like ($output, qr/Status\s+Pending\n/, "$ut: Pending");
|
||||||
|
|
||||||
$output = qx{../src/task rc:undo.rc undo 2>&1; ../src/task rc:undo.rc info 1 2>&1};
|
$output = qx{../src/task rc:$rc undo 2>&1; ../src/task rc:$rc info 1 2>&1};
|
||||||
like ($output, qr/Task removed\.\n/, 'Task removed');
|
like ($output, qr/Task removed\.\n/, "$ut: Task removed");
|
||||||
like ($output, qr/No matches\.\n/, 'No matches');
|
like ($output, qr/No matches\.\n/, "$ut: No matches");
|
||||||
|
|
||||||
# Inspect backlog.data
|
# Inspect backlog.data
|
||||||
if (open my $fh, '<', 'backlog.data')
|
if (open my $fh, '<', 'backlog.data')
|
||||||
|
@ -79,21 +83,21 @@ if (open my $fh, '<', 'backlog.data')
|
||||||
close $fh;
|
close $fh;
|
||||||
|
|
||||||
diag ($_) for @lines;
|
diag ($_) for @lines;
|
||||||
is (scalar (@lines), 4, '4 lines of backlog');
|
is (scalar (@lines), 4, "$ut: 4 lines of backlog");
|
||||||
ok (index ($lines[0], '"status":"pending"') != -1, '[0] pending');
|
ok (index ($lines[0], '"status":"pending"') != -1, "$ut: [0] pending");
|
||||||
ok (index ($lines[1], '"status":"completed"') != -1, '[1] completed');
|
ok (index ($lines[1], '"status":"completed"') != -1, "$ut: [1] completed");
|
||||||
ok (index ($lines[2], '"status":"pending"') != -1, '[2] pending');
|
ok (index ($lines[2], '"status":"pending"') != -1, "$ut: [2] pending");
|
||||||
ok (index ($lines[3], '"status":"completed"') != -1, '[3] completed');
|
ok (index ($lines[3], '"status":"completed"') != -1, "$ut: [3] completed");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fail ('4 lines of backlog');
|
fail ("$ut: 4 lines of backlog");
|
||||||
fail ('[0] pending');
|
fail ("$ut: [0] pending");
|
||||||
fail ('[1] completed');
|
fail ("$ut: [1] completed");
|
||||||
fail ('[2] pending');
|
fail ("$ut: [2] pending");
|
||||||
fail ('[3] completed');
|
fail ("$ut: [3] completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Cleanup.
|
# Cleanup.
|
||||||
unlink qw(pending.data completed.data undo.data backlog.data undo.rc);
|
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue