diff --git a/src/Hooks.cpp b/src/Hooks.cpp index f3012e2b7..c405cdfe9 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -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; diff --git a/src/command.cpp b/src/command.cpp index 73ffde87f..88aab23b8 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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); diff --git a/src/custom.cpp b/src/custom.cpp index ae487da15..9b26b0dd6 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -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,7 +584,10 @@ int runCustomReport ( { std::string recur = tasks[row].get ("recur"); if (recur != "") + { + context.hooks.trigger ("format-recur", "recur", recur); table.addCell (row, columnCount, recur); + } } } @@ -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); } } diff --git a/src/report.cpp b/src/report.cpp index 115a526d7..d27b63453 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -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 diff --git a/src/tests/hook.format-countdown.t b/src/tests/hook.format-countdown.t new file mode 100755 index 000000000..8d0f23ee5 --- /dev/null +++ b/src/tests/hook.format-countdown.t @@ -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 -> '); +} +else +{ + pass ('format-countdown hook 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; + diff --git a/src/tests/hook.format-countdown_compact.t b/src/tests/hook.format-countdown_compact.t new file mode 100755 index 000000000..1820d378c --- /dev/null +++ b/src/tests/hook.format-countdown_compact.t @@ -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 -> '); +} +else +{ + pass ('format-countdown_compact hook 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; + diff --git a/src/tests/hook.format-due.t b/src/tests/hook.format-due.t new file mode 100755 index 000000000..42c106427 --- /dev/null +++ b/src/tests/hook.format-due.t @@ -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 -> '); +} +else +{ + pass ('format-due hook 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; + diff --git a/src/tests/hook.format-end.t b/src/tests/hook.format-end.t new file mode 100755 index 000000000..10a21d302 --- /dev/null +++ b/src/tests/hook.format-end.t @@ -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 -> '); +} +else +{ + pass ('format-end hook 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; + diff --git a/src/tests/hook.format-end_time.t b/src/tests/hook.format-end_time.t new file mode 100755 index 000000000..76de1ce33 --- /dev/null +++ b/src/tests/hook.format-end_time.t @@ -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 -> '); +} +else +{ + pass ('format-end_time hook 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; + diff --git a/src/tests/hook.format-entry.t b/src/tests/hook.format-entry.t new file mode 100755 index 000000000..fd709df46 --- /dev/null +++ b/src/tests/hook.format-entry.t @@ -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 -> '); +} +else +{ + pass ('format-entry hook 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; + diff --git a/src/tests/hook.format-entry_time.t b/src/tests/hook.format-entry_time.t new file mode 100755 index 000000000..45c297311 --- /dev/null +++ b/src/tests/hook.format-entry_time.t @@ -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 -> '); +} +else +{ + pass ('format-entry_time hook 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; + diff --git a/src/tests/hook.format-prompt.t b/src/tests/hook.format-prompt.t new file mode 100755 index 000000000..777132d3c --- /dev/null +++ b/src/tests/hook.format-prompt.t @@ -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//, 'format-prompt hook prompt -> '); +} +else +{ + pass ('format-prompt hook 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; + diff --git a/src/tests/hook.format-recur.t b/src/tests/hook.format-recur.t new file mode 100755 index 000000000..3e99b9bbc --- /dev/null +++ b/src/tests/hook.format-recur.t @@ -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//, 'format-recur hook recur -> '); +} +else +{ + pass ('format-recur hook 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; + diff --git a/src/tests/hook.format-start.t b/src/tests/hook.format-start.t new file mode 100755 index 000000000..d192ef513 --- /dev/null +++ b/src/tests/hook.format-start.t @@ -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 -> '); +} +else +{ + pass ('format-start hook 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; + diff --git a/src/tests/hook.format-start_time.t b/src/tests/hook.format-start_time.t new file mode 100755 index 000000000..3e6ea16f1 --- /dev/null +++ b/src/tests/hook.format-start_time.t @@ -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 -> '); +} +else +{ + pass ('format-start_time hook 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; + diff --git a/src/tests/hook.format-wait.t b/src/tests/hook.format-wait.t new file mode 100755 index 000000000..f8924ac64 --- /dev/null +++ b/src/tests/hook.format-wait.t @@ -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 -> '); +} +else +{ + pass ('format-wait hook 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; +