| 1 | package Test2::Tools::Process; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Test2::Tools::Compare (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Test2::API qw( context ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Ref::Util qw( is_plain_arrayref is_ref is_plain_coderef is_plain_hashref ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Carp qw( croak carp ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Test2::Compare::Array (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Test2::Compare::Wildcard (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Test2::Compare::Number (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Test2::Compare::String (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Test2::Compare::Custom (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use Test2::Compare (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use Return::MultiLevel qw( with_return ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use Capture::Tiny qw( capture_stdout ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | our @EXPORT = qw( process proc_event named_signal intercept_exit intercept_exec ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | our @CARP_NOT = qw( Test2::Tools::Process::SystemProc ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # ABSTRACT: Unit tests for code that calls exit, exec, system or qx() | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | our $VERSION = '0.07'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | our %handlers; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | %handlers = ( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | exit => sub (;$) { CORE::exit(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | exec => sub { CORE::exec(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | system => sub { CORE::system(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | readpipe => sub (_) { CORE::readpipe(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | *CORE::GLOBAL::exit = sub (;$) { $handlers{exit}->(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | *CORE::GLOBAL::exec = sub { $handlers{exec}->(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | *CORE::GLOBAL::system = sub { $handlers{system}->(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | *CORE::GLOBAL::readpipe = sub (_) { $handlers{readpipe}->(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | sub process (&;@) | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 33 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=3 SCAR=11.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 33 | my $sub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 33 | my @expected = (); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 33 | my $test_name = 'process ok'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 33 | my @events; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 33 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 33 | ▶ | if(is_plain_arrayref $_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 31 | @expected = @{ shift() }; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 33 | ▶ | $test_name = shift if defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 33 | ▶ | with_return { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 33 | my($return) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 33 | local %handlers = %handlers; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | ▶ | $handlers{exit} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | my $expected = $expected[$i++]; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | my $status = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | ▶ | $status = 0 unless defined $status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 | $status = int($status); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | push @events, { event_type => 'exit', exit_status => $status }; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | if(defined $expected && $expected->is_exit && defined $expected->callback) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $expected and $expected->is_exit and defined $expected->callback
defined $expected and $expected->is_exit
MC/DC33%1/3
defined $expected and $expected->is_exit and defined $expected->callback
defined $expected
$expected->is_exit
defined $expected->callback
Truth table50%2/4
A and B and C
A= defined $expectedB= $expected->is_exitC= defined $expected->callback
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | my $proc = Test2::Tools::Process::Proc->new($return); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my $ret = $expected->callback->($proc, $status); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | if(exists $proc->{errno}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $! = $proc->{errno}; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | else | ||||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | $return->(); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 33 | }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 13 | ▶ | $handlers{exec} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 13 | my $expected = $expected[$i++]; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 13 | ▶ | if(@_ == 1 || @_ == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 or @_ == 0
MC/DC100%2/2
@_ == 1 or @_ == 0
@_ == 1
@_ == 0
Truth table100%3/3
A or B
A= @_ == 1B= @_ == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | push @events, { event_type => 'exec', command => $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | push @events, { event_type => 'exec', command => [@_] }; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | ▶ | if(defined $expected && $expected->is_exec && defined $expected->callback) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $expected and $expected->is_exec and defined $expected->callback
defined $expected and $expected->is_exec
MC/DC33%1/3
defined $expected and $expected->is_exec and defined $expected->callback
defined $expected
$expected->is_exec
defined $expected->callback
Truth table50%2/4
A and B and C
A= defined $expectedB= $expected->is_execC= defined $expected->callback
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my $proc = Test2::Tools::Process::Proc->new($return); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my $ret = $expected->callback->($proc, @_); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | if(exists $proc->{errno}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $! = $proc->{errno}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | else | ||||||||||||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | $return->(); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 33 | }; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 33 | foreach my $type (qw( system readpipe )) | |||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 17 | ▶ | $handlers{$type} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=29.3
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 17 | my $expected = $expected[$i++]; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 17 | my $event; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 17 | my $args = \@_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 17 | ▶ | if(@_ == 1 || @_ == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 or @_ == 0
MC/DC100%2/2
@_ == 1 or @_ == 0
@_ == 1
@_ == 0
Truth table100%3/3
A or B
A= @_ == 1B= @_ == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | push @events, $event = { event_type => 'system', command => $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | else | ||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | push @events, $event = { event_type => 'system', command => [@_] }; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 17 | ▶ | if(defined $expected && $expected->is_system && defined $expected->callback) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $expected and $expected->is_system and defined $expected->callback
defined $expected and $expected->is_system
MC/DC0%0/3
defined $expected and $expected->is_system and defined $expected->callback
defined $expected
$expected->is_system
defined $expected->callback
Truth table25%1/4
A and B and C
A= defined $expectedB= $expected->is_systemC= defined $expected->callback
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 17 | ▶ | my $inner = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 17 | my($return) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 17 | my $proc = Test2::Tools::Process::SystemProc->new($return, $event, $type); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 17 | $expected->callback->($proc, @$args); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | $event->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | $? = 0; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 17 | }; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 17 | ▶ | if($type eq 'system') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | ▶ | with_return { $inner->(@_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | ▶ | return -1 if exists $event->{errno}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | return $?; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | else | ||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | return scalar capture_stdout { with_return { $inner->(@_) } }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | else | ||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my($message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $message =~ s/ at .*? line [0-9]+\.$//; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | chomp $message; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | carp($message); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $ret = $type eq 'system' ? CORE::system(@_) : CORE::readpipe(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if($? == -1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $event->{errno} = $!; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | elsif($? & 127) | ||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $event->{signal} = $? & 127; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | else | ||||||||||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $event->{status} = $? >> 8; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 66 | }; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 33 | $sub->(); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 33 | }; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | @_ = ( | ||||||||||||||||||||||||||||||||||||||||||
| 186 | \@events, | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 33 | [ map { $_->to_check } @expected ], | |||||||||||||||||||||||||||||||||||||||||
| 188 | $test_name | ||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 33 | goto \&Test2::Tools::Compare::is; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | my $sig; | |||||||||||||||||||||||||||||||||||||||||
| 197 | sub named_signal ($) | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 70 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
named_signal: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 70 | my($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # build hash on demand. | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 70 | ▶ | $sig ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sig ||= do {
require Config;
my %sig;
my @num = split(/\s+/, $Config::Config{"sig_num"}, 0);
foreach my $name (split(/\s+/, $Config::Config{"sig_name"}, 0)) {
$sig{$name} = shift @num;
};
\%sig
}
MC/DC0%0/2
$sig ||= do {
require Config;
my %sig;
my @num = split(/\s+/, $Config::Config{"sig_num"}, 0);
foreach my $name (split(/\s+/, $Config::Config{"sig_name"}, 0)) {
$sig{$name} = shift @num;
};
\%sig
}
$sig
do {
require Config;
my %sig;
my @num = split(/\s+/, $Config::Config{"sig_num"}, 0);
foreach my $name (split(/\s+/, $Config::Config{"sig_name"}, 0)) {
$sig{$name} = shift @num;
};
\%sig
}
Truth table66%2/3
A ||= B
A= $sigB= do {
require Config;
my %sig;
my @num = split(/\s+/, $Config::Config{"sig_num"}, 0);
foreach my $name (split(/\s+/, $Config::Config{"sig_name"}, 0)) {
$sig{$name} = shift @num;
};
\%sig
}
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | require Config; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | my %sig; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | my @num = split /\s+/, $Config::Config{sig_num}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | foreach my $name (split /\s+/, $Config::Config{sig_name}) | |||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 68 | $sig{$name} = shift @num; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | \%sig; | |||||||||||||||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 70 | ▶ | croak "no such signal: $name" unless exists $sig->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 69 | $sig->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | sub intercept_exit (&) | |||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intercept_exit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | my $sub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | ▶ | with_return { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | my $return = shift; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | ▶ | local $handlers{exit} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | $ret = shift; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | ▶ | $ret = 0 unless defined $ret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | $ret = int $ret; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | $return->(); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | $sub->(); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | $ret; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | sub intercept_exec (&) | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intercept_exec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | my $sub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | ▶ | with_return { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | my $return = shift; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | ▶ | local $handlers{exec} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | $ret = \@_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | $return->(); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | $sub->(); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | $ret; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | sub proc_event ($;$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 41 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proc_event: called CC=20 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 41 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 41 | ▶ | croak("no such process event undef") unless defined $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 41 | my $check; | |||||||||||||||||||||||||||||||||||||||||
| 266 | my $check2; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 41 | my $callback; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 41 | ▶ | $check = shift if defined $_[0] && !is_plain_coderef $_[0] && !is_plain_hashref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $_[0] and not is_plain_coderef($_[0]) and not is_plain_hashref($_[0])
defined $_[0] and not is_plain_coderef($_[0])
MC/DC100%3/3
defined $_[0] and not is_plain_coderef($_[0]) and not is_plain_hashref($_[0])
defined $_[0]
not is_plain_coderef($_[0])
not is_plain_hashref($_[0])
Truth table100%4/4
A and not(B) and not(C)
A= defined $_[0]B= not is_plain_coderef($_[0])C= not is_plain_hashref($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 41 | ▶ | $check2 = shift if defined $_[0] && is_plain_hashref $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_[0] and is_plain_hashref($_[0])
MC/DC100%2/2
defined $_[0] and is_plain_hashref($_[0])
defined $_[0]
is_plain_hashref($_[0])
Truth table100%3/3
A and B
A= defined $_[0]B= is_plain_hashref($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 41 | ▶ | if(defined $_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 21 | ▶ | if(is_plain_coderef $_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 21 | $callback = shift; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | else | ||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | croak("callback is not a code reference"); | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 41 | my @caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 41 | ▶ | if($type eq 'exit') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 9 | ▶ | if(defined $check) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | ▶ | unless(is_ref $check) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | $check = Test2::Compare::Number->new( | |||||||||||||||||||||||||||||||||||||||||
| 293 | file => $caller[1], | ||||||||||||||||||||||||||||||||||||||||||
| 294 | lines => [$caller[2]], | ||||||||||||||||||||||||||||||||||||||||||
| 295 | input => $check, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | else | ||||||||||||||||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | $check = Test2::Compare::Custom->new( | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | code => sub { defined $_ ? 1 : 0 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | name => 'DEFINED', | |||||||||||||||||||||||||||||||||||||||||
| 304 | operator => 'DEFINED()', | ||||||||||||||||||||||||||||||||||||||||||
| 305 | file => $caller[1], | ||||||||||||||||||||||||||||||||||||||||||
| 306 | lines => [$caller[2]], | ||||||||||||||||||||||||||||||||||||||||||
| 307 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 9 | return Test2::Tools::Process::Exit->new(status_check => $check, callback => $callback); | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | elsif($type =~ /^(exec|system)$/) | ||||||||||||||||||||||||||||||||||||||||||
| 314 | { | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 32 | ▶ | if(defined $check) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 22 | ▶ | if(is_plain_arrayref $check) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 5 | my $array = Test2::Compare::Array->new( | |||||||||||||||||||||||||||||||||||||||||
| 320 | called => \@caller, | ||||||||||||||||||||||||||||||||||||||||||
| 321 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 5 | foreach my $item (@$check) | |||||||||||||||||||||||||||||||||||||||||
| 323 | { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 11 | my $wc = Test2::Compare::Wildcard->new( | |||||||||||||||||||||||||||||||||||||||||
| 325 | expect => $item, | ||||||||||||||||||||||||||||||||||||||||||
| 326 | file => $caller[1], | ||||||||||||||||||||||||||||||||||||||||||
| 327 | lines => [$caller[2]], | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 11 | $array->add_item($wc); | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | $check = $array; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | elsif(!is_ref $check) | ||||||||||||||||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 4 | $check = Test2::Compare::String->new( | |||||||||||||||||||||||||||||||||||||||||
| 336 | file => $caller[1], | ||||||||||||||||||||||||||||||||||||||||||
| 337 | lines => [$caller[2]], | ||||||||||||||||||||||||||||||||||||||||||
| 338 | input => $check, | ||||||||||||||||||||||||||||||||||||||||||
| 339 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | else | ||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | $check = Test2::Compare::Custom->new( | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 8 | ▶ | code => sub { defined $_ ? 1 : 0 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 10 | name => 'DEFINED', | |||||||||||||||||||||||||||||||||||||||||
| 347 | operator => 'DEFINED()', | ||||||||||||||||||||||||||||||||||||||||||
| 348 | file => $caller[1], | ||||||||||||||||||||||||||||||||||||||||||
| 349 | lines => [$caller[2]], | ||||||||||||||||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 32 | ▶ | if($type eq 'system') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | { | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 18 | ▶ | $check2 ||= { status => 0 }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$check2 ||= {"status", 0}
MC/DC100%1/1
$check2 ||= {"status", 0}
$check2
Truth table100%2/2
A
A= $check2
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 32 | ▶ | my $class = $type eq 'exec' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | ? 'Test2::Tools::Process::Exec' | ||||||||||||||||||||||||||||||||||||||||||
| 360 | : 'Test2::Tools::Process::System'; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 32 | return $class->new( command_check => $check, result_check => $check2, callback => $callback); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | croak("no such process event $type"); | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | package Test2::Tools::Process::Event; | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | ▶ | use constant is_exit => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 8 | ▶ | use constant is_exec => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 8 | ▶ | use constant is_system => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | ▶ | use Class::Tiny qw( callback ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | package Test2::Tools::Process::Exit; | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 8 | ▶ | use constant is_exit => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 8 | ▶ | use base qw( Test2::Tools::Process::Event ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 8 | ▶ | use Class::Tiny qw( status_check ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | sub to_check | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_check: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 9 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 9 | { event_type => 'exit', exit_status => $self->status_check }; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | package Test2::Tools::Process::Exec; | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 8 | ▶ | use constant is_exec => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 8 | ▶ | use base qw( Test2::Tools::Process::Event ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 8 | ▶ | use Class::Tiny qw( command_check ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | sub to_check | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_check: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 14 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 14 | { event_type => 'exec', command => $self->command_check }; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | package Test2::Tools::Process::System; | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 8 | ▶ | use constant is_system => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 8 | ▶ | use base qw( Test2::Tools::Process::Event ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 8 | ▶ | use Class::Tiny qw( command_check result_check ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | sub to_check | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_check: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 18 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 18 | { event_type => 'system', command => $self->command_check, %{ $self->result_check } }; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | package Test2::Tools::Process::Proc; | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | my($class, $return) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | bless { | |||||||||||||||||||||||||||||||||||||||||
| 416 | return => $return, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub terminate { shift->{return}->() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
terminate: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | sub errno | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errno: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my($self, $errno) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $self->{errno} = $errno; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | package Test2::Tools::Process::SystemProc; | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 17 | my($class, $return, $result, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 17 | bless { | |||||||||||||||||||||||||||||||||||||||||
| 434 | return => $return, | ||||||||||||||||||||||||||||||||||||||||||
| 435 | result => $result, | ||||||||||||||||||||||||||||||||||||||||||
| 436 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 437 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | ▶ | sub type { shift->{type} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | sub exit | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exit: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | my($self, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 5 | ▶ | $status = 0 unless defined $status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 5 | $status = int $status; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | $self->{result}->{status} = $status; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | $? = $status << 8; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 5 | $self->{return}->(); | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | sub signal | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signal: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 3 | my($self, $signal) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 3 | ▶ | $signal = 0 unless defined $signal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 3 | ▶ | if($signal =~ /^[A-Z]/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | $signal = Test2::Tools::Process::named_signal($signal); | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | else | ||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 1 | $signal = int $signal; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | $self->{result}->{signal} = $signal; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 2 | $? = $signal; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | $self->{return}->(); | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | sub errno | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errno: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | my($self, $errno) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | $errno = 0 unless defined $errno; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | $errno = int $errno; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | $self->{result}->{errno} = $! = $errno; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | $self->{return}->(); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | __END__ | ||||||||||||||||||||||||||||||||||||||||||