aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-29 18:18:48 +0200
committerGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-29 18:18:48 +0200
commit1eb7912a55921242a379fec76d6b93273ac3260e (patch)
tree26c532e38cde99b34408e2a4146819390e9108d7 /misc
parentf6ffcfd73fc0d0dd731c321efab9a408a176c801 (diff)
W3C validation script.
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/w3c-validator.pl68
1 files changed, 68 insertions, 0 deletions
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";
+ }
+}