line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::HTML::Tidy; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
33163
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
140
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1989
|
use Test::Builder; |
|
3
|
|
|
|
|
16674
|
|
|
3
|
|
|
|
|
79
|
|
6
|
3
|
|
|
3
|
|
31
|
use Exporter; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
262
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2638
|
use HTML::Tidy 1.00; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use vars qw( @ISA $VERSION @EXPORT ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Test::HTML::Tidy - Test::More-style wrapper around HTML::Tidy |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Version 1.28 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$Header: /home/cvs/test-html-tidy/Tidy.pm,v 1.4 2004/02/26 06:12:36 andy Exp $ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$VERSION = '1.00'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $Tester = Test::Builder->new; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Test::HTML::Tidy tests => 4; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $page = build_a_web_page(); |
35
|
|
|
|
|
|
|
html_tidy_ok( $page, 'Built page properly' ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Handy way to check that HTML is valid, according to L<HTML::Tidy>. |
40
|
|
|
|
|
|
|
It is built with L<Test::Builder> and plays happily with L<Test::More> |
41
|
|
|
|
|
|
|
and friends. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
If you are not already familiar with L<Test::More> now would be the time |
44
|
|
|
|
|
|
|
to go take a look. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 EXPORT |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
C<html_tidy_ok> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
@EXPORT = qw( html_tidy_ok ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub import { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
my $pack = caller; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$Tester->exported_to($pack); |
59
|
|
|
|
|
|
|
$Tester->plan(@_); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->export_to_level(1, $self, @EXPORT); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 html_tidy_ok( [$tidy, ] $html, $name ) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Checks to see if C<$html> contains valid HTML. C<$html> being blank is OK. |
67
|
|
|
|
|
|
|
C<$html> being undef is not. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
If you pass an HTML::Tidy object, C<html_tidy_ok()> will use that for its |
70
|
|
|
|
|
|
|
settings. The I<$html> will get passed through I<$tidy>. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $tidy = new HTML::Tidy; |
73
|
|
|
|
|
|
|
$tidy->ignore( type => TIDY_WARNING ); |
74
|
|
|
|
|
|
|
html_tidy_ok( $tidy, $content, "Web page passes without errors" ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Otherwise, C<html_tidy_ok> will use the default rules. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
html_tidy_ok( $content, "Web page passes ALL tests" ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Note that if you pass in your own HTML::Tidy object, C<html_tidy_ok()> |
81
|
|
|
|
|
|
|
will clear its errors before using it. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub html_tidy_ok { |
86
|
|
|
|
|
|
|
my $tidy; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
if ( ref($_[0]) eq "HTML::Tidy" ) { |
89
|
|
|
|
|
|
|
$tidy = shift; |
90
|
|
|
|
|
|
|
$tidy->clear_messages(); |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
$tidy = HTML::Tidy->new; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
my $html = shift; |
95
|
|
|
|
|
|
|
my $name = shift; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $ok = defined $html; |
98
|
|
|
|
|
|
|
if ( !$ok ) { |
99
|
|
|
|
|
|
|
$Tester->ok( 0, $name ); |
100
|
|
|
|
|
|
|
} else { |
101
|
|
|
|
|
|
|
$tidy->parse( $0, $html ); |
102
|
|
|
|
|
|
|
my $nerr = scalar $tidy->messages; |
103
|
|
|
|
|
|
|
$ok = !$nerr; |
104
|
|
|
|
|
|
|
$Tester->ok( $ok, $name ); |
105
|
|
|
|
|
|
|
if ( !$ok ) { |
106
|
|
|
|
|
|
|
my $msg = "Messages:"; |
107
|
|
|
|
|
|
|
$msg .= " $name" if $name; |
108
|
|
|
|
|
|
|
$Tester->diag( $msg ); |
109
|
|
|
|
|
|
|
$Tester->diag( $_->as_string ) for $tidy->messages; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
return $ok; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 Bugs |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
119
|
|
|
|
|
|
|
C<bug-test-html-tidy@rt.cpan.org>, or through the web interface at |
120
|
|
|
|
|
|
|
L<http://rt.cpan.org>. I will be notified, and then you'll automatically |
121
|
|
|
|
|
|
|
be notified of progress on your bug as I make changes. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 Author |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Andy Lester, C<< <andy@petdance.com> >> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 Copyright & License |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Copyright 2004 Andy Lester, All Rights Reserved. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
132
|
|
|
|
|
|
|
under the same terms as Perl itself. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Please note that these modules are not products of or supported by the |
135
|
|
|
|
|
|
|
employers of the various contributors to the code. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |