line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::Warnings; |
2
|
155
|
|
|
155
|
|
1632
|
use strict; |
|
155
|
|
|
|
|
340
|
|
|
155
|
|
|
|
|
4862
|
|
3
|
155
|
|
|
155
|
|
815
|
use warnings; |
|
155
|
|
|
|
|
311
|
|
|
155
|
|
|
|
|
6499
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
6
|
|
|
|
|
|
|
|
7
|
155
|
|
|
155
|
|
935
|
use Test2::API qw/context/; |
|
155
|
|
|
|
|
305
|
|
|
155
|
|
|
|
|
10386
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw/warns warning warnings no_warnings/; |
10
|
155
|
|
|
155
|
|
1005
|
use base 'Exporter'; |
|
155
|
|
|
|
|
346
|
|
|
155
|
|
|
|
|
62303
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub warns(&) { |
13
|
6
|
|
|
6
|
1
|
359
|
my $code = shift; |
14
|
6
|
|
|
|
|
11
|
my $warnings = 0; |
15
|
6
|
|
|
6
|
|
35
|
local $SIG{__WARN__} = sub { $warnings++ }; |
|
6
|
|
|
|
|
77
|
|
16
|
6
|
|
|
|
|
20
|
$code->(); |
17
|
6
|
|
|
|
|
103
|
return $warnings; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
1
|
8
|
sub no_warnings(&) { return !&warns(@_) } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub warning(&) { |
23
|
14
|
|
|
14
|
1
|
1023
|
my $code = shift; |
24
|
14
|
|
|
|
|
29
|
my @warnings; |
25
|
|
|
|
|
|
|
{ |
26
|
14
|
|
|
14
|
|
26
|
local $SIG{__WARN__} = sub { push @warnings => @_ }; |
|
14
|
|
|
|
|
82
|
|
|
14
|
|
|
|
|
315
|
|
27
|
14
|
|
|
|
|
59
|
$code->(); |
28
|
14
|
100
|
|
|
|
16790
|
return unless @warnings; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
13
|
100
|
|
|
|
47
|
if (@warnings > 1) { |
32
|
1
|
|
|
|
|
4
|
my $ctx = context(); |
33
|
1
|
|
|
|
|
96
|
$ctx->alert("Extra warnings in warning { ... }"); |
34
|
1
|
|
|
|
|
8
|
$ctx->note($_) for @warnings; |
35
|
1
|
|
|
|
|
479
|
$ctx->release; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
13
|
|
|
|
|
85
|
return $warnings[0]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub warnings(&) { |
42
|
5
|
|
|
5
|
1
|
370
|
my $code = shift; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
11
|
my @warnings; |
45
|
5
|
|
|
10
|
|
31
|
local $SIG{__WARN__} = sub { push @warnings => @_ }; |
|
10
|
|
|
|
|
167
|
|
46
|
5
|
|
|
|
|
18
|
$code->(); |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
122
|
return \@warnings; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |