| 1 | 3 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Test::DiagINC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: List modules and versions loaded if tests fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.010'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # If the tested module did not load strict/warnings we do not want | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # to load them either. On the other hand we would like to know our | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # code is at least somewhat ok. Therefore this madness ;) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=4 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | if ( $ENV{RELEASE_TESTING} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | require warnings && warnings->import; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | require strict && strict->import; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | sub _max_length { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_max_length: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | my $max = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 516 | ▶ | do { $max = length if length > $max } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | for @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | return $max; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Get our CWD *without* loading anything. Original idea by xdg++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # ribasushi thinks this is fragile and will break sooner rather than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # later, but adding it as is because haarg and xdg both claim it's fine. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Requires %ENV cleanup to work under taint mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | my $REALPATH_CWD = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | local $ENV{PATH}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | delete $ENV{PATH}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | local $ENV{IFS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | delete $ENV{IFS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | local $ENV{CDPATH}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | delete $ENV{CDPATH}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | local $ENV{ENV}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | delete $ENV{ENV}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | local $ENV{BASH_ENV}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | delete $ENV{BASH_ENV}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | my ($perl) = $^X =~ /(.+)/; # $^X is internal how could it be tainted?! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | `"$perl" -MCwd -le "print getcwd"`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | chomp $REALPATH_CWD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my $ORIGINAL_PID = $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | END { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | if ( $$ == $ORIGINAL_PID ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # make sure we report only on stuff that was loaded by the test, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # nothing more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # get a snapshot early in order to not misreport B.pm and friends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # below - this *will* skip any extra modules loaded in END, it was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # deemed an acceptable compromise by ribasushi and xdg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | my @INC_list = keys %INC; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # If we meet the "fail" criteria - no need to load B and fire | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # an extra check in an extra END (also doesn't work on 5.6) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if ( _assert_no_fail(@INC_list) and $] >= 5.008 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_assert_no_fail(@INC_list) and $] >= "5.008"
MC/DC50%1/2
_assert_no_fail(@INC_list) and $] >= "5.008"
_assert_no_fail(@INC_list)
$] >= "5.008"
Truth table66%2/3
A and B
A= _assert_no_fail(@INC_list)B= $] >= "5.008"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # we did not report anything yet - add an extra END to catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # possible future-fails | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | require B; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | push @{ B::end_av()->object_2svref }, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | _assert_no_fail(@INC_list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Dump %INC IFF in the main process and test is failing or exit is non-zero | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # return true if no failure or if PID mismatches, return false otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | sub _assert_no_fail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_no_fail: called CC=16 SCAR=28.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | return 1 if $$ != $ORIGINAL_PID; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$? or $INC{"Test/Builder.pm"} and "Test::Builder"->can("is_passing") and not "Test::Builder"->new->is_passing
$INC{"Test/Builder.pm"} and "Test::Builder"->can("is_passing") and not "Test::Builder"->new->is_passing
$INC{"Test/Builder.pm"} and "Test::Builder"->can("is_passing")
MC/DC50%2/4
$? or $INC{"Test/Builder.pm"} and "Test::Builder"->can("is_passing") and not "Test::Builder"->new->is_passing
$?
$INC{"Test/Builder.pm"}
"Test::Builder"->can("is_passing")
not "Test::Builder"->new->is_passing
Truth table60%3/5
A or B and C and not(D)
A= $?B= $INC{"Test/Builder.pm"}C= "Test::Builder"->can("is_passing")D= not "Test::Builder"->new->is_passing
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | or ( $INC{'Test/Builder.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | and Test::Builder->can('is_passing') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | and !Test::Builder->new->is_passing ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | require Cwd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | require File::Spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | require Cwd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my %results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | for my $pkg_as_path (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 266 | ▶ | next unless ( my $p = $pkg_as_path ) =~ s/\.pm\z//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 262 | $p =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 262 | ▶ | next unless $p =~ /\A[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*\Z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # a module we recorded as INCed disappeared... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 262 | ▶ | if ( not exists $INC{$pkg_as_path} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $results{$p} = 'Module unloaded in END...?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 262 | ▶ | if ( not defined $INC{$pkg_as_path} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | $results{$p} = 'Found and failed to load'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # rel2abs on an absolute path is a noop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # https://metacpan.org/source/SMUELLER/PathTools-3.40/lib/File/Spec/Unix.pm#L474 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # https://metacpan.org/source/SMUELLER/PathTools-3.40/lib/File/Spec/Win32.pm#L324 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 260 | ▶ | Cwd::realpath( File::Spec->rel2abs( $INC{$pkg_as_path}, $REALPATH_CWD ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =~ m| \A \Q$REALPATH_CWD\E [\\\/] |x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 256 | my $ver = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 256 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 256 | my $v = eval { $p->VERSION }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 256 | ▶ | $@ ? '->VERSION call failed' : $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 256 | ▶ | $ver = 'undef' unless defined $ver; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 256 | $results{$p} = $ver; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | my $diag = "Listing modules from %INC\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | my $ml = _max_length( keys %results ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | my $vl = _max_length( values %results ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | for ( sort keys %results ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | $diag .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | " %*s %*s\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # pairs of [ padding-length => content ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 258 | $vl => $results{$_}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | -$ml => $_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | if ( $INC{"Test/Builder.pm"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | Test::Builder->new->diag($diag); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $diag =~ s/^/# /mg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | print STDERR $diag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # vim: ts=4 sts=4 sw=4 et: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||