Enhancement - Hooks

- Implemented a few hooks.
- Implemented several Lua API calls.
- Unit tests for all hooks and API calls.
This commit is contained in:
Paul Beckingham 2010-02-07 00:22:02 -05:00
parent cb952329d3
commit 1a02cacc53
15 changed files with 990 additions and 60 deletions

76
src/tests/hook.api.task_exit.t Executable file
View 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;

View file

@ -0,0 +1,86 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 8;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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
View 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;

View 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;