diff --git a/src/tests/hook.post-start.t b/src/tests/hook.post-start.t new file mode 100755 index 000000000..a9e83f0ee --- /dev/null +++ b/src/tests/hook.post-start.t @@ -0,0 +1,67 @@ +#! /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", + "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 ('marker') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +# Test the hook. +my $output = qx{../task rc:hook.rc _version}; +like ($output, qr/^marker.+\n\d\.\d+\.\d+\n$/ms, 'Found marker before output'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'hook'; +ok (!-r 'hook', 'Removed hook'); + +unlink 'hook.rc'; +ok (!-r 'hook.rc', 'Removed hook.rc'); + +exit 0; + diff --git a/src/tests/hook.pre-exit.t b/src/tests/hook.pre-exit.t new file mode 100755 index 000000000..9093a9719 --- /dev/null +++ b/src/tests/hook.pre-exit.t @@ -0,0 +1,67 @@ +#! /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", + "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 ('marker') return 0, nil end\n"; + close $fh; + ok (-r 'hook', 'Created hook'); +} + +# Test the hook. +my $output = qx{../task rc:hook.rc _version}; +like ($output, qr/\n\d\.\d+\.\d+\nmarker\n$/ms, 'Found marker after output'); + +# 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; +