mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - Hooks
- Implemented a few hooks. - Implemented several Lua API calls. - Unit tests for all hooks and API calls.
This commit is contained in:
parent
cb952329d3
commit
1a02cacc53
15 changed files with 990 additions and 60 deletions
173
src/API.cpp
173
src/API.cpp
|
@ -53,6 +53,7 @@
|
||||||
#include "API.h"
|
#include "API.h"
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
Task* the_task = NULL;
|
||||||
|
|
||||||
#ifdef HAVE_LIBLUA
|
#ifdef HAVE_LIBLUA
|
||||||
|
|
||||||
|
@ -120,7 +121,10 @@ static int api_task_feature (lua_State* L)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushnumber (L, value ? 1 : 0);
|
else if (name == "lua")
|
||||||
|
value = true;
|
||||||
|
|
||||||
|
lua_pushboolean (L, value ? 1 : 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +134,18 @@ static int api_task_aliases ()
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
-- Returns values from .taskrc, by name.
|
// Returns values from .taskrc, by name.
|
||||||
static int api_task_get_config (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.
|
-- Temporarily sets .taskrc values, by name.
|
||||||
static int api_task_set_config (name, value)
|
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.
|
-- 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)
|
static int api_task_modify (t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
-- 'id' is the task id passed to the hook function. Date attributes are
|
// -- 'id' is the task id passed to the hook function. Date attributes are
|
||||||
-- returned as a numeric epoch offset. Tags and annotations are returned
|
// -- returned as a numeric epoch offset. Tags and annotations are returned
|
||||||
-- as tables. A nil value indicates a missing value.
|
// -- as tables. A nil value indicates a missing value.
|
||||||
static int api_task_get_uuid (id)
|
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)
|
static int api_task_get_annotations (id)
|
||||||
{
|
{
|
||||||
return task.annotations
|
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)
|
static int api_task_get_tags (id)
|
||||||
{
|
{
|
||||||
return task.tags
|
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)
|
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_os); lua_setglobal (L, "task_os");
|
||||||
lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature");
|
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_aliases); lua_setglobal (L, "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_get_config); lua_setglobal (L, "task_get_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_set_config); lua_setglobal (L, "task_set_config");
|
||||||
lua_pushcfunction (L, api_task_get_command); lua_setglobal (L, "api_task_get_command");
|
lua_pushcfunction (L, api_task_i18n_string); lua_setglobal (L, "task_i18n_string");
|
||||||
lua_pushcfunction (L, api_task_get_header_messages); lua_setglobal (L, "api_task_get_header_messages");
|
lua_pushcfunction (L, api_task_i18n_tips); lua_setglobal (L, "task_i18n_tips");
|
||||||
lua_pushcfunction (L, api_task_get_footnote_messages); lua_setglobal (L, "api_task_get_footnote_messages");
|
lua_pushcfunction (L, api_task_get_command); lua_setglobal (L, "task_get_command");
|
||||||
lua_pushcfunction (L, api_task_get_debug_messages); lua_setglobal (L, "api_task_get_debug_messages");
|
lua_pushcfunction (L, api_task_get_header_messages); lua_setglobal (L, "task_get_header_messages");
|
||||||
lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "api_task_header_message");
|
lua_pushcfunction (L, api_task_get_footnote_messages); lua_setglobal (L, "task_get_footnote_messages");
|
||||||
lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "api_task_footnote_message");
|
lua_pushcfunction (L, api_task_get_debug_messages); lua_setglobal (L, "task_get_debug_messages");
|
||||||
lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "api_task_debug_message");
|
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_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_inhibit_further_hooks); lua_setglobal (L, "task_inhibit_further_hooks");
|
||||||
lua_pushcfunction (L, api_task_get); lua_setglobal (L, "api_task_get");
|
lua_pushcfunction (L, api_task_get); lua_setglobal (L, "task_get");
|
||||||
lua_pushcfunction (L, api_task_add); lua_setglobal (L, "api_task_add");
|
lua_pushcfunction (L, api_task_add); lua_setglobal (L, "task_add");
|
||||||
lua_pushcfunction (L, api_task_modify); lua_setglobal (L, "api_task_modify");
|
lua_pushcfunction (L, api_task_modify); lua_setglobal (L, "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_uuid); lua_setglobal (L, "task_get_uuid");
|
||||||
lua_pushcfunction (L, api_task_get_annotations); lua_setglobal (L, "api_task_get_annotations");
|
lua_pushcfunction (L, api_task_get_description); lua_setglobal (L, "task_get_description");
|
||||||
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_annotations); lua_setglobal (L, "task_get_annotations");
|
||||||
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_project); lua_setglobal (L, "task_get_project");
|
||||||
lua_pushcfunction (L, api_task_get_due); lua_setglobal (L, "api_task_get_due");
|
lua_pushcfunction (L, api_task_get_priority); lua_setglobal (L, "task_get_priority");
|
||||||
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_tags); lua_setglobal (L, "task_get_tags");
|
||||||
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_status); lua_setglobal (L, "task_get_status");
|
||||||
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_get_due); lua_setglobal (L, "task_get_due");
|
||||||
lua_pushcfunction (L, api_task_set_description); lua_setglobal (L, "api_task_set_description");
|
lua_pushcfunction (L, api_task_get_entry); lua_setglobal (L, "task_get_entry");
|
||||||
lua_pushcfunction (L, api_task_set_annotations); lua_setglobal (L, "api_task_set_annotations");
|
lua_pushcfunction (L, api_task_get_start); lua_setglobal (L, "task_get_start");
|
||||||
lua_pushcfunction (L, api_task_set_project); lua_setglobal (L, "api_task_set_project");
|
lua_pushcfunction (L, api_task_get_end); lua_setglobal (L, "task_get_end");
|
||||||
lua_pushcfunction (L, api_task_set_priority); lua_setglobal (L, "api_task_set_priority");
|
lua_pushcfunction (L, api_task_get_recur); lua_setglobal (L, "task_get_recur");
|
||||||
lua_pushcfunction (L, api_task_set_tags); lua_setglobal (L, "api_task_set_tags");
|
lua_pushcfunction (L, api_task_get_until); lua_setglobal (L, "task_get_until");
|
||||||
lua_pushcfunction (L, api_task_set_status); lua_setglobal (L, "api_task_set_status");
|
lua_pushcfunction (L, api_task_get_wait); lua_setglobal (L, "task_get_wait");
|
||||||
lua_pushcfunction (L, api_task_set_due); lua_setglobal (L, "api_task_set_due");
|
lua_pushcfunction (L, api_task_set_description); lua_setglobal (L, "task_set_description");
|
||||||
lua_pushcfunction (L, api_task_set_start); lua_setglobal (L, "api_task_set_start");
|
lua_pushcfunction (L, api_task_set_annotations); lua_setglobal (L, "task_set_annotations");
|
||||||
lua_pushcfunction (L, api_task_set_recur); lua_setglobal (L, "api_task_set_recur");
|
lua_pushcfunction (L, api_task_set_project); lua_setglobal (L, "task_set_project");
|
||||||
lua_pushcfunction (L, api_task_set_until); lua_setglobal (L, "api_task_set_until");
|
lua_pushcfunction (L, api_task_set_priority); lua_setglobal (L, "task_set_priority");
|
||||||
lua_pushcfunction (L, api_task_set_wait); lua_setglobal (L, "api_task_set_wait");
|
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.
|
// Prepare args.
|
||||||
lua_pushnumber (L, current.id);
|
lua_pushnumber (L, current.id);
|
||||||
|
|
||||||
|
// Expose the task.
|
||||||
|
the_task = ¤t;
|
||||||
|
|
||||||
// Make call.
|
// Make call.
|
||||||
if (lua_pcall (L, 1, 2, 0) != 0)
|
if (lua_pcall (L, 1, 2, 0) != 0)
|
||||||
throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1);
|
throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1);
|
||||||
|
|
||||||
|
// Hide the task.
|
||||||
|
the_task = NULL;
|
||||||
|
|
||||||
// Call successful - get return values.
|
// Call successful - get return values.
|
||||||
if (!lua_isnumber (L, -2))
|
if (!lua_isnumber (L, -2))
|
||||||
throw std::string ("Error: '") + function + "' did not return a success indicator";
|
throw std::string ("Error: '") + function + "' did not return a success indicator";
|
||||||
|
|
|
@ -1255,6 +1255,8 @@ int handleExport (std::string &outs)
|
||||||
|
|
||||||
foreach (task, tasks)
|
foreach (task, tasks)
|
||||||
{
|
{
|
||||||
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
|
||||||
if (task->getStatus () != Task::recurring)
|
if (task->getStatus () != Task::recurring)
|
||||||
{
|
{
|
||||||
out << task->composeCSV ().c_str ();
|
out << task->composeCSV ().c_str ();
|
||||||
|
|
|
@ -169,7 +169,10 @@ int runCustomReport (
|
||||||
table.setReportName (report);
|
table.setReportName (report);
|
||||||
|
|
||||||
foreach (task, tasks)
|
foreach (task, tasks)
|
||||||
|
{
|
||||||
table.addRow ();
|
table.addRow ();
|
||||||
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
}
|
||||||
|
|
||||||
int columnCount = 0;
|
int columnCount = 0;
|
||||||
int dueColumn = -1;
|
int dueColumn = -1;
|
||||||
|
|
|
@ -349,6 +349,9 @@ int handleInfo (std::string &outs)
|
||||||
table.setColumnJustification (1, Table::left);
|
table.setColumnJustification (1, Table::left);
|
||||||
Date now;
|
Date now;
|
||||||
|
|
||||||
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
|
||||||
|
// id
|
||||||
char svalue[12];
|
char svalue[12];
|
||||||
std::string value;
|
std::string value;
|
||||||
int row = table.addRow ();
|
int row = table.addRow ();
|
||||||
|
@ -360,14 +363,17 @@ int handleInfo (std::string &outs)
|
||||||
|
|
||||||
std::string status = ucFirst (Task::statusToText (task->getStatus ()));
|
std::string status = ucFirst (Task::statusToText (task->getStatus ()));
|
||||||
|
|
||||||
|
// description
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
table.addCell (row, 0, "Description");
|
table.addCell (row, 0, "Description");
|
||||||
table.addCell (row, 1, getFullDescription (*task, "info"));
|
table.addCell (row, 1, getFullDescription (*task, "info"));
|
||||||
|
|
||||||
|
// status
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
table.addCell (row, 0, "Status");
|
table.addCell (row, 0, "Status");
|
||||||
table.addCell (row, 1, status);
|
table.addCell (row, 1, status);
|
||||||
|
|
||||||
|
// project
|
||||||
if (task->has ("project"))
|
if (task->has ("project"))
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
|
@ -375,6 +381,7 @@ int handleInfo (std::string &outs)
|
||||||
table.addCell (row, 1, task->get ("project"));
|
table.addCell (row, 1, task->get ("project"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// priority
|
||||||
if (task->has ("priority"))
|
if (task->has ("priority"))
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
|
@ -387,6 +394,7 @@ int handleInfo (std::string &outs)
|
||||||
if (task->getStatus () == Task::recurring ||
|
if (task->getStatus () == Task::recurring ||
|
||||||
task->has ("parent"))
|
task->has ("parent"))
|
||||||
{
|
{
|
||||||
|
// recur
|
||||||
if (task->has ("recur"))
|
if (task->has ("recur"))
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
|
@ -394,6 +402,7 @@ int handleInfo (std::string &outs)
|
||||||
table.addCell (row, 1, task->get ("recur"));
|
table.addCell (row, 1, task->get ("recur"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// until
|
||||||
if (task->has ("until"))
|
if (task->has ("until"))
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
|
@ -408,6 +417,7 @@ int handleInfo (std::string &outs)
|
||||||
table.addCell (row, 1, until);
|
table.addCell (row, 1, until);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mask
|
||||||
if (task->has ("mask"))
|
if (task->has ("mask"))
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
|
@ -415,6 +425,7 @@ int handleInfo (std::string &outs)
|
||||||
table.addCell (row, 1, task->get ("mask"));
|
table.addCell (row, 1, task->get ("mask"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parent
|
||||||
if (task->has ("parent"))
|
if (task->has ("parent"))
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
|
@ -422,6 +433,7 @@ int handleInfo (std::string &outs)
|
||||||
table.addCell (row, 1, task->get ("parent"));
|
table.addCell (row, 1, task->get ("parent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// imask
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
table.addCell (row, 0, "Mask Index");
|
table.addCell (row, 0, "Mask Index");
|
||||||
table.addCell (row, 1, task->get ("imask"));
|
table.addCell (row, 1, task->get ("imask"));
|
||||||
|
@ -1255,6 +1267,8 @@ int handleReportTimesheet (std::string &outs)
|
||||||
// If task completed within range.
|
// If task completed within range.
|
||||||
if (task->getStatus () == Task::completed)
|
if (task->getStatus () == Task::completed)
|
||||||
{
|
{
|
||||||
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
|
||||||
Date compDate (atoi (task->get ("end").c_str ()));
|
Date compDate (atoi (task->get ("end").c_str ()));
|
||||||
if (compDate >= start && compDate < end)
|
if (compDate >= start && compDate < end)
|
||||||
{
|
{
|
||||||
|
@ -1314,6 +1328,8 @@ int handleReportTimesheet (std::string &outs)
|
||||||
if (task->getStatus () == Task::pending &&
|
if (task->getStatus () == Task::pending &&
|
||||||
task->has ("start"))
|
task->has ("start"))
|
||||||
{
|
{
|
||||||
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
|
||||||
Date startDate (atoi (task->get ("start").c_str ()));
|
Date startDate (atoi (task->get ("start").c_str ()));
|
||||||
if (startDate >= start && startDate < end)
|
if (startDate >= start && startDate < end)
|
||||||
{
|
{
|
||||||
|
|
76
src/tests/hook.api.task_exit.t
Executable file
76
src/tests/hook.api.task_exit.t
Executable file
|
@ -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;
|
||||||
|
|
86
src/tests/hook.api.task_feature.t
Executable file
86
src/tests/hook.api.task_feature.t
Executable file
|
@ -0,0 +1,86 @@
|
||||||
|
#! /usr/bin/perl
|
||||||
|
################################################################################
|
||||||
|
## task - a command line task list manager.
|
||||||
|
##
|
||||||
|
## Copyright 2006 - 2010, Paul Beckingham.
|
||||||
|
## All rights reserved.
|
||||||
|
##
|
||||||
|
## This program is free software; you can redistribute it and/or modify it under
|
||||||
|
## the terms of the GNU General Public License as published by the Free Software
|
||||||
|
## Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
## version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
## details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License along with
|
||||||
|
## this program; if not, write to the
|
||||||
|
##
|
||||||
|
## Free Software Foundation, Inc.,
|
||||||
|
## 51 Franklin Street, Fifth Floor,
|
||||||
|
## Boston, MA
|
||||||
|
## 02110-1301
|
||||||
|
## USA
|
||||||
|
##
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Test::More tests => 8;
|
||||||
|
|
||||||
|
# Create the rc file.
|
||||||
|
if (open my $fh, '>', 'hook.rc')
|
||||||
|
{
|
||||||
|
print $fh "data.location=.\n",
|
||||||
|
"hooks=on\n",
|
||||||
|
"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 ('<<lua>>')\n",
|
||||||
|
" end\n",
|
||||||
|
" if task_feature ('foo') then\n",
|
||||||
|
" print ('<<foo>>')\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/^<<lua>>$/ms, 'Hook called task_feature (lua)');
|
||||||
|
unlike ($output, qr/^<<foo>>$/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;
|
||||||
|
|
77
src/tests/hook.api.task_get_config.t
Executable file
77
src/tests/hook.api.task_get_config.t
Executable file
|
@ -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;
|
||||||
|
|
77
src/tests/hook.api.task_get_description.t
Executable file
77
src/tests/hook.api.task_get_description.t
Executable file
|
@ -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/^<<foo>>$/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;
|
||||||
|
|
77
src/tests/hook.api.task_get_priority.t
Executable file
77
src/tests/hook.api.task_get_priority.t
Executable file
|
@ -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/^<<M>>$/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;
|
||||||
|
|
77
src/tests/hook.api.task_get_project.t
Executable file
77
src/tests/hook.api.task_get_project.t
Executable file
|
@ -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/^<<PPP>>$/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;
|
||||||
|
|
77
src/tests/hook.api.task_get_status.t
Executable file
77
src/tests/hook.api.task_get_status.t
Executable file
|
@ -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/^<<pending>>$/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;
|
||||||
|
|
77
src/tests/hook.api.task_get_uuid.t
Executable file
77
src/tests/hook.api.task_get_uuid.t
Executable file
|
@ -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;
|
||||||
|
|
76
src/tests/hook.api.task_lua_version.t
Executable file
76
src/tests/hook.api.task_lua_version.t
Executable file
|
@ -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;
|
||||||
|
|
80
src/tests/hook.api.task_os.t
Executable file
80
src/tests/hook.api.task_os.t
Executable file
|
@ -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;
|
||||||
|
|
76
src/tests/hook.api.task_version.t
Executable file
76
src/tests/hook.api.task_version.t
Executable file
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue