- Converted ::safety from Parser to CLI.
- Updated unit tests to use the new template.
- Added tests to cover both values of rc.allow.empty.filter.
This commit is contained in:
Paul Beckingham 2014-10-26 09:02:51 -04:00
parent 87cd22792d
commit 74526ee564
2 changed files with 40 additions and 29 deletions

View file

@ -258,27 +258,29 @@ bool Filter::pendingOnly ()
// all tasks to be modified. This is usually not intended.
void Filter::safety ()
{
Tree* tree = context.parser.tree ();
std::vector <Tree*>::iterator i;
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
std::vector <A>::iterator a;
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
{
if ((*i)->hasTag ("WRITECMD"))
if (a->hasTag ("CMD"))
{
if (context.parser.getFilterExpression () == "")
if (a->hasTag ("WRITECMD"))
{
if (! context.config.getBoolean ("allow.empty.filter"))
throw std::string (STRING_TASK_SAFETY_ALLOW);
if (context.cli.getFilter () == "")
{
if (! context.config.getBoolean ("allow.empty.filter"))
throw std::string (STRING_TASK_SAFETY_ALLOW);
// If user is willing to be asked, this can be avoided.
if (context.config.getBoolean ("confirmation") &&
confirm (STRING_TASK_SAFETY_VALVE))
return;
// If user is willing to be asked, this can be avoided.
if (context.config.getBoolean ("confirmation") &&
confirm (STRING_TASK_SAFETY_VALVE))
return;
// Sounds the alarm.
throw std::string (STRING_TASK_SAFETY_FAIL);
// Sounds the alarm.
throw std::string (STRING_TASK_SAFETY_FAIL);
}
}
// Nothing to see here. Move along.
// CMD was found.
return;
}
}

View file

@ -27,14 +27,18 @@
use strict;
use warnings;
use Test::More tests => 6;
use Test::More tests => 8;
# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
# Create the rc file.
if (open my $fh, '>', 'args.rc')
if (open my $fh, '>', $rc)
{
print $fh "data.location=.\n",
"confirmation=off\n";
@ -42,22 +46,27 @@ if (open my $fh, '>', 'args.rc')
}
# Test id before command, and id after command.
qx{../src/task rc:args.rc add one 2>&1};
qx{../src/task rc:args.rc add two 2>&1};
qx{../src/task rc:args.rc add three 2>&1};
my $output = qx{../src/task rc:args.rc list 2>&1};
like ($output, qr/one/, 'task 1 added');
like ($output, qr/two/, 'task 2 added');
like ($output, qr/three/, 'task 3 added');
qx{../src/task rc:$rc add one 2>&1};
qx{../src/task rc:$rc add two 2>&1};
qx{../src/task rc:$rc add three 2>&1};
my $output = qx{../src/task rc:$rc list 2>&1};
like ($output, qr/one/, "$ut: task 1 added");
like ($output, qr/two/, "$ut: task 2 added");
like ($output, qr/three/, "$ut: task 3 added");
$output = qx{../src/task rc:args.rc 1 done 2>&1};
like ($output, qr/^Completed 1 task.$/ms, 'COMMAND after ID');
$output = qx{../src/task rc:$rc 1 done 2>&1};
like ($output, qr/^Completed 1 task\.$/ms, "$ut: COMMAND after ID");
$output = qx{../src/task rc:args.rc done 2 2>&1};
like ($output, qr/^Command prevented from running.$/ms, 'ID after COMMAND');
unlike ($output, qr/^Completed 1 task.$/ms, 'ID after COMMAND');
$output = qx{../src/task rc:$rc rc.allow.empty.filter:yes done 2 2>&1};
like ($output, qr/^Command prevented from running.$/ms, "$ut: ID after COMMAND, allowing empty filter");
unlike ($output, qr/^Completed 1 task\.$/ms, "$ut: ID after COMMAND, allowing empty filter");
$output = qx{../src/task rc:$rc rc.allow.empty.filter:no done 2 2>&1};
like ($output, qr/^You did not specify a filter, and with the 'allow\.empty\.filter' value, no action is taken\.$/ms,
"$ut: ID after COMMAND, disallowing empty filter");
unlike ($output, qr/^Completed 1 task\.$/ms, "$ut: ID after COMMAND, disallowing empty filter");
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data args.rc);
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
exit 0;