Enhancement - Hooks

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

View File

@@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-countdown=" . $ENV{'PWD'} . "/hook:countdown\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function countdown (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo due:eom};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<(?:- )?\d+.+>/, 'format-countdown hook countdown -> <countdown>');
}
else
{
pass ('format-countdown hook countdown -> <countdown> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View File

@@ -0,0 +1,83 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"report.long.columns=id,project,priority,entry,start_time,due,",
"recur,countdown_compact,age,tags,description\n",
"hooks=on\n",
"hook.format-countdown_compact=" . $ENV{'PWD'} . "/hook:countdown_compact\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function countdown_compact (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo due:eom};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<(?:- )?\d+.+>/, 'format-countdown_compact hook countdown_compact -> <countdown_compact>');
}
else
{
pass ('format-countdown_compact hook countdown_compact -> <countdown_compact> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

81
src/tests/hook.format-due.t Executable file
View File

@@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-due=" . $ENV{'PWD'} . "/hook:due\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function due (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo due:tomorrow};
$output = qx{../task rc:hook.rc list};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-due hook due -> <due>');
}
else
{
pass ('format-due hook due -> <due> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

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

@@ -0,0 +1,82 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-end=" . $ENV{'PWD'} . "/hook:xend\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function xend (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
qx{../task rc:hook.rc do 1};
$output = qx{../task rc:hook.rc completed};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-end hook end -> <end>');
}
else
{
pass ('format-end hook end -> <end> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View File

@@ -0,0 +1,84 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"report.completed.columns=end_time,project,priority,age,description\n",
"report.completed.sort=end_time+,priority-,project+\n",
"hooks=on\n",
"hook.format-end_time=" . $ENV{'PWD'} . "/hook:end_time\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function end_time (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
qx{../task rc:hook.rc do 1};
$output = qx{../task rc:hook.rc completed};
like ($output, qr/<\d+\/\d+\/\d+\s\d+:\d+:\d+>/, 'format-end_time hook end_time -> <end_time>');
}
else
{
pass ('format-end_time hook end_time -> <end_time> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

81
src/tests/hook.format-entry.t Executable file
View File

@@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-entry=" . $ENV{'PWD'} . "/hook:entry\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function entry (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-entry hook entry -> <entry>');
}
else
{
pass ('format-entry hook entry -> <entry> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View File

@@ -0,0 +1,82 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"report.long.columns=id,project,priority,entry_time,start,due,recur,countdown,age,tags,description\n",
"hooks=on\n",
"hook.format-entry_time=" . $ENV{'PWD'} . "/hook:entry_time\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function entry_time (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<\d+\/\d+\/\d+\s\d+:\d+:\d+>/, 'format-entry_time hook entry_time -> <entry_time>');
}
else
{
pass ('format-entry_time hook entry_time -> <entry_time> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

81
src/tests/hook.format-prompt.t Executable file
View File

@@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"shell.prompt=foo\n",
"default.command=_version\n",
"hooks=on\n",
"hook.format-prompt=" . $ENV{'PWD'} . "/hook:prompt\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function prompt (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
my $output = qx{echo "\\nquit\\n" | ../task rc:hook.rc shell};
like ($output, qr/<foo>/, 'format-prompt hook prompt -> <prompt>');
}
else
{
pass ('format-prompt hook prompt -> <prompt> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

81
src/tests/hook.format-recur.t Executable file
View File

@@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-recur=" . $ENV{'PWD'} . "/hook:recur\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function recur (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo due:tomorrow recur:weekly};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<weekly>/, 'format-recur hook recur -> <recur>');
}
else
{
pass ('format-recur hook recur -> <recur> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

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

@@ -0,0 +1,82 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-start=" . $ENV{'PWD'} . "/hook:start\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function start (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
qx{../task rc:hook.rc start 1};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-start hook start -> <start>');
}
else
{
pass ('format-start hook start -> <start> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

View File

@@ -0,0 +1,83 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"report.long.columns=id,project,priority,entry,start_time,due,recur,countdown,age,tags,description\n",
"hooks=on\n",
"hook.format-start_time=" . $ENV{'PWD'} . "/hook:start_time\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function start_time (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo};
qx{../task rc:hook.rc start 1};
$output = qx{../task rc:hook.rc long};
like ($output, qr/<\d+\/\d+\/\d+\s\d+:\d+:\d+>/, 'format-start_time hook start_time -> <start_time>');
}
else
{
pass ('format-start_time hook start_time -> <start_time> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;

81
src/tests/hook.format-wait.t Executable file
View File

@@ -0,0 +1,81 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 7;
# Create the rc file.
if (open my $fh, '>', 'hook.rc')
{
print $fh "data.location=.\n",
"hooks=on\n",
"hook.format-wait=" . $ENV{'PWD'} . "/hook:wait\n";
close $fh;
ok (-r 'hook.rc', 'Created hook.rc');
}
# Create the hook functions.
if (open my $fh, '>', 'hook')
{
print $fh "function wait (name, value)\n",
" value = '<' .. value .. '>'\n",
" return value, 0, nil\n",
"end\n";
close $fh;
ok (-r 'hook', 'Created hook');
}
my $output = qx{../task rc:hook.rc version};
if ($output =~ /PUC-Rio/)
{
qx{../task rc:hook.rc add foo wait:tomorrow};
$output = qx{../task rc:hook.rc waiting};
like ($output, qr/<\d+\/\d+\/\d+>/, 'format-wait hook wait -> <wait>');
}
else
{
pass ('format-wait hook wait -> <wait> - skip: no Lua support');
}
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'hook';
ok (!-r 'hook', 'Removed hook');
unlink 'hook.rc';
ok (!-r 'hook.rc', 'Removed hook.rc');
exit 0;