| 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
| |||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | if( length ${ $thingy } == 0 ){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
-f $file && -r $file
MC/DC50%1/2
-f $file && -r $file
-f $file
-r $file
Truth table66%2/3
A && B
A= -f $fileB= -r $file
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||