Enhancement - Hooks

- Added many more format hooks.
- Added unit tests for all added hooks.
- Added unit tests for format-countdown and format-countdown_compact.
This commit is contained in:
Paul Beckingham 2010-03-01 18:14:06 -05:00
parent 95e420bb15
commit f6ff18e31d
16 changed files with 1035 additions and 22 deletions

View file

@ -372,7 +372,8 @@ bool Hooks::validFieldEvent (const std::string& event)
event == "format-tag_indicator" ||
event == "format-description_only" ||
event == "format-description" ||
event == "format-wait")
event == "format-wait" ||
event == "format-prompt")
return true;
return false;

View file

@ -1646,7 +1646,13 @@ void handleShell ()
do
{
std::cout << context.config.get ("shell.prompt") << " ";
std::string prompt = context.config.get ("shell.prompt");
if (context.hooks.trigger ("pre-shell-prompt"))
{
context.hooks.trigger ("format-prompt", "prompt", prompt);
std::cout << prompt << " ";
}
context.hooks.trigger ("post-shell-prompt");
command = "";
std::getline (std::cin, command);

View file

@ -287,6 +287,7 @@ int runCustomReport (
{
Date dt (::atoi (entered.c_str ()));
entered = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-entry", "entry", entered);
table.addCell (row, columnCount, entered);
}
}
@ -306,6 +307,7 @@ int runCustomReport (
{
Date dt (::atoi (entered.c_str ()));
entered = dt.toStringWithTime (context.config.get ("dateformat"));
context.hooks.trigger ("format-entry_time", "entry_time", entered);
table.addCell (row, columnCount, entered);
}
}
@ -325,6 +327,7 @@ int runCustomReport (
{
Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-start", "start", started);
table.addCell (row, columnCount, started);
}
}
@ -344,6 +347,7 @@ int runCustomReport (
{
Date dt (::atoi (started.c_str ()));
started = dt.toStringWithTime (context.config.get ("dateformat"));
context.hooks.trigger ("format-start_time", "start_time", started);
table.addCell (row, columnCount, started);
}
}
@ -355,15 +359,16 @@ int runCustomReport (
table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right);
std::string started;
std::string ended;
for (unsigned int row = 0; row < tasks.size(); ++row)
{
started = tasks[row].get ("end");
if (started.length ())
ended = tasks[row].get ("end");
if (ended.length ())
{
Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat"));
table.addCell (row, columnCount, started);
Date dt (::atoi (ended.c_str ()));
ended = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-end", "end", ended);
table.addCell (row, columnCount, ended);
}
}
}
@ -376,15 +381,16 @@ int runCustomReport (
std::string format = context.config.get ("dateformat");
std::string started;
std::string ended;
for (unsigned int row = 0; row < tasks.size(); ++row)
{
started = tasks[row].get ("end");
if (started.length ())
ended = tasks[row].get ("end");
if (ended.length ())
{
Date dt (::atoi (started.c_str ()));
started = dt.toStringWithTime (format);
table.addCell (row, columnCount, started);
Date dt (::atoi (ended.c_str ()));
ended = dt.toStringWithTime (format);
context.hooks.trigger ("format-end_time", "end_time", ended);
table.addCell (row, columnCount, ended);
}
}
}
@ -404,7 +410,11 @@ int runCustomReport (
int row = 0;
std::string due;
foreach (task, tasks)
table.addCell (row++, columnCount, getDueDate (*task, format));
{
std::string value = getDueDate (*task, format);
context.hooks.trigger ("format-due", "due", value);
table.addCell (row++, columnCount, value);
}
dueColumn = columnCount;
}
@ -574,9 +584,12 @@ int runCustomReport (
{
std::string recur = tasks[row].get ("recur");
if (recur != "")
{
context.hooks.trigger ("format-recur", "recur", recur);
table.addCell (row, columnCount, recur);
}
}
}
else if (*col == "recurrence_indicator")
{
@ -615,6 +628,7 @@ int runCustomReport (
{
Date dt (::atoi (wait.c_str ()));
wait = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-wait", "wait", wait);
table.addCell (row++, columnCount, wait);
}
}

View file

@ -399,7 +399,9 @@ int handleInfo (std::string &outs)
{
row = table.addRow ();
table.addCell (row, 0, "Recurrence");
table.addCell (row, 1, task->get ("recur"));
value = task->get ("recur");
context.hooks.trigger ("format-recur", "recur", value);
table.addCell (row, 1, value);
}
// until
@ -445,13 +447,13 @@ int handleInfo (std::string &outs)
row = table.addRow ();
table.addCell (row, 0, "Due");
Date dt (atoi (task->get ("due").c_str ()));
std::string format = context.config.get ("reportdateformat");
if (format == "")
format = context.config.get ("dateformat");
std::string due = getDueDate (*task, format);
table.addCell (row, 1, due);
value = getDueDate (*task, format);
context.hooks.trigger ("format-due", "due", value);
table.addCell (row, 1, value);
}
// wait
@ -460,7 +462,9 @@ int handleInfo (std::string &outs)
row = table.addRow ();
table.addCell (row, 0, "Waiting until");
Date dt (atoi (task->get ("wait").c_str ()));
table.addCell (row, 1, dt.toString (context.config.get ("dateformat")));
value = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-wait", "wait", value);
table.addCell (row, 1, value);
}
// start
@ -469,7 +473,10 @@ int handleInfo (std::string &outs)
row = table.addRow ();
table.addCell (row, 0, "Start");
Date dt (atoi (task->get ("start").c_str ()));
table.addCell (row, 1, dt.toString (context.config.get ("dateformat")));
value = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-due", "due", value);
table.addCell (row, 1, value);
}
// end
@ -478,7 +485,9 @@ int handleInfo (std::string &outs)
row = table.addRow ();
table.addCell (row, 0, "End");
Date dt (atoi (task->get ("end").c_str ()));
table.addCell (row, 1, dt.toString (context.config.get ("dateformat")));
value = dt.toString (context.config.get ("dateformat"));
context.hooks.trigger ("format-end", "end", value);
table.addCell (row, 1, value);
}
// tags ...
@ -515,6 +524,7 @@ int handleInfo (std::string &outs)
age = formatSeconds ((time_t) (now - dt));
}
context.hooks.trigger ("format-entry", "entry", entry);
table.addCell (row, 1, entry + " (" + age + ")");
// fg

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-countdown=" . $ENV{'PWD'} . "/hook:countdown\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function countdown (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 due:eom};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<(?:- )?\d+.+>/, 'format-countdown hook countdown -> <countdown>');
}
else
{
pass ('format-countdown hook countdown -> <countdown> - 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,83 @@
#! /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",
"report.long.columns=id,project,priority,entry,start_time,due,",
"recur,countdown_compact,age,tags,description\n",
"hooks=on\n",
"hook.format-countdown_compact=" . $ENV{'PWD'} . "/hook:countdown_compact\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function countdown_compact (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 due:eom};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<(?:- )?\d+.+>/, 'format-countdown_compact hook countdown_compact -> <countdown_compact>');
}
else
{
pass ('format-countdown_compact hook countdown_compact -> <countdown_compact> - 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-due.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-due=" . $ENV{'PWD'} . "/hook:due\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function due (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 due:tomorrow};
$output = qx{../task rc:hook.rc list};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-due hook due -> <due>');
}
else
{
pass ('format-due hook due -> <due> - 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;

82
src/tests/hook.format-end.t Executable file
View file

@ -0,0 +1,82 @@
#! /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-end=" . $ENV{'PWD'} . "/hook:xend\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function xend (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 do 1};
$output = qx{../task rc:hook.rc completed};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-end hook end -> <end>');
}
else
{
pass ('format-end hook end -> <end> - 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,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 => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"report.completed.columns=end_time,project,priority,age,description\n",
"report.completed.sort=end_time+,priority-,project+\n",
"hooks=on\n",
"hook.format-end_time=" . $ENV{'PWD'} . "/hook:end_time\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function end_time (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 do 1};
$output = qx{../task rc:hook.rc completed};
like ($output, qr/<\d+\/\d+\/\d+\s\d+:\d+:\d+>/, 'format-end_time hook end_time -> <end_time>');
}
else
{
pass ('format-end_time hook end_time -> <end_time> - 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-entry.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-entry=" . $ENV{'PWD'} . "/hook:entry\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function entry (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 long};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-entry hook entry -> <entry>');
}
else
{
pass ('format-entry hook entry -> <entry> - 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,82 @@
#! /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",
"report.long.columns=id,project,priority,entry_time,start,due,recur,countdown,age,tags,description\n",
"hooks=on\n",
"hook.format-entry_time=" . $ENV{'PWD'} . "/hook:entry_time\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function entry_time (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 long};
like ($output, qr/<\d+\/\d+\/\d+\s\d+:\d+:\d+>/, 'format-entry_time hook entry_time -> <entry_time>');
}
else
{
pass ('format-entry_time hook entry_time -> <entry_time> - 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-prompt.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",
"shell.prompt=foo\n",
"default.command=_version\n",
"hooks=on\n",
"hook.format-prompt=" . $ENV{'PWD'} . "/hook:prompt\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function prompt (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/)
{
my $output = qx{echo "\\nquit\\n" | ../task rc:hook.rc shell};
like ($output, qr/<foo>/, 'format-prompt hook prompt -> <prompt>');
}
else
{
pass ('format-prompt hook prompt -> <prompt> - 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-recur.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-recur=" . $ENV{'PWD'} . "/hook:recur\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function recur (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 due:tomorrow recur:weekly};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<weekly>/, 'format-recur hook recur -> <recur>');
}
else
{
pass ('format-recur hook recur -> <recur> - 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;

82
src/tests/hook.format-start.t Executable file
View file

@ -0,0 +1,82 @@
#! /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-start=" . $ENV{'PWD'} . "/hook:start\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function start (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 start 1};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-start hook start -> <start>');
}
else
{
pass ('format-start hook start -> <start> - 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,83 @@
#! /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",
"report.long.columns=id,project,priority,entry,start_time,due,recur,countdown,age,tags,description\n",
"hooks=on\n",
"hook.format-start_time=" . $ENV{'PWD'} . "/hook:start_time\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function start_time (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 start 1};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<\d+\/\d+\/\d+\s\d+:\d+:\d+>/, 'format-start_time hook start_time -> <start_time>');
}
else
{
pass ('format-start_time hook start_time -> <start_time> - 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-wait.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-wait=" . $ENV{'PWD'} . "/hook:wait\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function wait (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 wait:tomorrow};
$output = qx{../task rc:hook.rc waiting};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-wait hook wait -> <wait>');
}
else
{
pass ('format-wait hook wait -> <wait> - 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;