Enhancement - Hooks

- Implemented all command hooks.
- Implemented several field hooks.
- Implemented several task hooks.
- Reorganized event validation code.
- Finalized Hooks -> API::call* mechanism.
- Implemented several hook unit tests.
- Corrected unit tests that didn't specify rc.hooks=on.
- Corrected builds that include Lua.
This commit is contained in:
Paul Beckingham 2010-01-31 23:29:22 -05:00
parent 50f27e0952
commit f351e17a63
15 changed files with 782 additions and 97 deletions

84
src/tests/hook.format-id.t Executable file
View file

@ -0,0 +1,84 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 8;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-id=" . $ENV{'PWD'} . "/hook:priority\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function priority (name, value)\n",
" value = '(' .. value .. ')'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
qx{../task rc:hook.rc add bar};
$output = qx{../task rc:hook.rc ls};
like ($output, qr/\(1\)\s+foo/, 'format-id hook 1 -> (1)');
like ($output, qr/\(2\)\s+bar/, 'format-id hook 2 -> (2)');
}
else
{
pass ('format-id hook 1 -> (1) - skip: no Lua support');
pass ('format-id hook 2 -> (2) - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View file

@ -0,0 +1,95 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 9;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-priority_long=" . $ENV{'PWD'} . "/hook:priority\n",
"report.ls.columns=id,project,priority_long,description\n",
"report.ls.sort=priority_long-,project+\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function priority (name, value)\n",
" if value == 'High' then\n",
" value = '^^^^'\n",
" elseif value == 'Medium' then\n",
" value = '===='\n",
" elseif value == 'Low' then\n",
" value = 'vvvv'\n",
" end\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo pri:H};
qx{../task rc:hook.rc add bar pri:M};
qx{../task rc:hook.rc add baz pri:L};
$output = qx{../task rc:hook.rc ls};
like ($output, qr/\^\^\^\^\s+foo/, 'format-priority_long hook High -> ^^^^');
like ($output, qr/====\s+bar/, 'format-priority_long hook Medium -> ====');
like ($output, qr/vvvv\s+baz/, 'format-priority_long hook Low -> vvvv');
}
else
{
pass ('format-priority_long hook High -> ^^^^ - skip: no Lua support');
pass ('format-priority_long hook Medium -> ==== - skip: no Lua support');
pass ('format-priority_long hook Low -> vvvv - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View file

@ -0,0 +1,93 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 9;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-priority=" . $ENV{'PWD'} . "/hook:priority\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function priority (name, value)\n",
" if value == 'H' then\n",
" value = 'Hi'\n",
" elseif value == 'M' then\n",
" value = 'Me'\n",
" elseif value == 'L' then\n",
" value = 'Lo'\n",
" end\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo pri:H};
qx{../task rc:hook.rc add bar pri:M};
qx{../task rc:hook.rc add baz pri:L};
$output = qx{../task rc:hook.rc ls};
like ($output, qr/Hi\s+foo/, 'format-priority hook H -> Hi');
like ($output, qr/Me\s+bar/, 'format-priority hook M -> Me');
like ($output, qr/Lo\s+baz/, 'format-priority hook L -> Lo');
}
else
{
pass ('format-priority hook H -> Hi - skip: no Lua support');
pass ('format-priority hook M -> Me - skip: no Lua support');
pass ('format-priority hook L -> Lo - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

81
src/tests/hook.format-uuid.t Executable file
View file

@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-uuid=" . $ENV{'PWD'} . "/hook:uuid\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function uuid (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
$output = qx{../task rc:hook.rc info 1};
like ($output, qr/UUID\s+<[0-9a-f-]+>/, 'format-uuid hook uuid -> <uuid>');
}
else
{
pass ('format-uuid hook uuid -> <uuid> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View file

@ -34,6 +34,7 @@ use Test::More tests => 7;
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.post-start=" . $ENV{'PWD'} . "/hook:test\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');

86
src/tests/hook.pre-completed.t Executable file
View file

@ -0,0 +1,86 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 8;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function good () print ('marker') return 0, nil end\n",
"function bad () print ('marker') return 1, 'disallowed' end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
my $good = $ENV{'PWD'} . '/hook:good';
my $bad = $ENV{'PWD'} . '/hook:bad';
qx{echo 'y'|../task rc:hook.rc config -- hook.pre-completed "$bad"};
qx{../task rc:hook.rc add foo};
$output = qx{../task rc:hook.rc done 1};
like ($output, qr/disallowed/, 'pre-completed hook rejected completion');
qx{echo 'y'|../task rc:hook.rc config -- hook.pre-completed "$good"};
$output = qx{../task rc:hook.rc done 1};
like ($output, qr/Marked 1 task as done/, 'pre-completed hook allowed completion');
}
else
{
pass ('pre-complete hook rejected completion - skip: no Lua support');
pass ('pre-complete hook allowed completion - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View file

@ -34,6 +34,7 @@ use Test::More tests => 7;
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.pre-exit=" . $ENV{'PWD'} . "/hook:test\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');

View file

@ -29,7 +29,7 @@
use strict;
use warnings;
use File::Path;
use Test::More tests => 12;
use Test::More tests => 13;
# Create the rc file, using rc.name:value.
unlink 'foo.rc';
@ -68,6 +68,12 @@ qx{echo 'y'|../task rc:foo.rc config must_be_unique};
$output = qx{../task rc:foo.rc config};
unlike ($output, qr/^must_be_unique/ms, 'config removing a value');
# 'report.:b' is designed to get past the config command checks for recognized
# names.
qx{echo 'y'|../task rc:foo.rc config -- report.:b +c};
$output = qx{../task rc:foo.rc config};
like ($output, qr/^report\.:b\s+\+c/ms, 'the -- operator is working');
rmtree 'foo', 0, 0;
ok (!-r 'foo', 'Removed foo');