line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NoWarnings; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
529667
|
use 5.006; |
|
8
|
|
|
|
|
95
|
|
4
|
8
|
|
|
8
|
|
42
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
234
|
|
5
|
8
|
|
|
8
|
|
43
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
287
|
|
6
|
8
|
|
|
8
|
|
44
|
use Carp (); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
197
|
|
7
|
8
|
|
|
8
|
|
41
|
use Exporter (); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
172
|
|
8
|
8
|
|
|
8
|
|
48
|
use Test::Builder (); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
172
|
|
9
|
8
|
|
|
8
|
|
3709
|
use Test::NoWarnings::Warning (); |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
609
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our ( $VERSION, @EXPORT_OK, @ISA, $do_end_test ); |
12
|
|
|
|
|
|
|
BEGIN { |
13
|
8
|
|
|
8
|
|
25
|
$VERSION = '1.06'; |
14
|
8
|
|
|
|
|
160
|
@ISA = 'Exporter'; |
15
|
8
|
|
|
|
|
40
|
@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
|
|
|
|
|
5539
|
$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
|
|
|
|
|
49
|
|
35
|
0
|
|
|
|
|
0
|
@_ = grep { $_ ne ':early' } @_; |
|
0
|
|
|
|
|
0
|
|
36
|
0
|
|
|
|
|
0
|
$EARLY = 1; |
37
|
|
|
|
|
|
|
} |
38
|
7
|
|
|
|
|
9174
|
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
|
|
13142
|
had_no_warnings() if $do_end_test; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make_warning { |
49
|
4
|
|
|
4
|
0
|
12
|
local $SIG{__WARN__}; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
8
|
my $msg = shift; |
52
|
4
|
|
|
|
|
21
|
my $warning = Test::NoWarnings::Warning->new; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
16
|
$warning->setMessage($msg); |
55
|
4
|
|
|
|
|
12
|
$warning->fillTest($TEST); |
56
|
4
|
|
|
|
|
11
|
$warning->fillTrace(__PACKAGE__); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
6
|
$Carp::Internal{__PACKAGE__.""}++; |
59
|
4
|
|
|
|
|
8
|
local $Carp::CarpLevel = $Carp::CarpLevel + 1; |
60
|
4
|
|
|
|
|
11
|
$warning->fillCarp($msg); |
61
|
4
|
|
|
|
|
8
|
$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
|
|
3027
|
my $msg = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Generate the warning |
76
|
4
|
|
|
|
|
10
|
$Carp::Internal{__PACKAGE__.""}++; |
77
|
4
|
|
|
|
|
11
|
push(@$array, make_warning($msg)); |
78
|
4
|
|
|
|
|
7
|
$Carp::Internal{__PACKAGE__.""}--; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Show the diag early rather than at the end |
81
|
4
|
50
|
|
|
|
15
|
if ( $EARLY ) { |
82
|
0
|
|
|
|
|
0
|
$TEST->diag( $array->[-1]->toString ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
150
|
return $msg; |
86
|
8
|
|
|
|
|
82
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub had_no_warnings { |
90
|
11
|
100
|
|
11
|
1
|
3238
|
return 0 if $$ != $PID; |
91
|
|
|
|
|
|
|
|
92
|
10
|
|
|
|
|
50
|
$do_end_test = 0; # for use with done_testing |
93
|
|
|
|
|
|
|
|
94
|
10
|
|
|
|
|
73
|
local $SIG{__WARN__}; |
95
|
10
|
|
100
|
|
|
105
|
my $name = shift || "no warnings"; |
96
|
|
|
|
|
|
|
|
97
|
10
|
|
|
|
|
29
|
my $ok; |
98
|
|
|
|
|
|
|
my $diag; |
99
|
10
|
100
|
|
|
|
54
|
if ( @WARNINGS == 0 ) { |
100
|
7
|
|
|
|
|
29
|
$ok = 1; |
101
|
|
|
|
|
|
|
} else { |
102
|
3
|
|
|
|
|
6
|
$ok = 0; |
103
|
3
|
|
|
|
|
11
|
$diag = "There were " . scalar(@WARNINGS) . " warning(s)\n"; |
104
|
3
|
50
|
|
|
|
9
|
unless ( $EARLY ) { |
105
|
3
|
|
|
|
|
8
|
$diag .= join "----------\n", map { $_->toString } @WARNINGS; |
|
4
|
|
|
|
|
11
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
10
|
100
|
|
|
|
88
|
$TEST->ok($ok, $name) || $TEST->diag($diag); |
110
|
|
|
|
|
|
|
|
111
|
10
|
|
|
|
|
5026
|
return $ok; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub clear_warnings { |
115
|
1
|
|
|
1
|
1
|
1851
|
local $SIG{__WARN__}; |
116
|
1
|
|
|
|
|
8
|
@WARNINGS = (); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub warnings { |
120
|
1
|
|
|
1
|
1
|
4159
|
local $SIG{__WARN__}; |
121
|
1
|
|
|
|
|
4
|
return @WARNINGS; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub builder { |
125
|
2
|
|
|
2
|
0
|
187
|
local $SIG{__WARN__}; |
126
|
2
|
50
|
|
|
|
9
|
if ( @_ ) { |
127
|
2
|
|
|
|
|
5
|
$TEST = shift; |
128
|
|
|
|
|
|
|
} |
129
|
2
|
|
|
|
|
7
|
return $TEST; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |