Cron-Sequencer
view release on metacpan or search on metacpan
#!perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Test::Fatal;
require_ok('Cron::Sequencer::Parser')
or BAIL_OUT('When Cron::Sequencer fails to even load, nothing is going to work');
# We assume that the tests for Algorithm::Cron sufficiently test its parser for
# time strings, so we concentrate on our code here (the env parser and the
# special strings)
my @fields = qw(min hour mday mon wday);
for ([hourly => { min => 0, }],
[daily => { min => 0, hour => 0 }],
[midnight => { min => 0, hour => 0 }],
[weekly => { min => 0, hour => 0, wday => 0 }],
[monthly => { min => 0, hour => 0, mday => 1 }],
[annually => { min => 0, hour => 0, mon => 0, mday => 1 }],
[yearly => { min => 0, hour => 0, mon => 0, mday => 1 }],
) {
my ($special, $expect) = @$_;
$special = '@' . $special;
my $have = Cron::Sequencer::Parser::_parser(\"$special woof!", "Bother!");
cmp_deeply($have, [{
file => "Bother!",
lineno => 1,
when => $special,
command => 'woof!',
whenever => isa('Algorithm::Cron'),
}], "Special string $special");
for my $field (@fields) {
my $whenever = $have->[0]->{whenever};
my $want = defined $expect->{$field} ? [$expect->{$field}] : [];
cmp_deeply([$whenever->$field], $want, "$special $field");
}
}
cmp_deeply(Cron::Sequencer::Parser::_parser(\'@reboot woof!', "Oops!"),
[], 'Special string @reboot is ignored');
like(exception {
Cron::Sequencer::Parser::_parser(\'@woof reboot!', "Oops!");
}, qr/^Unknown special string \@woof at line 1 of Oops!/,
'Special string @woof is unknown');
my $crontab = <<"EOT";
# This is a comment
# This too
#IS=Comment
#STILL=Comment
0 1 2 3 4 woof!
FOO=BAR
1 2 3 4 5 woof!\t
FOO=BAZ
( run in 1.087 second using v1.01-cache-2.11-cpan-54e63673c56 )