| 1 | package App::Duppy; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: a wrapper around casperjs to pass test configurations as json files | ||||||||||||||||||||||||||||
| 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 Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use MooX::Options; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use IPC::Run qw/run new_chunker/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Which; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use IO::All; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use DDP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | option 'test' => ( | |||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||||||
| 19 | format => 's@', | ||||||||||||||||||||||||||||
| 20 | doc => | ||||||||||||||||||||||||||||
| 21 | 'Test option: one ore more json file(s) containing the casperjs tests to perform' | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | option 'casper_path' => ( | |||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | format => 's', | ||||||||||||||||||||||||||||
| 27 | doc => 'Path to casperjs, if not standard', | ||||||||||||||||||||||||||||
| 28 | predicate => 'has_casper_path', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | has 'tests' => ( is => 'lazy', ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | has 'buffer_return' => ( is => 'rw', default => sub {''}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | has 'silent_run' => (is => 'rw', default => sub { 0 }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _build_tests { | ||||||||||||||||||||||||||
|
Subroutine
_build_tests: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 0 | my $ret = {}; | |||||||||||||||||||||||||||
| 40 | 0 | foreach my $file ( @{ $self->test } ) { | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( io($file)->exists ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | my $content = io($file)->slurp; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 0 | $ret->{$file} = decode_json($content); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | 0 | carp "'$file' is not valid: $_"; | |||||||||||||||||||||||||||
| 48 | 0 | }; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||
| 51 | 0 | carp "'$file' does not exist"; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | return $ret; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub run_casper { | ||||||||||||||||||||||||||
|
Subroutine
run_casper: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | 0 | my $full_path; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self->buffer_return('') if ($self->buffer_return); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $self->has_casper_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( -f $self->casper_path and -x $self->casper_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $self->casper_path and -x $self->casper_path
MC/DC0%0/2
-f $self->casper_path and -x $self->casper_path
-f $self->casper_path
-x $self->casper_path
Truth table0%0/3
A and B
A= -f $self->casper_pathB= -x $self->casper_path
| |||||||||||||||||||||||||||||
| 63 | 0 | $full_path = $self->casper_path; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||
| 66 | 0 | croak sprintf( | |||||||||||||||||||||||||||
| 67 | q{'%s' is not an executable file}, | ||||||||||||||||||||||||||||
| 68 | $self->casper_path | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | $full_path = which('casperjs'); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | $self->silent_run (shift @_); | |||||||||||||||||||||||||||
| 76 | 0 | foreach my $test ( keys %{ $self->tests } ) { | |||||||||||||||||||||||||||
| 77 | 0 | my $param_spec = $self->transform_arg_spec( $self->tests->{$test} ); | |||||||||||||||||||||||||||
| 78 | 0 | unshift @{ $param_spec->{cmd} }, $full_path; | |||||||||||||||||||||||||||
| 79 | 0 | push @{ $param_spec->{cmd} }, "test", @{ $param_spec->{paths} }; | |||||||||||||||||||||||||||
| 80 | 0 | print "\n\n\n"; | |||||||||||||||||||||||||||
| 81 | 0 | print "="x10; | |||||||||||||||||||||||||||
| 82 | 0 | print "> Running test from file $test... \n\n\n"; | |||||||||||||||||||||||||||
| 83 | 0 | run $param_spec->{cmd}, '>', new_chunker("\n"),$self->lines_handler; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($self->silent_run) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | return $self->buffer_return; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub lines_handler { | ||||||||||||||||||||||||||
|
Subroutine
lines_handler: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 0 | my ($self,$in_ref,$out_ref) = @_; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 97 | 0 | my ($out) = @_; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($out) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($self->silent_run) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $self->buffer_return($self->buffer_return.$out); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||
| 103 | 0 | print $out; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | } | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub transform_arg_spec { | ||||||||||||||||||||||||||
|
Subroutine
transform_arg_spec: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 111 | 0 | my $ref_params = shift; | |||||||||||||||||||||||||||
| 112 | 0 | my $ret = {}; | |||||||||||||||||||||||||||
| 113 | 0 | my %params = %{$ref_params}; | |||||||||||||||||||||||||||
| 114 | 0 | $ret->{paths} = delete $params{paths}; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | while ( my ( $k, $v ) = each %params ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( ref($v) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | $v = join( ',', @{$v} ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $v = "true" if ( $v eq '1' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $v = "false" if ( $v eq '0' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | push @{ $ret->{cmd} }, "--$k=$v"; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | return $ret; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 3 | 1; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||