line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NoWarnings; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
153613
|
use 5.006; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
233
|
|
4
|
7
|
|
|
7
|
|
37
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
192
|
|
5
|
7
|
|
|
7
|
|
107
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
216
|
|
6
|
7
|
|
|
7
|
|
33
|
use Carp (); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
123
|
|
7
|
7
|
|
|
7
|
|
30
|
use Exporter (); |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
143
|
|
8
|
7
|
|
|
7
|
|
29
|
use Test::Builder (); |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
84
|
|
9
|
7
|
|
|
7
|
|
3398
|
use Test::NoWarnings::Warning (); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
144
|
|
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
|
32
|
use vars qw( $VERSION @EXPORT_OK @ISA $do_end_test ); |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
566
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
7
|
|
|
7
|
|
46
|
$VERSION = '1.04'; |
14
|
7
|
|
|
|
|
101
|
@ISA = 'Exporter'; |
15
|
7
|
|
|
|
|
19
|
@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
|
7
|
|
|
|
|
4270
|
$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
|
6
|
|
|
6
|
|
39
|
$do_end_test = 1; |
34
|
6
|
50
|
|
|
|
11
|
if ( grep { $_ eq ':early' } @_ ) { |
|
9
|
|
|
|
|
39
|
|
35
|
0
|
|
|
|
|
0
|
@_ = grep { $_ ne ':early' } @_; |
|
0
|
|
|
|
|
0
|
|
36
|
0
|
|
|
|
|
0
|
$EARLY = 1; |
37
|
|
|
|
|
|
|
} |
38
|
6
|
|
|
|
|
8097
|
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
|
6
|
50
|
|
6
|
|
6730
|
had_no_warnings() if $do_end_test; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make_warning { |
49
|
4
|
|
|
4
|
0
|
10
|
local $SIG{__WARN__}; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
6
|
my $msg = shift; |
52
|
4
|
|
|
|
|
20
|
my $warning = Test::NoWarnings::Warning->new; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
13
|
$warning->setMessage($msg); |
55
|
4
|
|
|
|
|
11
|
$warning->fillTest($TEST); |
56
|
4
|
|
|
|
|
11
|
$warning->fillTrace(__PACKAGE__); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
5
|
$Carp::Internal{__PACKAGE__.""}++; |
59
|
4
|
|
|
|
|
6
|
local $Carp::CarpLevel = $Carp::CarpLevel + 1; |
60
|
4
|
|
|
|
|
13
|
$warning->fillCarp($msg); |
61
|
4
|
|
|
|
|
5
|
$Carp::Internal{__PACKAGE__.""}--; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
12
|
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
|
7
|
|
|
7
|
0
|
12
|
my $array = shift; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return sub { |
73
|
4
|
|
|
4
|
|
1595
|
my $msg = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Generate the warning |
76
|
4
|
|
|
|
|
9
|
$Carp::Internal{__PACKAGE__.""}++; |
77
|
4
|
|
|
|
|
9
|
push(@$array, make_warning($msg)); |
78
|
4
|
|
|
|
|
6
|
$Carp::Internal{__PACKAGE__.""}--; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Show the diag early rather than at the end |
81
|
4
|
50
|
|
|
|
10
|
if ( $EARLY ) { |
82
|
0
|
|
|
|
|
0
|
$TEST->diag( $array->[-1]->toString ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
92
|
return $msg; |
86
|
7
|
|
|
|
|
53
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub had_no_warnings { |
90
|
11
|
100
|
|
11
|
1
|
1637
|
return 0 if $$ != $PID; |
91
|
|
|
|
|
|
|
|
92
|
10
|
|
|
|
|
336
|
local $SIG{__WARN__}; |
93
|
10
|
|
100
|
|
|
81
|
my $name = shift || "no warnings"; |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
21
|
my $ok; |
96
|
|
|
|
|
|
|
my $diag; |
97
|
10
|
100
|
|
|
|
76
|
if ( @WARNINGS == 0 ) { |
98
|
6
|
|
|
|
|
9
|
$ok = 1; |
99
|
|
|
|
|
|
|
} else { |
100
|
4
|
|
|
|
|
4
|
$ok = 0; |
101
|
4
|
|
|
|
|
9
|
$diag = "There were " . scalar(@WARNINGS) . " warning(s)\n"; |
102
|
4
|
50
|
|
|
|
10
|
unless ( $EARLY ) { |
103
|
4
|
|
|
|
|
6
|
$diag .= join "----------\n", map { $_->toString } @WARNINGS; |
|
6
|
|
|
|
|
19
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
10
|
100
|
|
|
|
63
|
$TEST->ok($ok, $name) || $TEST->diag($diag); |
108
|
|
|
|
|
|
|
|
109
|
10
|
|
|
|
|
2165
|
return $ok; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub clear_warnings { |
113
|
1
|
|
|
1
|
1
|
1206
|
local $SIG{__WARN__}; |
114
|
1
|
|
|
|
|
8
|
@WARNINGS = (); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub warnings { |
118
|
1
|
|
|
1
|
1
|
2239
|
local $SIG{__WARN__}; |
119
|
1
|
|
|
|
|
4
|
return @WARNINGS; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub builder { |
123
|
2
|
|
|
2
|
0
|
48
|
local $SIG{__WARN__}; |
124
|
2
|
50
|
|
|
|
6
|
if ( @_ ) { |
125
|
2
|
|
|
|
|
38
|
$TEST = shift; |
126
|
|
|
|
|
|
|
} |
127
|
2
|
|
|
|
|
7
|
return $TEST; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |