comparison tests/html-validator.t @ 138:918bfcb2787e

Added test to validate HTML output.
author Steve Kemp <steve@steve.org.uk>
date Tue, 25 Dec 2007 21:13:03 +0000
parents
children f107f6107ad4
comparison
equal deleted inserted replaced
137:1ae476191bec 138:918bfcb2787e
1 #!/usr/bin/perl -w
2 #
3 # Test that our output is validatored
4 #
5 # Steve
6 # --
7
8
9 use File::Find;
10 use HTML::Lint;
11 use Test::More;
12
13
14 #
15 # Basically this test validates the HTML which would be produced if
16 # a blog is compiled - if one is not present then we have nothing to
17 # validate against.
18 #
19
20 if ( -d "./output/" )
21 {
22 plan no_plan;
23 }
24 else
25 {
26 plan skip_all => 'There is no output directory to validate against!';
27 exit;
28 }
29
30 #
31 # Find all the files beneath the current directory,
32 # and call 'checkFile' with the name.
33 #
34 find( { wanted => \&checkFile, no_chdir => 1 }, './output/' );
35
36
37
38 #
39 # Check a file.
40 #
41 #
42 sub checkFile
43 {
44 # The file.
45 my $file = $File::Find::name;
46
47 # We don't care about directories
48 return if ( ! -f $file );
49
50 # We only care about html files.
51 return if ( $file !~ /\.html$/ );
52
53 my $lint = HTML::Lint->new;
54
55 $lint->parse_file( $file );
56
57 my $error_count = $lint->errors;
58
59 # foreach my $error ( $lint->errors ) {
60 # print $error->as_string, "\n";
61 # }
62
63 is( $error_count, 0 , "There are no errors in $file" );
64 }
65
66
67
68 #
69 # Count and return the number of literal TAB characters contained
70 # in the specified file.
71 #
72 sub countTabCharacters
73 {
74 my ( $file ) = (@_);
75 my $count = 0;
76
77 open( FILE, "<", $file )
78 or die "Cannot open $file - $!";
79 foreach my $line ( <FILE> )
80 {
81 # We will count multiple tab characters in a single line.
82 while( $line =~ /(.*)\t(.*)/ )
83 {
84 $count += 1;
85 $line = $1 . $2;
86 }
87 }
88 close( FILE );
89
90 return( $count );
91 }