line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Stream::Formatter::TAP; |
2
|
109
|
|
|
109
|
|
1062
|
use strict; |
|
109
|
|
|
|
|
191
|
|
|
109
|
|
|
|
|
2850
|
|
3
|
109
|
|
|
109
|
|
511
|
use warnings; |
|
109
|
|
|
|
|
195
|
|
|
109
|
|
|
|
|
2843
|
|
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
599
|
use Test::Stream::Util qw/protect/; |
|
109
|
|
|
|
|
193
|
|
|
109
|
|
|
|
|
779
|
|
6
|
|
|
|
|
|
|
use Test::Stream::HashBase( |
7
|
109
|
|
|
|
|
929
|
accessors => [qw/no_numbers no_header no_diag handles _encoding/], |
8
|
109
|
|
|
109
|
|
563
|
); |
|
109
|
|
|
|
|
200
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub OUT_STD() { 0 } |
11
|
|
|
|
|
|
|
sub OUT_ERR() { 1 } |
12
|
|
|
|
|
|
|
sub OUT_TODO() { 2 } |
13
|
|
|
|
|
|
|
|
14
|
109
|
|
|
109
|
|
601
|
use Test::Stream::Exporter; |
|
109
|
|
|
|
|
203
|
|
|
109
|
|
|
|
|
758
|
|
15
|
|
|
|
|
|
|
exports qw/OUT_STD OUT_ERR OUT_TODO/; |
16
|
109
|
|
|
109
|
|
568
|
no Test::Stream::Exporter; |
|
109
|
|
|
|
|
198
|
|
|
109
|
|
|
|
|
564
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
_autoflush(\*STDOUT); |
19
|
|
|
|
|
|
|
_autoflush(\*STDERR); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init { |
22
|
131
|
|
|
131
|
0
|
304
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
131
|
|
66
|
|
|
1474
|
$self->{+HANDLES} ||= $self->_open_handles; |
25
|
131
|
100
|
|
|
|
720
|
if(my $enc = delete $self->{encoding}) { |
26
|
1
|
|
|
|
|
5
|
$self->encoding($enc); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub encoding { |
31
|
116
|
|
|
116
|
1
|
260
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
116
|
100
|
|
|
|
453
|
if (@_) { |
34
|
115
|
|
|
|
|
622
|
my ($enc) = @_; |
35
|
115
|
|
|
|
|
310
|
my $handles = $self->{+HANDLES}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# https://rt.perl.org/Public/Bug/Display.html?id=31923 |
38
|
|
|
|
|
|
|
# If utf8 is requested we use ':utf8' instead of ':encoding(utf8)' in |
39
|
|
|
|
|
|
|
# order to avoid the thread segfault. |
40
|
115
|
50
|
|
|
|
1106
|
if ($enc =~ m/^utf-?8$/i) { |
41
|
115
|
|
|
|
|
1097
|
binmode($_, ":utf8") for @$handles; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
0
|
binmode($_, ":encoding($enc)") for @$handles; |
45
|
|
|
|
|
|
|
} |
46
|
115
|
|
|
|
|
395
|
$self->{+_ENCODING} = $enc; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
116
|
|
|
|
|
764
|
return $self->{+_ENCODING}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if ($^C) { |
53
|
109
|
|
|
109
|
|
607
|
no warnings 'redefine'; |
|
109
|
|
|
|
|
224
|
|
|
109
|
|
|
|
|
22769
|
|
54
|
|
|
|
|
|
|
*write = sub {}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub write { |
57
|
1726
|
|
|
1726
|
1
|
2932
|
my ($self, $e, $num) = @_; |
58
|
|
|
|
|
|
|
|
59
|
1726
|
100
|
100
|
|
|
6312
|
return if $self->{+NO_DIAG} && $e->isa('Test::Stream::Event::Diag'); |
60
|
1725
|
100
|
100
|
|
|
4865
|
return if $self->{+NO_HEADER} && $e->isa('Test::Stream::Event::Plan'); |
61
|
|
|
|
|
|
|
|
62
|
1724
|
100
|
|
|
|
3925
|
$num = undef if $self->{+NO_NUMBERS}; |
63
|
1724
|
|
|
|
|
5312
|
my @tap = $e->to_tap($num); |
64
|
|
|
|
|
|
|
|
65
|
1724
|
|
|
|
|
3077
|
my $handles = $self->{+HANDLES}; |
66
|
1724
|
|
100
|
|
|
6591
|
my $nesting = $e->nested || 0; |
67
|
1724
|
|
|
|
|
10536
|
my $indent = ' ' x $nesting; |
68
|
|
|
|
|
|
|
|
69
|
1724
|
100
|
100
|
|
|
4558
|
return if $nesting && $e->isa('Test::Stream::Event::Bail'); |
70
|
|
|
|
|
|
|
|
71
|
1723
|
|
|
|
|
6538
|
local($\, $", $,) = (undef, ' ', ''); |
72
|
1723
|
|
|
|
|
3226
|
for my $set (@tap) { |
73
|
109
|
|
|
109
|
|
573
|
no warnings 'uninitialized'; |
|
109
|
|
|
|
|
186
|
|
|
109
|
|
|
|
|
28958
|
|
74
|
3400
|
|
|
|
|
6785
|
my ($hid, $msg) = @$set; |
75
|
3400
|
50
|
|
|
|
7857
|
next unless $msg; |
76
|
3400
|
50
|
|
|
|
7834
|
my $io = $handles->[$hid] or next; |
77
|
|
|
|
|
|
|
|
78
|
3400
|
100
|
|
|
|
7038
|
$msg =~ s/^/$indent/mg if $nesting; |
79
|
3400
|
|
|
|
|
114921
|
print $io $msg; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _open_handles { |
84
|
128
|
|
|
128
|
|
283
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
128
|
50
|
|
|
|
3550
|
open( my $out, ">&STDOUT" ) or die "Can't dup STDOUT: $!"; |
87
|
128
|
50
|
|
|
|
1598
|
open( my $err, ">&STDERR" ) or die "Can't dup STDERR: $!"; |
88
|
|
|
|
|
|
|
|
89
|
128
|
|
|
|
|
553
|
_autoflush($out); |
90
|
128
|
|
|
|
|
398
|
_autoflush($err); |
91
|
|
|
|
|
|
|
|
92
|
128
|
|
|
|
|
810
|
return [$out, $err, $out]; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _autoflush { |
96
|
474
|
|
|
474
|
|
883
|
my($fh) = pop; |
97
|
474
|
|
|
|
|
1487
|
my $old_fh = select $fh; |
98
|
474
|
|
|
|
|
1096
|
$| = 1; |
99
|
474
|
|
|
|
|
1349
|
select $old_fh; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |