From ac099143cc2fa718d20daaaef2820b96624bd572 Mon Sep 17 00:00:00 2001 From: herrmannj <> Date: Wed, 23 Aug 2023 10:58:50 +0000 Subject: [PATCH] Cron.pm: wip git-svn-id: https://svn.fhem.de/fhem/trunk@27882 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/t/FHEM/90_Cron/10_Cronlib.t | 26 ++++++++++++++++---------- fhem/t/FHEM/90_Cron/99_Cronlib_DEBUG.t | 11 +++++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/fhem/t/FHEM/90_Cron/10_Cronlib.t b/fhem/t/FHEM/90_Cron/10_Cronlib.t index ded9809c5..2e1f3ad9c 100644 --- a/fhem/t/FHEM/90_Cron/10_Cronlib.t +++ b/fhem/t/FHEM/90_Cron/10_Cronlib.t @@ -22,11 +22,11 @@ my $test = [ # [q(RULE4 logic '$cron_text'), '* * * * 1,&2', 0, 0, qr(^$)], # [q(validate date '$cron_text'), '* * 30 2 *', 0, 0, qr(^$)], -# # positive tests for minute - [q(accept '$cron_text'), '* * * * *', qr(^$), 20230101000000, 20230101000100], - [q(accept '$cron_text'), '1 * * * *', qr(^$), 20230101000000, 20230101000100], -# [q(accept '$cron_text'), '1-5 * * * *', 0, 0, qr(^$)], -# [q(accept '$cron_text'), '1-5/1 * * * *', 0, 0, qr(^$)], + # positive tests for minute + [q(handle '$cron_text'), '1 * * * *', qr(^$), sub {my @r = (20230101000000); for my $h (0..23) {for my $m (1) {push @r, sprintf('20230101%02d%02d00', $h, $m)}}; @r}->()], + [q(handle '$cron_text'), '1-5 * * * *', qr(^$), sub {my @r = (20230101000000); for my $h (0..23) {for my $m (1..5) {push @r, sprintf('20230101%02d%02d00', $h, $m)}}; @r}->()], + [q(handle '$cron_text'), '1-5/1 * * * *', qr(^$), sub {my @r = (20230101000000); for my $h (0..23) {for my $m (1..5) {push @r, sprintf('20230101%02d%02d00', $h, $m)}}; @r}->()], + [q(handle '$cron_text'), '1-5/2 * * * *', qr(^$), sub {my @r = (20230101000000); for my $h (0..23) {for my $m (1,3,5) {push @r, sprintf('20230101%02d%02d00', $h, $m)}}; @r}->()], # [q(accept '$cron_text'), '*/1 * * * *', 0, 0, qr(^$)], # # positive tests for minute / value range # [q(accept '$cron_text'), '0 * * * *', 0, join (',', ((20200101120000 .. 20200101120059 ), (20200101120100 .. 20200101120159 ))), qr(^$)], @@ -51,27 +51,33 @@ my $test = [ # [q(must throw an error '$cron_text'), '0-59/60 * * * *', 0, 0, qr(^syntax error in minute item:)], # [q(must throw an error '$cron_text'), '20~10 * * * *', 0, 0, qr(^syntax error in minute item:)], # # negative tests for minute / value range + + # time series + [q(Timeseries '$cron_text'), '0 12 3,4,5 2 0,2,3,4', qr(^$), 20230102150000, 20230201120000, 20230202120000, 20230203120000, 20230204120000], + [q(Feb-29 & Sunday '$cron_text'), '0 12 29 2 &7', qr(^$), 20230102150000, 20320229120000], ]; # print join ",", (20200101120000 .. 20200101120010 ), (20200101120100 .. 20200101120110 ); # print "\n"; -# my $cron_lib_loadable = eval{use FHEM::Scheduler::Cron;1;}; -# ok($cron_lib_loadable, "FHEM::Scheduler::Cron loaded"); +my $cron_lib_loadable = eval{use FHEM::Scheduler::Cron;1;}; +ok($cron_lib_loadable, "FHEM::Scheduler::Cron loaded"); -foreach my $test (@$test) { - my ($desc, $cron_text, $err_expected, @series) = @$test; +foreach my $t (@$test) { + my ($desc, $cron_text, $err_expected, @series) = @$t; my ($cron_obj, $err) = FHEM::Scheduler::Cron->new($cron_text); my $ok = 1; + my $count = 0; for my $iter (0 .. $#series -1) { # next unless ($series[$iter]); my $got = $cron_obj->next($series[$iter]); + $count++; $ok = 0 if ($got ne $series[$iter +1]); say sprintf('%s -> expected: %s, got: %s', ($got ne $series[$iter +1])?'not ok':'ok', $series[$iter +1], $got) if $ENV{EXTENDED_DEBUG}; } $ok &&= ($err // '' =~ /$err_expected/); - ok($ok, sprintf('%s %s', eval qq{"$desc"} , $err?"(got '$err')":'')); + ok($ok, sprintf('%s %s', eval qq{"$desc"} , $err?"(got '$err')":"(# of passes: $count)")); }; done_testing; diff --git a/fhem/t/FHEM/90_Cron/99_Cronlib_DEBUG.t b/fhem/t/FHEM/90_Cron/99_Cronlib_DEBUG.t index 4f0b634f2..afa95090e 100644 --- a/fhem/t/FHEM/90_Cron/99_Cronlib_DEBUG.t +++ b/fhem/t/FHEM/90_Cron/99_Cronlib_DEBUG.t @@ -13,22 +13,25 @@ $ENV{EXTENDED_DEBUG} = 1; my $test = [ #[q(Timeseries '$cron_text'), '0 12 3,4,5 2 0,2,3,4', qr(^$), 20230102150000, 20230201120000, 20230202120000, 20230203120000, 20230204120000], - [q(Timeseries '$cron_text'), '0 12 29 2 &7', qr(^$), 20230102150000, 20320229120000], + #[q(Feb-29 & Sunday '$cron_text'), '0 12 29 2 &7', qr(^$), 20230102150000, 20320229120000, sub {20600229120000}->()], + [q(accept '$cron_text'), '1-5 * * * *', qr(^$), sub {my @r = (20230101000000); for my $h (0..23) {for my $m (1..5) {push @r, sprintf('20230101%02d%02d00', $h, $m)}}; @r}->()], ]; -foreach my $test (@$test) { - my ($desc, $cron_text, $err_expected, @series) = @$test; +foreach my $t (@$test) { + my ($desc, $cron_text, $err_expected, @series) = @$t; my ($cron_obj, $err) = FHEM::Scheduler::Cron->new($cron_text); my $ok = 1; + my $count = 0; for my $iter (0 .. $#series -1) { # next unless ($series[$iter]); my $got = $cron_obj->next($series[$iter]); + $count++; $ok = 0 if ($got ne $series[$iter +1]); say sprintf('%s -> expected: %s, got: %s', ($got ne $series[$iter +1])?'not ok':'ok', $series[$iter +1], $got) if $ENV{EXTENDED_DEBUG}; } $ok &&= ($err // '' =~ /$err_expected/); - ok($ok, sprintf('%s %s', eval qq{"$desc"} , $err?"(got '$err')":'')); + ok($ok, sprintf('%s %s', eval qq{"$desc"} , $err?"(got '$err')":"(# of passes: $count)")); }; done_testing;