From 1eb7912a55921242a379fec76d6b93273ac3260e Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 29 Sep 2012 18:18:48 +0200 Subject: W3C validation script. --- misc/w3c-validator.pl | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 misc/w3c-validator.pl (limited to 'misc') diff --git a/misc/w3c-validator.pl b/misc/w3c-validator.pl new file mode 100755 index 0000000..29bfd73 --- /dev/null +++ b/misc/w3c-validator.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +# Usage: w3c-validator.pl /tmp/fpanel/*.html +# +# To generate a bunch of HTML files for the RunModes you want to check, +# add the following to lib/Fripost/Panel/Login.pm +# +# sub cgiapp_postrun { +# my $self = shift; +# my $out = shift; +# unless ($$out eq '') { +# open OUT, '>', "/tmp/fpanel/".$self->get_current_runmode +# .int(rand 65536).'.'.$$.'.html'; +# print OUT $$out; +# close OUT; +# } +# return $out; +# } +# +# cd /opt/fripost-panel/ +# sudo mkdir /tmp/fpanel && sudo chown fpanel:www-data /tmp/fpanel/ +# sudo ./bin/fripost-panel restart +# +# Every HTML page will now be dumped into /tmp/fpanel/. Once you are done +# browsing the RunModes, +# sudo chmod -R +r /tmp/fpanel/ +# ./misc/w3c-validator.pl /tmp/fpanel/*.html +# +# /!\ Note: There is a serious privacy concern here. Do *NOT* forget to /!\ +# /!\ remove the postrun hook once you are done testing the application! /!\ + +use 5.010_000; +use strict; +use warnings; +use utf8; + +use WebService::Validator::HTML::W3C; +my $v = WebService::Validator::HTML::W3C->new( detailed => 1 ); + +foreach my $html (@ARGV) { + die "Error: Cannot read file $html" unless -f $html and -r $html; + $v->validate_file($html) or die "Cannot validate: ", $v->validator_error, "\n"; + + if (defined $v->errors) { + my @errors = @{$v->errors}; + foreach (@errors) { + printf STDERR ( "line: %s, col: %s\n\terror: %s\n", + $_->line, $_->col, + $_->msg ); + } + die "ERR: Cannot validate ".$html.' ('.(1+$#errors)." error(s) found).\n"; + } + elsif (@{$v->warnings}) { + my @warnings = @{$v->warnings}; + foreach (@warnings) { + printf STDERR ( "line: %s, col: %s\n\twarning: %s\n", + $_->line, $_->col, + $_->msg ); + } + die "WARN: Cannot validate ".$html.' ('.(1+$#warnings)." warnings(s) found).\n"; + } + elsif ($v->is_valid) { + print STDERR "Passed: $html\n"; + } + else { + die "A weird thing happened with $html\n"; + } +} -- cgit v1.2.3