line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::HTML::Lint; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
133751
|
use warnings; |
|
6
|
|
|
|
|
28
|
|
|
6
|
|
|
|
|
171
|
|
4
|
6
|
|
|
6
|
|
26
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
113
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
651
|
use Test::Builder; |
|
6
|
|
|
|
|
56482
|
|
|
6
|
|
|
|
|
101
|
|
7
|
6
|
|
|
6
|
|
26
|
use Exporter; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
191
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
1415
|
use HTML::Lint; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
156
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
33
|
use vars qw( @ISA $VERSION @EXPORT ); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2713
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@ISA = qw( HTML::Parser Exporter ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Test::HTML::Lint - Test::More-style wrapper around HTML::Lint |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Version 2.27_03 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = '2.27_03'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $Tester = Test::Builder->new; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Test::HTML::Lint tests => 4; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $table = build_display_table(); |
34
|
|
|
|
|
|
|
html_ok( $table, 'Built display table properly' ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This module provides a few convenience methods for testing exception |
39
|
|
|
|
|
|
|
based code. It is built with L and plays happily with |
40
|
|
|
|
|
|
|
L and friends. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
If you are not already familiar with L now would be the time |
43
|
|
|
|
|
|
|
to go take a look. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 EXPORT |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
C |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
@EXPORT = qw( |
52
|
|
|
|
|
|
|
html_ok |
53
|
|
|
|
|
|
|
html_fragment_ok |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub import { |
57
|
6
|
|
|
6
|
|
49
|
my $self = shift; |
58
|
6
|
|
|
|
|
10
|
my $pack = caller; |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
24
|
$Tester->exported_to($pack); |
61
|
6
|
|
|
|
|
73
|
$Tester->plan(@_); |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
1232
|
$self->export_to_level(1, $self, @EXPORT); |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
6690
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 html_ok( [$lint, ] $html, $name ) |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Checks to see if C<$html> is a valid HTML document, including checks |
71
|
|
|
|
|
|
|
for having C<< >>, C<< >>, C<< > >> and |
72
|
|
|
|
|
|
|
C<< >> tags. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
If you're checking something that is only a fragment of an HTML document, |
75
|
|
|
|
|
|
|
use C. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
If you pass an HTML::Lint object, C will use that for its |
78
|
|
|
|
|
|
|
settings. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $lint = new HTML::Lint( only_types => STRUCTURE ); |
81
|
|
|
|
|
|
|
html_ok( $lint, $content, "Web page passes structural tests only" ); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Otherwise, it will use the default rules. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
html_ok( $content, "Web page passes ALL tests" ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Note that if you pass in your own HTML::Lint object, C |
88
|
|
|
|
|
|
|
will clear its errors before using it. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub html_ok { |
93
|
6
|
|
|
6
|
1
|
3805
|
my $lint; |
94
|
|
|
|
|
|
|
|
95
|
6
|
100
|
|
|
|
31
|
if ( ref($_[0]) eq 'HTML::Lint' ) { |
96
|
1
|
|
|
|
|
2
|
$lint = shift; |
97
|
1
|
|
|
|
|
4
|
$lint->newfile(); |
98
|
1
|
|
|
|
|
3
|
$lint->clear_errors(); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
5
|
|
|
|
|
31
|
$lint = HTML::Lint->new; |
102
|
|
|
|
|
|
|
} |
103
|
6
|
|
|
|
|
12
|
my $html = shift; |
104
|
6
|
|
|
|
|
10
|
my $name = shift; |
105
|
|
|
|
|
|
|
|
106
|
6
|
|
|
|
|
11
|
my $ok = defined $html; |
107
|
6
|
100
|
|
|
|
17
|
if ( !$ok ) { |
108
|
1
|
|
|
|
|
5
|
$Tester->ok( 0, $name ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
5
|
|
|
|
|
17
|
$lint->parse( $html ); |
112
|
5
|
|
|
|
|
27
|
$lint->eof(); |
113
|
5
|
|
|
|
|
19
|
my $nerr = scalar $lint->errors; |
114
|
5
|
|
|
|
|
10
|
$ok = !$nerr; |
115
|
5
|
|
|
|
|
24
|
$Tester->ok( $ok, $name ); |
116
|
5
|
100
|
|
|
|
2818
|
if ( !$ok ) { |
117
|
2
|
|
|
|
|
5
|
my $msg = 'Errors:'; |
118
|
2
|
50
|
|
|
|
5
|
$msg .= " $name" if $name; |
119
|
2
|
|
|
|
|
5
|
$Tester->diag( $msg ); |
120
|
2
|
|
|
|
|
416
|
$Tester->diag( $_->as_string ) for $lint->errors; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
6
|
|
|
|
|
1816
|
return $ok; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 html_fragment_ok( [$lint, ] $html, $name ) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Checks that C<$fragment> is valid HTML, but not necessarily a valid |
131
|
|
|
|
|
|
|
HTML document. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
For example, this is a valid fragment, but not a valid HTML document: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Lorem ipsum |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
because it doesn't contain C<< >> and C<< >> tags. If you |
140
|
|
|
|
|
|
|
want to check that it is a valid document, use C. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
If you pass an HTML::Lint object, C will use that for its |
143
|
|
|
|
|
|
|
settings. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $lint = new HTML::Lint( only_types => STRUCTURE ); |
146
|
|
|
|
|
|
|
html_fragment_ok( $lint, $content, 'Web page passes structural tests only' ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Otherwise, it will use the default rules. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
html_fragment_ok( $content, 'Fragment passes ALL tests' ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Note that if you pass in your own HTML::Lint object, C |
153
|
|
|
|
|
|
|
will clear its errors before using it. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub html_fragment_ok { |
158
|
2
|
|
|
2
|
1
|
4167
|
my $lint; |
159
|
|
|
|
|
|
|
|
160
|
2
|
50
|
|
|
|
6
|
if ( ref($_[0]) eq 'HTML::Lint' ) { |
161
|
0
|
|
|
|
|
0
|
$lint = shift; |
162
|
0
|
|
|
|
|
0
|
$lint->newfile(); |
163
|
0
|
|
|
|
|
0
|
$lint->clear_errors(); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
else { |
166
|
2
|
|
|
|
|
7
|
$lint = HTML::Lint->new; |
167
|
|
|
|
|
|
|
} |
168
|
2
|
|
|
|
|
4
|
my $html = shift; |
169
|
2
|
|
|
|
|
3
|
my $name = shift; |
170
|
|
|
|
|
|
|
|
171
|
2
|
|
|
|
|
4
|
my $ok = defined $html; |
172
|
2
|
50
|
|
|
|
4
|
if ( !$ok ) { |
173
|
0
|
|
|
|
|
0
|
$Tester->ok( 0, $name ); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
else { |
176
|
2
|
|
|
|
|
5
|
$lint->parse( $html ); |
177
|
2
|
|
|
|
|
5
|
$lint->eof(); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Ignore doc-level errors. |
180
|
2
|
|
|
|
|
6
|
my @errors = grep { $_->errcode ne 'doc-tag-required' } $lint->errors; |
|
10
|
|
|
|
|
17
|
|
181
|
|
|
|
|
|
|
|
182
|
2
|
|
|
|
|
3
|
my $nerr = @errors; |
183
|
2
|
|
|
|
|
4
|
$ok = !$nerr; |
184
|
2
|
|
|
|
|
7
|
$Tester->ok( $ok, $name ); |
185
|
2
|
100
|
|
|
|
980
|
if ( !$ok ) { |
186
|
1
|
|
|
|
|
2
|
my $msg = 'Errors:'; |
187
|
1
|
50
|
|
|
|
4
|
$msg .= " $name" if $name; |
188
|
1
|
|
|
|
|
4
|
$Tester->diag( $msg ); |
189
|
1
|
|
|
|
|
241
|
$Tester->diag( $_->as_string ) for @errors; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
2
|
|
|
|
|
201
|
return $ok; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 BUGS |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
All bugs and requests are now being handled through GitHub. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
https://github.com/petdance/html-lint/issues |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
DO NOT send bug reports to http://rt.cpan.org/. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 TO DO |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
There needs to be a C to check that the HTML is a |
209
|
|
|
|
|
|
|
self-contained, well-formed table, and then a comparable one for |
210
|
|
|
|
|
|
|
C. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
If you think this module should do something that it doesn't do at the |
213
|
|
|
|
|
|
|
moment please let me know. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Thanks to chromatic and Michael G Schwern for the excellent Test::Builder, |
218
|
|
|
|
|
|
|
without which this module wouldn't be possible. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Thanks to Adrian Howard for writing Test::Exception, from which most of |
221
|
|
|
|
|
|
|
this module is taken. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright 2005-2017 Andy Lester. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
228
|
|
|
|
|
|
|
it under the terms of the Artistic License v2.0. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
http://www.opensource.org/licenses/Artistic-2.0 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Please note that these modules are not products of or supported by the |
233
|
|
|
|
|
|
|
employers of the various contributors to the code. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 AUTHOR |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Andy Lester, C |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; |