diff --git a/src/API.cpp b/src/API.cpp index b21d645b8..504af8574 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -53,6 +53,7 @@ #include "API.h" extern Context context; +Task* the_task = NULL; #ifdef HAVE_LIBLUA @@ -120,7 +121,10 @@ static int api_task_feature (lua_State* L) #endif } - lua_pushnumber (L, value ? 1 : 0); + else if (name == "lua") + value = true; + + lua_pushboolean (L, value ? 1 : 0); return 1; } @@ -130,14 +134,18 @@ static int api_task_aliases () { return {}; } +*/ //////////////////////////////////////////////////////////////////////////////// --- Returns values from .taskrc, by name. -static int api_task_get_config (name) +// Returns values from .taskrc, by name. +static int api_task_get_config (lua_State* L) { - return "foo" + std::string name = luaL_checkstring (L, 1); + lua_pushstring (L, context.config.get (name).c_str ()); + return 1; } +/* //////////////////////////////////////////////////////////////////////////////// -- Temporarily sets .taskrc values, by name. static int api_task_set_config (name, value) @@ -221,9 +229,9 @@ static int api_task_inhibit_further_hooks () //////////////////////////////////////////////////////////////////////////////// -- Returns a table that contains a complete copy of the task. -static int api_task_get (id) +static int api_task_get (lua_State* L) { - return task + return 1; } //////////////////////////////////////////////////////////////////////////////// @@ -237,52 +245,83 @@ static int api_task_add (t) static int api_task_modify (t) { } +*/ //////////////////////////////////////////////////////////////////////////////// --- 'id' is the task id passed to the hook function. Date attributes are --- returned as a numeric epoch offset. Tags and annotations are returned --- as tables. A nil value indicates a missing value. -static int api_task_get_uuid (id) +// -- 'id' is the task id passed to the hook function. Date attributes are +// -- returned as a numeric epoch offset. Tags and annotations are returned +// -- as tables. A nil value indicates a missing value. +static int api_task_get_uuid (lua_State* L) { - return task.uuid + if (the_task != NULL) + lua_pushstring (L, the_task->get ("uuid").c_str ()); + else + lua_pushnil (L); + + return 1; } //////////////////////////////////////////////////////////////////////////////// -static int api_task_get_description (id) +static int api_task_get_description (lua_State* L) { - return task.description + if (the_task != NULL) + lua_pushstring (L, the_task->get ("description").c_str ()); + else + lua_pushnil (L); + + return 1; } +/* //////////////////////////////////////////////////////////////////////////////// static int api_task_get_annotations (id) { return task.annotations } +*/ //////////////////////////////////////////////////////////////////////////////// -static int api_task_get_project (id) +static int api_task_get_project (lua_State* L) { - return task.project + if (the_task != NULL) + lua_pushstring (L, the_task->get ("project").c_str ()); + else + lua_pushnil (L); + + return 1; } //////////////////////////////////////////////////////////////////////////////// -static int api_task_get_priority (id) +static int api_task_get_priority (lua_State* L) { - return task.priority + if (the_task != NULL) + lua_pushstring (L, the_task->get ("priority").c_str ()); + else + lua_pushnil (L); + + return 1; } +/* //////////////////////////////////////////////////////////////////////////////// static int api_task_get_tags (id) { return task.tags } +*/ //////////////////////////////////////////////////////////////////////////////// -static int api_task_get_status (id) +static int api_task_get_status (lua_State* L) { - return task.status + if (the_task != NULL) + lua_pushstring (L, Task::statusToText (the_task->getStatus ()).c_str ()); + else + lua_pushnil (L); + + return 1; } +/* //////////////////////////////////////////////////////////////////////////////// static int api_task_get_due (id) { @@ -424,50 +463,58 @@ void API::initialize () lua_pushcfunction (L, api_task_os); lua_setglobal (L, "task_os"); lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature"); /* - lua_pushcfunction (L, api_task_aliases); lua_setglobal (L, "api_task_aliases"); - lua_pushcfunction (L, api_task_get_config); lua_setglobal (L, "api_task_get_config"); - lua_pushcfunction (L, api_task_set_config); lua_setglobal (L, "api_task_set_config"); - lua_pushcfunction (L, api_task_i18n_string); lua_setglobal (L, "api_task_i18n_string"); - lua_pushcfunction (L, api_task_i18n_tips); lua_setglobal (L, "api_task_i18n_tips"); - lua_pushcfunction (L, api_task_get_command); lua_setglobal (L, "api_task_get_command"); - lua_pushcfunction (L, api_task_get_header_messages); lua_setglobal (L, "api_task_get_header_messages"); - lua_pushcfunction (L, api_task_get_footnote_messages); lua_setglobal (L, "api_task_get_footnote_messages"); - lua_pushcfunction (L, api_task_get_debug_messages); lua_setglobal (L, "api_task_get_debug_messages"); - lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "api_task_header_message"); - lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "api_task_footnote_message"); - lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "api_task_debug_message"); + lua_pushcfunction (L, api_task_aliases); lua_setglobal (L, "task_aliases"); +*/ + lua_pushcfunction (L, api_task_get_config); lua_setglobal (L, "task_get_config"); +/* + lua_pushcfunction (L, api_task_set_config); lua_setglobal (L, "task_set_config"); + lua_pushcfunction (L, api_task_i18n_string); lua_setglobal (L, "task_i18n_string"); + lua_pushcfunction (L, api_task_i18n_tips); lua_setglobal (L, "task_i18n_tips"); + lua_pushcfunction (L, api_task_get_command); lua_setglobal (L, "task_get_command"); + lua_pushcfunction (L, api_task_get_header_messages); lua_setglobal (L, "task_get_header_messages"); + lua_pushcfunction (L, api_task_get_footnote_messages); lua_setglobal (L, "task_get_footnote_messages"); + lua_pushcfunction (L, api_task_get_debug_messages); lua_setglobal (L, "task_get_debug_messages"); + lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message"); + lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message"); + lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message"); */ lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit"); /* - lua_pushcfunction (L, api_task_inhibit_further_hooks); lua_setglobal (L, "api_task_inhibit_further_hooks"); - lua_pushcfunction (L, api_task_get); lua_setglobal (L, "api_task_get"); - lua_pushcfunction (L, api_task_add); lua_setglobal (L, "api_task_add"); - lua_pushcfunction (L, api_task_modify); lua_setglobal (L, "api_task_modify"); - lua_pushcfunction (L, api_task_get_uuid); lua_setglobal (L, "api_task_get_uuid"); - lua_pushcfunction (L, api_task_get_description); lua_setglobal (L, "api_task_get_description"); - lua_pushcfunction (L, api_task_get_annotations); lua_setglobal (L, "api_task_get_annotations"); - lua_pushcfunction (L, api_task_get_project); lua_setglobal (L, "api_task_get_project"); - lua_pushcfunction (L, api_task_get_priority); lua_setglobal (L, "api_task_get_priority"); - lua_pushcfunction (L, api_task_get_tags); lua_setglobal (L, "api_task_get_tags"); - lua_pushcfunction (L, api_task_get_status); lua_setglobal (L, "api_task_get_status"); - lua_pushcfunction (L, api_task_get_due); lua_setglobal (L, "api_task_get_due"); - lua_pushcfunction (L, api_task_get_entry); lua_setglobal (L, "api_task_get_entry"); - lua_pushcfunction (L, api_task_get_start); lua_setglobal (L, "api_task_get_start"); - lua_pushcfunction (L, api_task_get_end); lua_setglobal (L, "api_task_get_end"); - lua_pushcfunction (L, api_task_get_recur); lua_setglobal (L, "api_task_get_recur"); - lua_pushcfunction (L, api_task_get_until); lua_setglobal (L, "api_task_get_until"); - lua_pushcfunction (L, api_task_get_wait); lua_setglobal (L, "api_task_get_wait"); - lua_pushcfunction (L, api_task_set_description); lua_setglobal (L, "api_task_set_description"); - lua_pushcfunction (L, api_task_set_annotations); lua_setglobal (L, "api_task_set_annotations"); - lua_pushcfunction (L, api_task_set_project); lua_setglobal (L, "api_task_set_project"); - lua_pushcfunction (L, api_task_set_priority); lua_setglobal (L, "api_task_set_priority"); - lua_pushcfunction (L, api_task_set_tags); lua_setglobal (L, "api_task_set_tags"); - lua_pushcfunction (L, api_task_set_status); lua_setglobal (L, "api_task_set_status"); - lua_pushcfunction (L, api_task_set_due); lua_setglobal (L, "api_task_set_due"); - lua_pushcfunction (L, api_task_set_start); lua_setglobal (L, "api_task_set_start"); - lua_pushcfunction (L, api_task_set_recur); lua_setglobal (L, "api_task_set_recur"); - lua_pushcfunction (L, api_task_set_until); lua_setglobal (L, "api_task_set_until"); - lua_pushcfunction (L, api_task_set_wait); lua_setglobal (L, "api_task_set_wait"); + lua_pushcfunction (L, api_task_inhibit_further_hooks); lua_setglobal (L, "task_inhibit_further_hooks"); + lua_pushcfunction (L, api_task_get); lua_setglobal (L, "task_get"); + lua_pushcfunction (L, api_task_add); lua_setglobal (L, "task_add"); + lua_pushcfunction (L, api_task_modify); lua_setglobal (L, "task_modify"); +*/ + lua_pushcfunction (L, api_task_get_uuid); lua_setglobal (L, "task_get_uuid"); + lua_pushcfunction (L, api_task_get_description); lua_setglobal (L, "task_get_description"); +/* + lua_pushcfunction (L, api_task_get_annotations); lua_setglobal (L, "task_get_annotations"); +*/ + lua_pushcfunction (L, api_task_get_project); lua_setglobal (L, "task_get_project"); + lua_pushcfunction (L, api_task_get_priority); lua_setglobal (L, "task_get_priority"); +/* + lua_pushcfunction (L, api_task_get_tags); lua_setglobal (L, "task_get_tags"); +*/ + lua_pushcfunction (L, api_task_get_status); lua_setglobal (L, "task_get_status"); +/* + lua_pushcfunction (L, api_task_get_due); lua_setglobal (L, "task_get_due"); + lua_pushcfunction (L, api_task_get_entry); lua_setglobal (L, "task_get_entry"); + lua_pushcfunction (L, api_task_get_start); lua_setglobal (L, "task_get_start"); + lua_pushcfunction (L, api_task_get_end); lua_setglobal (L, "task_get_end"); + lua_pushcfunction (L, api_task_get_recur); lua_setglobal (L, "task_get_recur"); + lua_pushcfunction (L, api_task_get_until); lua_setglobal (L, "task_get_until"); + lua_pushcfunction (L, api_task_get_wait); lua_setglobal (L, "task_get_wait"); + lua_pushcfunction (L, api_task_set_description); lua_setglobal (L, "task_set_description"); + lua_pushcfunction (L, api_task_set_annotations); lua_setglobal (L, "task_set_annotations"); + lua_pushcfunction (L, api_task_set_project); lua_setglobal (L, "task_set_project"); + lua_pushcfunction (L, api_task_set_priority); lua_setglobal (L, "task_set_priority"); + lua_pushcfunction (L, api_task_set_tags); lua_setglobal (L, "task_set_tags"); + lua_pushcfunction (L, api_task_set_status); lua_setglobal (L, "task_set_status"); + lua_pushcfunction (L, api_task_set_due); lua_setglobal (L, "task_set_due"); + lua_pushcfunction (L, api_task_set_start); lua_setglobal (L, "task_set_start"); + lua_pushcfunction (L, api_task_set_recur); lua_setglobal (L, "task_set_recur"); + lua_pushcfunction (L, api_task_set_until); lua_setglobal (L, "task_set_until"); + lua_pushcfunction (L, api_task_set_wait); lua_setglobal (L, "task_set_wait"); */ } @@ -555,10 +602,16 @@ bool API::callTaskHook ( // Prepare args. lua_pushnumber (L, current.id); + // Expose the task. + the_task = ¤t; + // Make call. if (lua_pcall (L, 1, 2, 0) != 0) throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1); + // Hide the task. + the_task = NULL; + // Call successful - get return values. if (!lua_isnumber (L, -2)) throw std::string ("Error: '") + function + "' did not return a success indicator"; diff --git a/src/command.cpp b/src/command.cpp index 63b236e21..74ac69ce5 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1255,6 +1255,8 @@ int handleExport (std::string &outs) foreach (task, tasks) { + context.hooks.trigger ("pre-display", *task); + if (task->getStatus () != Task::recurring) { out << task->composeCSV ().c_str (); diff --git a/src/custom.cpp b/src/custom.cpp index 3df210391..ddf45eb36 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -169,7 +169,10 @@ int runCustomReport ( table.setReportName (report); foreach (task, tasks) + { table.addRow (); + context.hooks.trigger ("pre-display", *task); + } int columnCount = 0; int dueColumn = -1; diff --git a/src/report.cpp b/src/report.cpp index fe3f4795a..c9a97ec8b 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -349,6 +349,9 @@ int handleInfo (std::string &outs) table.setColumnJustification (1, Table::left); Date now; + context.hooks.trigger ("pre-display", *task); + + // id char svalue[12]; std::string value; int row = table.addRow (); @@ -360,14 +363,17 @@ int handleInfo (std::string &outs) std::string status = ucFirst (Task::statusToText (task->getStatus ())); + // description row = table.addRow (); table.addCell (row, 0, "Description"); table.addCell (row, 1, getFullDescription (*task, "info")); + // status row = table.addRow (); table.addCell (row, 0, "Status"); table.addCell (row, 1, status); + // project if (task->has ("project")) { row = table.addRow (); @@ -375,6 +381,7 @@ int handleInfo (std::string &outs) table.addCell (row, 1, task->get ("project")); } + // priority if (task->has ("priority")) { row = table.addRow (); @@ -387,6 +394,7 @@ int handleInfo (std::string &outs) if (task->getStatus () == Task::recurring || task->has ("parent")) { + // recur if (task->has ("recur")) { row = table.addRow (); @@ -394,6 +402,7 @@ int handleInfo (std::string &outs) table.addCell (row, 1, task->get ("recur")); } + // until if (task->has ("until")) { row = table.addRow (); @@ -408,6 +417,7 @@ int handleInfo (std::string &outs) table.addCell (row, 1, until); } + // mask if (task->has ("mask")) { row = table.addRow (); @@ -415,6 +425,7 @@ int handleInfo (std::string &outs) table.addCell (row, 1, task->get ("mask")); } + // parent if (task->has ("parent")) { row = table.addRow (); @@ -422,6 +433,7 @@ int handleInfo (std::string &outs) table.addCell (row, 1, task->get ("parent")); } + // imask row = table.addRow (); table.addCell (row, 0, "Mask Index"); table.addCell (row, 1, task->get ("imask")); @@ -1255,6 +1267,8 @@ int handleReportTimesheet (std::string &outs) // If task completed within range. if (task->getStatus () == Task::completed) { + context.hooks.trigger ("pre-display", *task); + Date compDate (atoi (task->get ("end").c_str ())); if (compDate >= start && compDate < end) { @@ -1314,6 +1328,8 @@ int handleReportTimesheet (std::string &outs) if (task->getStatus () == Task::pending && task->has ("start")) { + context.hooks.trigger ("pre-display", *task); + Date startDate (atoi (task->get ("start").c_str ())); if (startDate >= start && startDate < end) { diff --git a/src/tests/hook.api.task_exit.t b/src/tests/hook.api.task_exit.t new file mode 100755 index 000000000..4a8177e17 --- /dev/null +++ b/src/tests/hook.api.task_exit.t @@ -0,0 +1,76 @@ +#! /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.pre-exit=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () task_exit () return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + $output = qx{../task rc:hook.rc _version}; + like ($output, qr/^Exiting.$/ms, 'Hook called task_exit'); +} +else +{ + pass ('Hook called task_exit - 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.api.task_feature.t b/src/tests/hook.api.task_feature.t new file mode 100755 index 000000000..7961c76a0 --- /dev/null +++ b/src/tests/hook.api.task_feature.t @@ -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", + "hook.pre-exit=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test ()\n", + " if task_feature ('lua') then\n", + " print ('<>')\n", + " end\n", + " if task_feature ('foo') then\n", + " print ('<>')\n", + " end\n", + " return 0, nil\n", + "end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + $output = qx{../task rc:hook.rc _version}; + like ($output, qr/^<>$/ms, 'Hook called task_feature (lua)'); + unlike ($output, qr/^<>$/ms, 'Hook called task_feature (foo)'); +} +else +{ + pass ('Hook called task_feature (lua) - skip: no Lua support'); + pass ('Hook called task_feature (foo) - 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.api.task_get_config.t b/src/tests/hook.api.task_get_config.t new file mode 100755 index 000000000..27cc22786 --- /dev/null +++ b/src/tests/hook.api.task_get_config.t @@ -0,0 +1,77 @@ +#! /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", + "nag=NAG-STRING\n", + "hooks=on\n", + "hook.post-start=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print (task_get_config ('nag')) return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + $output = qx{../task rc:hook.rc _version}; + like ($output, qr/^NAG-STRING$/ms, 'Hook called task_get_config'); +} +else +{ + pass ('Hook called task_get_config - 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.api.task_get_description.t b/src/tests/hook.api.task_get_description.t new file mode 100755 index 000000000..84400d570 --- /dev/null +++ b/src/tests/hook.api.task_get_description.t @@ -0,0 +1,77 @@ +#! /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.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_get_description () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/^<>$/ms, 'Hook called task_get_description'); +} +else +{ + pass ('Hook called task_get_description - 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.api.task_get_priority.t b/src/tests/hook.api.task_get_priority.t new file mode 100755 index 000000000..45ffda0f5 --- /dev/null +++ b/src/tests/hook.api.task_get_priority.t @@ -0,0 +1,77 @@ +#! /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.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_get_priority () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo priority:M}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/^<>$/ms, 'Hook called task_get_priority'); +} +else +{ + pass ('Hook called task_get_priority - 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.api.task_get_project.t b/src/tests/hook.api.task_get_project.t new file mode 100755 index 000000000..6da6662ae --- /dev/null +++ b/src/tests/hook.api.task_get_project.t @@ -0,0 +1,77 @@ +#! /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.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_get_project () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo pro:PPP}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/^<>$/ms, 'Hook called task_get_project'); +} +else +{ + pass ('Hook called task_get_project - 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.api.task_get_status.t b/src/tests/hook.api.task_get_status.t new file mode 100755 index 000000000..f7f675a50 --- /dev/null +++ b/src/tests/hook.api.task_get_status.t @@ -0,0 +1,77 @@ +#! /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.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_get_status () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/^<>$/ms, 'Hook called task_get_status'); +} +else +{ + pass ('Hook called task_get_status - 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.api.task_get_uuid.t b/src/tests/hook.api.task_get_uuid.t new file mode 100755 index 000000000..f6f0af2da --- /dev/null +++ b/src/tests/hook.api.task_get_uuid.t @@ -0,0 +1,77 @@ +#! /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.pre-display=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_get_uuid () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + qx{../task rc:hook.rc add foo}; + $output = qx{../task rc:hook.rc info 1}; + like ($output, qr/^<<.+>>$/ms, 'Hook called task_get_uuid'); +} +else +{ + pass ('Hook called task_get_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; + diff --git a/src/tests/hook.api.task_lua_version.t b/src/tests/hook.api.task_lua_version.t new file mode 100755 index 000000000..8db97ebcd --- /dev/null +++ b/src/tests/hook.api.task_lua_version.t @@ -0,0 +1,76 @@ +#! /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.pre-exit=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_lua_version () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + $output = qx{../task rc:hook.rc _version}; + like ($output, qr/^<<\d\.\d+\.\d+.*>>$/ms, 'Hook called task_lua_version'); +} +else +{ + pass ('Hook called task_lua_version - 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.api.task_os.t b/src/tests/hook.api.task_os.t new file mode 100755 index 000000000..98a17c66e --- /dev/null +++ b/src/tests/hook.api.task_os.t @@ -0,0 +1,80 @@ +#! /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.pre-exit=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_os () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + $output = qx{../task rc:hook.rc _version}; + + my ($os) = $output =~ /^<<(darwin|solaris|cygwin|openbsd|haiku|freebsd|linux)>>$/ms; + diag ($os); + + like ($os, qr/darwin|solaris|cygwin|openbsd|haiku|freebsd|linux/, 'Hook called task_os'); +} +else +{ + pass ('Hook called task_os - 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.api.task_version.t b/src/tests/hook.api.task_version.t new file mode 100755 index 000000000..553cdca5f --- /dev/null +++ b/src/tests/hook.api.task_version.t @@ -0,0 +1,76 @@ +#! /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.pre-exit=" . $ENV{'PWD'} . "/hook:test\n"; + close $fh; + ok (-r 'hook.rc', 'Created hook.rc'); +} + +if (open my $fh, '>', 'hook') +{ + print $fh "function test () print ('<<' .. task_version () .. '>>') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +my $output = qx{../task rc:hook.rc version}; +if ($output =~ /PUC-Rio/) +{ + # Test the hook. + $output = qx{../task rc:hook.rc _version}; + like ($output, qr/^<<\d\.\d+\.\d+.*>>$/ms, 'Hook called task_version'); +} +else +{ + pass ('Hook called task_version - 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; +