blib/lib/Test/Crontab/Format.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 12 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 97.3% 72 / 74 CC 8 SCAR 15.5
CC
8
Cov
98%
crontab_format_ok
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
↑ Summary
1 package Test::Crontab::Format;
2  
3 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Parse::Crontab 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Check crontab format validity
12  
13 3 our $VERSION = "0.02";
14  
15 3 our @EXPORT = qw(
16 crontab_format_ok
17 );
18  
19 3 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
20 3 my $self = shift;
21 3 my $pack = caller;
22  
23 3 my $test = Test::Builder->new;
24  
25 3 $test->exported_to( $pack );
26 3 $test->plan( @_ );
27  
28 3 $self->export_to_level( 1, $self, @EXPORT );
29 }
30  
31 8 ▶sub crontab_format_ok {
Subroutine crontab_format_ok: called CC=8 SCAR=20.8
Pod documented
32 8 my ($thingy) = @_;
33  
34 8 my $test = Test::Builder->new;
35  
36 8 ▶ if( ref $thingy eq 'SCALAR' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thingy eq 'SCALAR') { } 3 5 8
37 3 ▶ if( length ${ $thingy } == 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if (length ${$thingy;} == 0) { } 1 2 3
38 1 $test->ok( 0, "scalar content" );
39 1 $test->diag("content is empty");
40 }
41 else{
42 2 my $crontab = Parse::Crontab->new( content => ${ $thingy }, verbose => 0 );
43 2 ▶ if( $crontab->is_valid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($crontab->is_valid) { } 1 1 2
44 1 $test->ok( 1, "crontab format: scalar content" );
45 }
46 else{
47 1 $test->ok( 0, "scalar content" );
48 # $test->diag( $crontab->error_messages );
49 }
50 }
51 }
52 else{
53 5 my $file = $thingy;
54 5 ▶ if( not -f $file or not -r $file ){
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $file && -r $file) { } 2 3 5
elsif (-z $file) { } 1 2 3
Condition66%2/3
-f $file && -r $file
!ll&&!rl&&r
203
MC/DC50%1/2
-f $file && -r $file
-f $file -r $file
Truth table66%2/3
A && B
A= -f $fileB= -r $file
ABresult
0X0
100
111
55 2 $test->ok( 0, $file );
56 2 $test->diag( sprintf "file '%s' not readable", $file );
57 }
58 elsif( -z $file ){
59 1 $test->ok( 0, $file );
60 1 $test->diag( sprintf "file '%s' is empty", $file );
61 }
62 else{
63 2 my $crontab = Parse::Crontab->new( file => $file, verbose => 0 );
64 2 ▶ if( $crontab->is_valid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($crontab->is_valid) { } 1 1 2
65 1 $test->ok( 1, sprintf "crontab format: %s", $file );
66 }
67 else{
68 1 $test->ok( 0, $file );
69 # $test->diag( $crontab->error_messages );
70 }
71 }
72 }
73 }
74  
75 3 1;
76  
77 __END__
↑ Summary