line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Testing; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
HTML::Testing - Test module to make test files simpler. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
A test file, simple.t may be created as follows: |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
print "1..1\n"; |
12
|
|
|
|
|
|
|
use strict; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require HTML::FormatNroff; |
15
|
|
|
|
|
|
|
use HTML::Parse; |
16
|
|
|
|
|
|
|
require HTML::Testing; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $man_date = '20 Dec 97'; |
19
|
|
|
|
|
|
|
my $name = "simple"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $html_source =<
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is the body. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
END_INPUT |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $expected = ".TH \"$name\" \"1\" \"$man_date\" \"FormatNroff\" \n"; |
28
|
|
|
|
|
|
|
$expected .=<
|
29
|
|
|
|
|
|
|
.PP |
30
|
|
|
|
|
|
|
This is the body. |
31
|
|
|
|
|
|
|
END_EXPECTED |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $tester = new HTML::Testing(name => $name, |
34
|
|
|
|
|
|
|
man_date => $man_date, |
35
|
|
|
|
|
|
|
project => 'FormatNroff', |
36
|
|
|
|
|
|
|
man_header => 1, |
37
|
|
|
|
|
|
|
expected => $expected, |
38
|
|
|
|
|
|
|
html_source => $html_source |
39
|
|
|
|
|
|
|
output => 'TestOutput', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
$tester->run_test(); |
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Running the test harness with this will result in the creation of the files |
47
|
|
|
|
|
|
|
simple_expected.out, simple_actual.out and an html file corresponding to the |
48
|
|
|
|
|
|
|
html_source (simple.html). In addition, the |
49
|
|
|
|
|
|
|
test will return 'ok' if they are the same, and 'not ok' if not. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
If the attribute html_file is specified, then html will be sourced from |
52
|
|
|
|
|
|
|
that file instead of html_source, and no html file will be created. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
1
|
|
751
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
57
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
72
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
require HTML::FormatNroffSub; |
60
|
1
|
|
|
1
|
|
|
use HTML::Parse; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use File::Path; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 $testing = new HTML::Testing(); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Create new test. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
|
|
|
|
|
|
my($class, %attr) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $self = bless { |
73
|
|
|
|
|
|
|
name => $attr{'name'}, |
74
|
|
|
|
|
|
|
man_date => $attr{'man_date'}, |
75
|
|
|
|
|
|
|
project => $attr{'project'} || "test", |
76
|
|
|
|
|
|
|
man_header => $attr{'man_header'}, |
77
|
|
|
|
|
|
|
expected => $attr{'expected'}, |
78
|
|
|
|
|
|
|
html_source => $attr{'html_source'}, |
79
|
|
|
|
|
|
|
html_file => $attr{'html_file'}, |
80
|
|
|
|
|
|
|
directory => 'TestOut', |
81
|
|
|
|
|
|
|
}, $class; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
if($self->{'directory'}) { |
84
|
|
|
|
|
|
|
mkpath($self->{'directory'}); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
return $self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 $testing->directory($value); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Set the directory for output (HTML, actual and expected output files) |
92
|
|
|
|
|
|
|
to $value. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub directory { |
97
|
|
|
|
|
|
|
my($self, $value) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$self->{'directory'} = $value; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub create_files { |
103
|
|
|
|
|
|
|
my($self, $actual) = @_; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $dir = $self->{'directory'}; |
106
|
|
|
|
|
|
|
if($dir) { |
107
|
|
|
|
|
|
|
$dir .= '/'; |
108
|
|
|
|
|
|
|
} else { |
109
|
|
|
|
|
|
|
$dir = ''; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
open(FILE, ">${dir}$self->{name}_actual.out"); |
113
|
|
|
|
|
|
|
print FILE $actual; |
114
|
|
|
|
|
|
|
close(FILE); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
open(FILE, ">${dir}$self->{name}_expected.out"); |
117
|
|
|
|
|
|
|
print FILE $self->{'expected'}; |
118
|
|
|
|
|
|
|
close(FILE); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
unless($self->{'html_file'}) { |
121
|
|
|
|
|
|
|
open(FILE, ">${dir}$self->{name}.html"); |
122
|
|
|
|
|
|
|
print FILE $self->{'html_source'}; |
123
|
|
|
|
|
|
|
close(FILE); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 $testing->run_test(); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Run the test. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub run_test { |
134
|
|
|
|
|
|
|
my($self) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $html; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
if($self->{'html_file'}) { |
139
|
|
|
|
|
|
|
print STDERR "Using file $self->{'html_file'}\n"; |
140
|
|
|
|
|
|
|
$html = parse_htmlfile($self->{'html_file'}); |
141
|
|
|
|
|
|
|
} else { |
142
|
|
|
|
|
|
|
$html = parse_html($self->{'html_source'}); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
unless($html) { |
146
|
|
|
|
|
|
|
print STDERR "No HTML?\n"; |
147
|
|
|
|
|
|
|
print "not ok\n"; |
148
|
|
|
|
|
|
|
return; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $formatter = new HTML::FormatNroffSub(name => $self->{'name'}, |
152
|
|
|
|
|
|
|
project => $self->{'project'}, |
153
|
|
|
|
|
|
|
man_date => $self->{'man_date'}, |
154
|
|
|
|
|
|
|
man_header => $self->{'man_header'} |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
my $actual = $formatter->format($html); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$self->create_files($actual); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
if("$actual" ne "$self->{'expected'}") { |
161
|
|
|
|
|
|
|
# print STDERR "Actual=\"\n$actual\n\""; |
162
|
|
|
|
|
|
|
# print STDERR "Expected=\"\n$expected\n\""; |
163
|
|
|
|
|
|
|
print 'not ok'; |
164
|
|
|
|
|
|
|
} else { |
165
|
|
|
|
|
|
|
print 'ok'; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 COPYRIGHT |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright (c) 1997 Frederick Hirsch. All rights reserved. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or |
174
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 AUTHOR |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Frederick Hirsch |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |