| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Csistck::Test::Script; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 17 |  |  | 17 |  | 388 | use 5.010; | 
|  | 17 |  |  |  |  | 59 |  | 
|  | 17 |  |  |  |  | 678 |  | 
| 4 | 17 |  |  | 17 |  | 143 | use strict; | 
|  | 17 |  |  |  |  | 38 |  | 
|  | 17 |  |  |  |  | 577 |  | 
| 5 | 17 |  |  | 17 |  | 89 | use warnings; | 
|  | 17 |  |  |  |  | 30 |  | 
|  | 17 |  |  |  |  | 675 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 17 |  |  | 17 |  | 91 | use base 'Csistck::Test'; | 
|  | 17 |  |  |  |  | 32 |  | 
|  | 17 |  |  |  |  | 1540 |  | 
| 8 | 17 |  |  | 17 |  | 99 | use Csistck::Oper qw/debug/; | 
|  | 17 |  |  |  |  | 34 |  | 
|  | 17 |  |  |  |  | 1057 |  | 
| 9 | 17 |  |  | 17 |  | 93 | use Csistck::Config qw/option/; | 
|  | 17 |  |  |  |  | 34 |  | 
|  | 17 |  |  |  |  | 1126 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our @EXPORT_OK = qw/script/; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 17 |  |  | 17 |  | 102 | use Digest::MD5; | 
|  | 17 |  |  |  |  | 30 |  | 
|  | 17 |  |  |  |  | 583 |  | 
| 14 | 17 |  |  | 17 |  | 87 | use File::Basename; | 
|  | 17 |  |  |  |  | 29 |  | 
|  | 17 |  |  |  |  | 1100 |  | 
| 15 | 17 |  |  | 17 |  | 179 | use FindBin; | 
|  | 17 |  |  |  |  | 45 |  | 
|  | 17 |  |  |  |  | 699 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 17 |  |  | 17 |  | 99 | use constant MODE_CHECK => 'check'; | 
|  | 17 |  |  |  |  | 41 |  | 
|  | 17 |  |  |  |  | 1669 |  | 
| 18 | 17 |  |  | 17 |  | 107 | use constant MODE_REPAIR => 'run'; | 
|  | 17 |  |  |  |  | 31 |  | 
|  | 17 |  |  |  |  | 9389 |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Use the convenience function to normalize args | 
| 21 |  |  |  |  |  |  | sub script { | 
| 22 | 3 |  |  | 3 | 1 | 926 | my $script = shift; | 
| 23 | 3 |  | 100 |  |  | 26 | my $script_args = shift // []; | 
| 24 | 3 | 50 |  |  |  | 58 | my %args = ( | 
| 25 |  |  |  |  |  |  | args => (ref $script_args eq 'ARRAY') ? | 
| 26 |  |  |  |  |  |  | $script_args : | 
| 27 |  |  |  |  |  |  | [$script_args], | 
| 28 |  |  |  |  |  |  | @_ | 
| 29 |  |  |  |  |  |  | ); | 
| 30 | 3 |  |  |  |  | 50 | Csistck::Test::Script->new($script, %args); | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 20 |  |  | 20 | 0 | 390 | sub script_name { shift->{target}; } | 
| 34 | 8 |  |  | 8 | 0 | 24 | sub args { shift->{args}; } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # Wrap common process function | 
| 37 | 12 |  |  | 12 | 0 | 64 | sub desc { return sprintf("Script test for %s", shift->script_name); } | 
| 38 | 6 |  |  | 6 | 0 | 681 | sub check { shift->process(MODE_CHECK); } | 
| 39 | 2 |  |  | 2 | 0 | 15 | sub repair { shift->process(MODE_REPAIR); } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub process { | 
| 42 | 8 |  |  | 8 | 0 | 19 | my $self = shift; | 
| 43 | 8 |  |  |  |  | 24 | my $mode = shift; | 
| 44 | 8 |  |  |  |  | 20 | my $script = $self->script_name; | 
| 45 |  |  |  |  |  |  | # Args was passed as arrayref | 
| 46 | 8 |  |  |  |  | 16 | my @args = @{$self->args}; | 
|  | 8 |  |  |  |  | 45 |  | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | # TODO sanity check on script | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # Build command | 
| 51 | 8 |  |  |  |  | 26 | my @command = ($script, $mode, @args); | 
| 52 | 8 |  |  |  |  | 105 | debug(sprintf("Run command: cmd=<%s>", join(" ", @command))); | 
| 53 | 8 |  |  |  |  | 282 | chdir($FindBin::Bin); | 
| 54 | 8 |  |  |  |  | 58988 | my $ret = system(@command); | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 8 | 100 |  |  |  | 541 | return (($ret == 0) ? $self->pass('Command passed') : | 
| 57 |  |  |  |  |  |  | $self->fail('Command failed')); | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | 1; | 
| 61 |  |  |  |  |  |  | __END__ |