- From: Bjoern Hoehrmann <derhoermi@gmx.net>
- Date: Thu, 07 Oct 2004 03:55:40 +0200
- To: public-qa-dev@w3.org
* Bjoern Hoehrmann wrote:
>A script that uses this module would then be able to perform operations
>such as
>
> my $doc = ...->("/");
> is_http200($doc);
> is_wellformed($doc);
> is_valid($doc);
> ...
Here is an example how this could look like:
# test module
package W3C::Markup::Validator::Test;
use strict;
use warnings;
use Test::Builder qw();
use LWP::UserAgent qw();
use URI::QueryParam qw();
use base qw(Exporter);
our @EXPORT = qw(is_http200);
our $CHECK = 'http://validator.w3.org/check';
our $Test = Test::Builder->new;
sub import
{
my $self = shift;
my $call = caller;
$Test->exported_to($call);
$Test->plan(@_);
$self->export_to_level(1, $self, @EXPORT);
}
sub get
{
my $self = {};
my $class = shift;
$self->{uri} = URI->new($CHECK);
$self->{uri}->query_param(@_);
$self->{ua} = LWP::UserAgent->new;
$self->{res} = $self->{ua}->get($self->{uri});
bless $self, $class;
}
sub is_http200
{
my $self = shift;
my $mess = shift || 'Validator returned status 200';
my $code = $self->{res}->code;
if ($code == 200)
{
$Test->ok(1, $mess)
}
else
{
$Test->ok(0, $mess);
$Test->diag("Got status " . $code);
}
}
1;
# test script
package main;
use strict;
use warnings;
use Test::More tests => 2;
import W3C::Markup::Validator::Test;
my $v = W3C::Markup::Validator::Test->get(
uri => "http://www.w3.org"
);
is_http200($v); # or
$v->is_http200;
(s/import/use/ if these are in separate files), this could then be run
using just `perl script` or something like `perl -MTest::Harness -e
"runtests shift" script`. This could then be easily extended, e.g. with
...
sub has_errors
{
my $self = shift;
my $mess = shift || 'Results contain errors';
$Test->like($self->{res}->content, qr/<ol id="errors">/, $mess);
}
...
$v = W3C::Markup::Validator::Test->get( uri => '.../invalid.xhtml' );
...
$v->has_errors;
depending on which checks we want to perform.
Received on Thursday, 7 October 2004 01:56:27 UTC