line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NoWarnings; |
2
|
|
|
|
|
|
|
|
3
|
85
|
|
|
85
|
|
229266
|
use 5.006; |
|
85
|
|
|
|
|
311
|
|
4
|
85
|
|
|
85
|
|
383
|
use strict; |
|
85
|
|
|
|
|
130
|
|
|
85
|
|
|
|
|
1788
|
|
5
|
85
|
|
|
85
|
|
400
|
use warnings; |
|
85
|
|
|
|
|
387
|
|
|
85
|
|
|
|
|
2512
|
|
6
|
85
|
|
|
85
|
|
358
|
use Carp (); |
|
85
|
|
|
|
|
143
|
|
|
85
|
|
|
|
|
1283
|
|
7
|
85
|
|
|
85
|
|
372
|
use Exporter (); |
|
85
|
|
|
|
|
134
|
|
|
85
|
|
|
|
|
1305
|
|
8
|
85
|
|
|
85
|
|
363
|
use Test::Builder (); |
|
85
|
|
|
|
|
172
|
|
|
85
|
|
|
|
|
1311
|
|
9
|
85
|
|
|
85
|
|
26332
|
use Test::NoWarnings::Warning (); |
|
85
|
|
|
|
|
151
|
|
|
85
|
|
|
|
|
1851
|
|
10
|
|
|
|
|
|
|
|
11
|
85
|
|
|
85
|
|
346
|
use vars qw( $VERSION @EXPORT_OK @ISA $do_end_test ); |
|
85
|
|
|
|
|
120
|
|
|
85
|
|
|
|
|
5927
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
85
|
|
|
85
|
|
221
|
$VERSION = '1.02'; |
14
|
85
|
|
|
|
|
1622
|
@ISA = 'Exporter'; |
15
|
85
|
|
|
|
|
282
|
@EXPORT_OK = qw( |
16
|
|
|
|
|
|
|
clear_warnings had_no_warnings warnings |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Do we add the warning test at the end? |
20
|
85
|
|
|
|
|
44291
|
$do_end_test = 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $TEST = Test::Builder->new; |
24
|
|
|
|
|
|
|
my $PID = $$; |
25
|
|
|
|
|
|
|
my @WARNINGS = (); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$SIG{__WARN__} = make_catcher(\@WARNINGS); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub import { |
30
|
85
|
|
|
85
|
|
473
|
$do_end_test = 1; |
31
|
85
|
|
|
|
|
105466
|
goto &Exporter::import; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# the END block must be after the "use Test::Builder" to make sure it runs |
35
|
|
|
|
|
|
|
# before Test::Builder's end block |
36
|
|
|
|
|
|
|
# only run the test if there have been other tests |
37
|
|
|
|
|
|
|
END { |
38
|
85
|
50
|
|
85
|
|
4867137
|
had_no_warnings() if $do_end_test; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub make_warning { |
42
|
6
|
|
|
6
|
0
|
35
|
local $SIG{__WARN__}; |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
16
|
my $msg = shift; |
45
|
6
|
|
|
|
|
22
|
my $warning = Test::NoWarnings::Warning->new; |
46
|
|
|
|
|
|
|
|
47
|
6
|
|
|
|
|
18
|
$warning->setMessage($msg); |
48
|
6
|
|
|
|
|
12
|
$warning->fillTest($TEST); |
49
|
6
|
|
|
|
|
19
|
$warning->fillTrace(__PACKAGE__); |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
7
|
$Carp::Internal{__PACKAGE__.""}++; |
52
|
6
|
|
|
|
|
11
|
local $Carp::CarpLevel = $Carp::CarpLevel + 1; |
53
|
6
|
|
|
|
|
12
|
$warning->fillCarp($msg); |
54
|
6
|
|
|
|
|
10
|
$Carp::Internal{__PACKAGE__.""}--; |
55
|
|
|
|
|
|
|
|
56
|
6
|
|
|
|
|
18
|
return $warning; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# this make a subroutine which can be used in $SIG{__WARN__} |
60
|
|
|
|
|
|
|
# it takes one argument, a ref to an array |
61
|
|
|
|
|
|
|
# it will push the details of the warning onto the end of the array. |
62
|
|
|
|
|
|
|
sub make_catcher { |
63
|
85
|
|
|
85
|
0
|
113
|
my $array = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return sub { |
66
|
6
|
|
|
6
|
|
240
|
my $msg = shift; |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
12
|
$Carp::Internal{__PACKAGE__.""}++; |
69
|
6
|
|
|
|
|
13
|
push(@$array, make_warning($msg)); |
70
|
6
|
|
|
|
|
8
|
$Carp::Internal{__PACKAGE__.""}--; |
71
|
|
|
|
|
|
|
|
72
|
6
|
|
|
|
|
42
|
return $msg; |
73
|
85
|
|
|
|
|
589
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub had_no_warnings { |
77
|
87
|
100
|
|
87
|
1
|
2364
|
return 0 if $$ != $PID; |
78
|
|
|
|
|
|
|
|
79
|
85
|
|
|
|
|
532
|
local $SIG{__WARN__}; |
80
|
85
|
|
50
|
|
|
783
|
my $name = shift || "no warnings"; |
81
|
|
|
|
|
|
|
|
82
|
85
|
|
|
|
|
3689
|
my $ok; |
83
|
|
|
|
|
|
|
my $diag; |
84
|
85
|
50
|
|
|
|
309
|
if ( @WARNINGS == 0 ) { |
85
|
85
|
|
|
|
|
176
|
$ok = 1; |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
0
|
$ok = 0; |
88
|
0
|
|
|
|
|
0
|
$diag = "There were ".@WARNINGS." warning(s)\n"; |
89
|
0
|
|
|
|
|
0
|
$diag .= join "----------\n", map { $_->toString } @WARNINGS; |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
85
|
50
|
|
|
|
593
|
$TEST->ok($ok, $name) || $TEST->diag($diag); |
93
|
|
|
|
|
|
|
|
94
|
85
|
|
|
|
|
30868
|
return $ok; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub clear_warnings { |
98
|
2
|
|
|
2
|
1
|
463
|
local $SIG{__WARN__}; |
99
|
2
|
|
|
|
|
194
|
@WARNINGS = (); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub warnings { |
103
|
0
|
|
|
0
|
1
|
|
local $SIG{__WARN__}; |
104
|
0
|
|
|
|
|
|
return @WARNINGS; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub builder { |
108
|
0
|
|
|
0
|
0
|
|
local $SIG{__WARN__}; |
109
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
110
|
0
|
|
|
|
|
|
$TEST = shift; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
|
return $TEST; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |