line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NoWarnings; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
529315
|
use 5.006; |
|
8
|
|
|
|
|
89
|
|
4
|
8
|
|
|
8
|
|
46
|
use strict; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
229
|
|
5
|
8
|
|
|
8
|
|
40
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
294
|
|
6
|
8
|
|
|
8
|
|
44
|
use Carp (); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
196
|
|
7
|
8
|
|
|
8
|
|
38
|
use Exporter (); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
170
|
|
8
|
8
|
|
|
8
|
|
48
|
use Test::Builder (); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
150
|
|
9
|
8
|
|
|
8
|
|
3579
|
use Test::NoWarnings::Warning (); |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
655
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our ( $VERSION, @EXPORT_OK, @ISA, $do_end_test ); |
12
|
|
|
|
|
|
|
BEGIN { |
13
|
8
|
|
|
8
|
|
27
|
$VERSION = '1.05_01'; |
14
|
8
|
|
|
|
|
162
|
@ISA = 'Exporter'; |
15
|
8
|
|
|
|
|
39
|
@EXPORT_OK = qw( |
16
|
|
|
|
|
|
|
clear_warnings |
17
|
|
|
|
|
|
|
had_no_warnings |
18
|
|
|
|
|
|
|
warnings |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Do we add the warning test at the end? |
22
|
8
|
|
|
|
|
5490
|
$do_end_test = 0; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $TEST = Test::Builder->new; |
26
|
|
|
|
|
|
|
my $PID = $$; |
27
|
|
|
|
|
|
|
my @WARNINGS = (); |
28
|
|
|
|
|
|
|
my $EARLY = 0; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$SIG{__WARN__} = make_catcher(\@WARNINGS); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import { |
33
|
7
|
|
|
7
|
|
53
|
$do_end_test = 1; |
34
|
7
|
50
|
|
|
|
19
|
if ( grep { $_ eq ':early' } @_ ) { |
|
11
|
|
|
|
|
48
|
|
35
|
0
|
|
|
|
|
0
|
@_ = grep { $_ ne ':early' } @_; |
|
0
|
|
|
|
|
0
|
|
36
|
0
|
|
|
|
|
0
|
$EARLY = 1; |
37
|
|
|
|
|
|
|
} |
38
|
7
|
|
|
|
|
9536
|
goto &Exporter::import; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# the END block must be after the "use Test::Builder" to make sure it runs |
42
|
|
|
|
|
|
|
# before Test::Builder's end block |
43
|
|
|
|
|
|
|
# only run the test if there have been other tests |
44
|
|
|
|
|
|
|
END { |
45
|
7
|
100
|
|
7
|
|
13329
|
had_no_warnings() if $do_end_test; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make_warning { |
49
|
4
|
|
|
4
|
0
|
12
|
local $SIG{__WARN__}; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
9
|
my $msg = shift; |
52
|
4
|
|
|
|
|
20
|
my $warning = Test::NoWarnings::Warning->new; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
17
|
$warning->setMessage($msg); |
55
|
4
|
|
|
|
|
14
|
$warning->fillTest($TEST); |
56
|
4
|
|
|
|
|
13
|
$warning->fillTrace(__PACKAGE__); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
7
|
$Carp::Internal{__PACKAGE__.""}++; |
59
|
4
|
|
|
|
|
10
|
local $Carp::CarpLevel = $Carp::CarpLevel + 1; |
60
|
4
|
|
|
|
|
11
|
$warning->fillCarp($msg); |
61
|
4
|
|
|
|
|
9
|
$Carp::Internal{__PACKAGE__.""}--; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
14
|
return $warning; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# this make a subroutine which can be used in $SIG{__WARN__} |
67
|
|
|
|
|
|
|
# it takes one argument, a ref to an array |
68
|
|
|
|
|
|
|
# it will push the details of the warning onto the end of the array. |
69
|
|
|
|
|
|
|
sub make_catcher { |
70
|
8
|
|
|
8
|
0
|
15
|
my $array = shift; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return sub { |
73
|
4
|
|
|
4
|
|
2913
|
my $msg = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Generate the warning |
76
|
4
|
|
|
|
|
12
|
$Carp::Internal{__PACKAGE__.""}++; |
77
|
4
|
|
|
|
|
11
|
push(@$array, make_warning($msg)); |
78
|
4
|
|
|
|
|
11
|
$Carp::Internal{__PACKAGE__.""}--; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Show the diag early rather than at the end |
81
|
4
|
50
|
|
|
|
13
|
if ( $EARLY ) { |
82
|
0
|
|
|
|
|
0
|
$TEST->diag( $array->[-1]->toString ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
180
|
return $msg; |
86
|
8
|
|
|
|
|
83
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub had_no_warnings { |
90
|
11
|
100
|
|
11
|
1
|
3266
|
return 0 if $$ != $PID; |
91
|
|
|
|
|
|
|
|
92
|
10
|
|
|
|
|
34
|
$do_end_test = 0; # for use with done_testing |
93
|
|
|
|
|
|
|
|
94
|
10
|
|
|
|
|
70
|
local $SIG{__WARN__}; |
95
|
10
|
|
100
|
|
|
92
|
my $name = shift || "no warnings"; |
96
|
|
|
|
|
|
|
|
97
|
10
|
|
|
|
|
28
|
my $ok; |
98
|
|
|
|
|
|
|
my $diag; |
99
|
10
|
100
|
|
|
|
60
|
if ( @WARNINGS == 0 ) { |
100
|
7
|
|
|
|
|
34
|
$ok = 1; |
101
|
|
|
|
|
|
|
} else { |
102
|
3
|
|
|
|
|
6
|
$ok = 0; |
103
|
3
|
|
|
|
|
10
|
$diag = "There were " . scalar(@WARNINGS) . " warning(s)\n"; |
104
|
3
|
50
|
|
|
|
9
|
unless ( $EARLY ) { |
105
|
3
|
|
|
|
|
6
|
$diag .= join "----------\n", map { $_->toString } @WARNINGS; |
|
4
|
|
|
|
|
23
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
10
|
100
|
|
|
|
89
|
$TEST->ok($ok, $name) || $TEST->diag($diag); |
110
|
|
|
|
|
|
|
|
111
|
10
|
|
|
|
|
5144
|
return $ok; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub clear_warnings { |
115
|
1
|
|
|
1
|
1
|
1879
|
local $SIG{__WARN__}; |
116
|
1
|
|
|
|
|
9
|
@WARNINGS = (); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub warnings { |
120
|
1
|
|
|
1
|
1
|
3979
|
local $SIG{__WARN__}; |
121
|
1
|
|
|
|
|
5
|
return @WARNINGS; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub builder { |
125
|
2
|
|
|
2
|
0
|
233
|
local $SIG{__WARN__}; |
126
|
2
|
50
|
|
|
|
10
|
if ( @_ ) { |
127
|
2
|
|
|
|
|
6
|
$TEST = shift; |
128
|
|
|
|
|
|
|
} |
129
|
2
|
|
|
|
|
8
|
return $TEST; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |