| 1 | 6 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | |||||||||||||
| 3 | package Test::Tester::Capture; | ||||||||||||
| 4 | |||||||||||||
| 5 | 6 | our $VERSION = '1.302226'; | |||||||||||
| 6 | |||||||||||||
| 7 | |||||||||||||
| 8 | 6 | ▶ | use Test::Builder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 6 | our @ISA = qw( Test::Builder ); | |||||||||||
| 11 | |||||||||||||
| 12 | # Make Test::Tester::Capture thread-safe for ithreads. | ||||||||||||
| 13 | 6 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 6 | ▶ | use Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 6 | ▶ | *share = sub { 0 }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 6 | ▶ | *lock = sub { 0 }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | } | ||||||||||||
| 18 | |||||||||||||
| 19 | 6 | my $Curr_Test = 0; share($Curr_Test); | |||||||||||
| 20 | 6 | my @Test_Results = (); share(@Test_Results); | |||||||||||
| 21 | 6 | my $Prem_Diag = {diag => ""}; share($Curr_Test); | |||||||||||
| 22 | |||||||||||||
| 23 | sub new | ||||||||||||
| 24 | 63 | ▶ | { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 25 | # Test::Tester::Capgture::new used to just return __PACKAGE__ | ||||||||||||
| 26 | # because Test::Builder::new enforced its singleton nature by | ||||||||||||
| 27 | # return __PACKAGE__. That has since changed, Test::Builder::new now | ||||||||||||
| 28 | # returns a blessed has and around version 0.78, Test::Builder::todo | ||||||||||||
| 29 | # started wanting to modify $self. To cope with this, we now return | ||||||||||||
| 30 | # a blessed hash. This is a short-term hack, the correct thing to do | ||||||||||||
| 31 | # is to detect which style of Test::Builder we're dealing with and | ||||||||||||
| 32 | # act appropriately. | ||||||||||||
| 33 | |||||||||||||
| 34 | 63 | my $class = shift; | |||||||||||
| 35 | 63 | return bless {}, $class; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 21 | ▶ | sub ok { | ||||||||||
|
Subroutine
ok: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||
| 39 | 21 | my($self, $test, $name) = @_; | |||||||||||
| 40 | |||||||||||||
| 41 | 21 | my $ctx = $self->ctx; | |||||||||||
| 42 | |||||||||||||
| 43 | # $test might contain an object which we don't want to accidentally | ||||||||||||
| 44 | # store, so we turn it into a boolean. | ||||||||||||
| 45 | 21 | ▶ | $test = $test ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | |||||||||||||
| 47 | 21 | lock $Curr_Test; | |||||||||||
| 48 | 21 | $Curr_Test++; | |||||||||||
| 49 | |||||||||||||
| 50 | 21 | my($pack, $file, $line) = $self->caller; | |||||||||||
| 51 | |||||||||||||
| 52 | 21 | my $todo = $self->todo(); | |||||||||||
| 53 | |||||||||||||
| 54 | 21 | my $result = {}; | |||||||||||
| 55 | 21 | share($result); | |||||||||||
| 56 | |||||||||||||
| 57 | 21 | ▶ | unless( $test ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 7 | ▶ | @$result{ 'ok', 'actual_ok' } = ( ( $todo ? 1 : 0 ), 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | } | ||||||||||||
| 60 | else { | ||||||||||||
| 61 | 14 | @$result{ 'ok', 'actual_ok' } = ( 1, $test ); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 21 | ▶ | if( defined $name ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 19 | $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. | |||||||||||
| 66 | 19 | $result->{name} = $name; | |||||||||||
| 67 | } | ||||||||||||
| 68 | else { | ||||||||||||
| 69 | 2 | $result->{name} = ''; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 21 | ▶ | if( $todo ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 0 | my $what_todo = $todo; | |||||||||||
| 74 | 0 | $result->{reason} = $what_todo; | |||||||||||
| 75 | 0 | $result->{type} = 'todo'; | |||||||||||
| 76 | } | ||||||||||||
| 77 | else { | ||||||||||||
| 78 | 21 | $result->{reason} = ''; | |||||||||||
| 79 | 21 | $result->{type} = ''; | |||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | 21 | $Test_Results[$Curr_Test-1] = $result; | |||||||||||
| 83 | |||||||||||||
| 84 | 21 | ▶ | unless( $test ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 7 | ▶ | my $msg = $todo ? "Failed (TODO)" : "Failed"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 7 | $result->{fail_diag} = (" $msg test ($file at line $line)\n"); | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 21 | $result->{diag} = ""; | |||||||||||
| 90 | 21 | $result->{_level} = $Test::Builder::Level; | |||||||||||
| 91 | 21 | $result->{_depth} = Test::Tester::find_run_tests(); | |||||||||||
| 92 | |||||||||||||
| 93 | 21 | $ctx->release; | |||||||||||
| 94 | |||||||||||||
| 95 | 21 | ▶ | return $test ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 3 | ▶ | sub skip { | ||||||||||
|
Subroutine
skip: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 99 | 3 | my($self, $why) = @_; | |||||||||||
| 100 | 3 | ▶ | $why ||= ''; | ||||||||||
|
Condition50%1/2
$why ||= ""
MC/DC0%0/1
$why ||= ""
$why
Truth table50%1/2
A
A= $why
| |||||||||||||
| 101 | |||||||||||||
| 102 | 3 | my $ctx = $self->ctx; | |||||||||||
| 103 | |||||||||||||
| 104 | 3 | lock($Curr_Test); | |||||||||||
| 105 | 3 | $Curr_Test++; | |||||||||||
| 106 | |||||||||||||
| 107 | 3 | my %result; | |||||||||||
| 108 | 3 | share(%result); | |||||||||||
| 109 | 3 | %result = ( | |||||||||||
| 110 | 'ok' => 1, | ||||||||||||
| 111 | actual_ok => 1, | ||||||||||||
| 112 | name => '', | ||||||||||||
| 113 | type => 'skip', | ||||||||||||
| 114 | reason => $why, | ||||||||||||
| 115 | diag => "", | ||||||||||||
| 116 | _level => $Test::Builder::Level, | ||||||||||||
| 117 | _depth => Test::Tester::find_run_tests(), | ||||||||||||
| 118 | ); | ||||||||||||
| 119 | 3 | $Test_Results[$Curr_Test-1] = \%result; | |||||||||||
| 120 | |||||||||||||
| 121 | 3 | $ctx->release; | |||||||||||
| 122 | 3 | return 1; | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | 3 | ▶ | sub todo_skip { | ||||||||||
|
Subroutine
todo_skip: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 126 | 3 | my($self, $why) = @_; | |||||||||||
| 127 | 3 | ▶ | $why ||= ''; | ||||||||||
|
Condition50%1/2
$why ||= ""
MC/DC0%0/1
$why ||= ""
$why
Truth table50%1/2
A
A= $why
| |||||||||||||
| 128 | |||||||||||||
| 129 | 3 | my $ctx = $self->ctx; | |||||||||||
| 130 | |||||||||||||
| 131 | 3 | lock($Curr_Test); | |||||||||||
| 132 | 3 | $Curr_Test++; | |||||||||||
| 133 | |||||||||||||
| 134 | 3 | my %result; | |||||||||||
| 135 | 3 | share(%result); | |||||||||||
| 136 | 3 | %result = ( | |||||||||||
| 137 | 'ok' => 1, | ||||||||||||
| 138 | actual_ok => 0, | ||||||||||||
| 139 | name => '', | ||||||||||||
| 140 | type => 'todo_skip', | ||||||||||||
| 141 | reason => $why, | ||||||||||||
| 142 | diag => "", | ||||||||||||
| 143 | _level => $Test::Builder::Level, | ||||||||||||
| 144 | _depth => Test::Tester::find_run_tests(), | ||||||||||||
| 145 | ); | ||||||||||||
| 146 | |||||||||||||
| 147 | 3 | $Test_Results[$Curr_Test-1] = \%result; | |||||||||||
| 148 | |||||||||||||
| 149 | 3 | $ctx->release; | |||||||||||
| 150 | 3 | return 1; | |||||||||||
| 151 | } | ||||||||||||
| 152 | |||||||||||||
| 153 | 18 | ▶ | sub diag { | ||||||||||
|
Subroutine
diag: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||
| 154 | 18 | my($self, @msgs) = @_; | |||||||||||
| 155 | 18 | ▶ | return unless @msgs; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 156 | |||||||||||||
| 157 | # Prevent printing headers when compiling (i.e. -c) | ||||||||||||
| 158 | 18 | ▶ | return if $^C; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 159 | |||||||||||||
| 160 | 18 | my $ctx = $self->ctx; | |||||||||||
| 161 | |||||||||||||
| 162 | # Escape each line with a #. | ||||||||||||
| 163 | 18 | foreach (@msgs) { | |||||||||||
| 164 | 18 | ▶ | $_ = 'undef' unless defined; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 165 | } | ||||||||||||
| 166 | |||||||||||||
| 167 | 18 | ▶ | push @msgs, "\n" unless $msgs[-1] =~ /\n\Z/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 168 | |||||||||||||
| 169 | 18 | ▶ | my $result = $Curr_Test ? $Test_Results[$Curr_Test - 1] : $Prem_Diag; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 170 | |||||||||||||
| 171 | 18 | $result->{diag} .= join("", @msgs); | |||||||||||
| 172 | |||||||||||||
| 173 | 18 | $ctx->release; | |||||||||||
| 174 | 18 | return 0; | |||||||||||
| 175 | } | ||||||||||||
| 176 | |||||||||||||
| 177 | 19 | ▶ | sub details { | ||||||||||
|
Subroutine
details: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 178 | 19 | return @Test_Results; | |||||||||||
| 179 | } | ||||||||||||
| 180 | |||||||||||||
| 181 | |||||||||||||
| 182 | # Stub. Feel free to send me a patch to implement this. | ||||||||||||
| 183 | 0 | ▶ | sub note { | ||||||||||
|
Subroutine
note: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 184 | } | ||||||||||||
| 185 | |||||||||||||
| 186 | 0 | ▶ | sub explain { | ||||||||||
|
Subroutine
explain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 187 | 0 | return Test::Builder::explain(@_); | |||||||||||
| 188 | } | ||||||||||||
| 189 | |||||||||||||
| 190 | sub premature | ||||||||||||
| 191 | 18 | ▶ | { | ||||||||||
|
Subroutine
premature: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 192 | 18 | return $Prem_Diag->{diag}; | |||||||||||
| 193 | } | ||||||||||||
| 194 | |||||||||||||
| 195 | sub current_test | ||||||||||||
| 196 | 2 | ▶ | { | ||||||||||
|
Subroutine
current_test: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 197 | 2 | ▶ | if (@_ > 1) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 198 | { | ||||||||||||
| 199 | 1 | die "Don't try to change the test number!"; | |||||||||||
| 200 | } | ||||||||||||
| 201 | else | ||||||||||||
| 202 | { | ||||||||||||
| 203 | 1 | return $Curr_Test; | |||||||||||
| 204 | } | ||||||||||||
| 205 | } | ||||||||||||
| 206 | |||||||||||||
| 207 | sub reset | ||||||||||||
| 208 | 18 | ▶ | { | ||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 209 | 18 | $Curr_Test = 0; | |||||||||||
| 210 | 18 | @Test_Results = (); | |||||||||||
| 211 | 18 | $Prem_Diag = {diag => ""}; | |||||||||||
| 212 | } | ||||||||||||
| 213 | |||||||||||||
| 214 | 6 | 1; | |||||||||||
| 215 | |||||||||||||
| 216 | __END__ | ||||||||||||