File Coverage

blib/lib/Test/App/RunCron.pm
Criterion Covered Total %
statement 53 55 96.3
branch 5 6 83.3
condition 4 8 50.0
subroutine 14 15 93.3
pod 2 2 100.0
total 78 86 90.7


line stmt bran cond sub pod time code
1             package Test::App::RunCron;
2 3     3   53180 use strict;
  3         4  
  3         105  
3 3     3   11 use warnings;
  3         3  
  3         71  
4 3     3   16 use utf8;
  3         4  
  3         15  
5              
6 3     3   1088 use App::RunCron;
  3         7  
  3         83  
7 3     3   16 use Test::More ();
  3         3  
  3         36  
8 3     3   1413 use Test::Mock::Guard ();
  3         72460  
  3         66  
9 3     3   1568 use YAML::Tiny;
  3         13260  
  3         176  
10              
11 3     3   17 use parent 'Exporter';
  3         4  
  3         20  
12              
13             our @EXPORT = qw/runcron_yml_ok mock_runcron/;
14              
15             sub runcron_yml_ok {
16 4   50 4 1 5193 my $yml = shift || 'runcron.yml';
17 4   33     21 my $description = shift || "test of $yml";
18              
19 4         6 eval {
20 4         18 my $conf = YAML::Tiny::LoadFile($yml);
21 3         26633 my $obj = App::RunCron->new($conf);
22              
23 3         37 my @reporters;
24              
25 3         9 for my $reporter_kind (qw/reporter error_reporter common_reporter/) {
26 9 100       74 push @reporters, App::RunCron::_retrieve_plugins($conf->{$reporter_kind}) if $conf->{$reporter_kind};
27             }
28              
29 3         6 for my $r (@reporters) {
30 5         29 my ($class, $arg) = @$r;
31 5   66     15 App::RunCron::_load_class_with_prefix($class, 'App::RunCron::Reporter')->new($arg || ());
32             }
33             };
34 4         501 my $err = $@;
35 4         40 my $BUILDER = Test::More->builder;
36 4 100       42 if ($err) {
37 2         13 $BUILDER->ok(0, $description);
38 2         223 $BUILDER->diag($err);
39             }
40             else {
41 2         18 $BUILDER->ok(1, $description);
42             }
43             }
44              
45             sub mock_runcron {
46 2 50   2 1 2879 my %args = @_ == 1 ? %{$_[0]} : @_;
  0         0  
47              
48 2         6 my %mock;
49 2         6 for my $key (keys %args) {
50 2     2   9 $mock{$key} = sub { $args{$key} };
  2         365  
51             }
52             my $guard = Test::Mock::Guard->new('App::RunCron' => {
53 1     1   459 run => sub { die "can't run mock object" },
54 0     0   0 command => sub { [qw/dummy/] },
55 1     1   325 report => sub { 'mock report' },
56 1     1   9 exit_code => sub { 0 },
57 2         35 %mock,
58             });
59 2         478 my $mock = App::RunCron->new;
60 2         29 $mock->{_guard} = $guard;
61 2         7 $mock;
62             }
63              
64             1;
65             __END__