Mailing List Archive

r1522 - in trunk/varnish-tools/regress: . lib/Varnish lib/Varnish/Test lib/Varnish/Test/Report
Author: des
Date: 2007-06-15 11:23:25 +0200 (Fri, 15 Jun 2007)
New Revision: 1522

Added:
trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Report/
trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html
Modified:
trunk/varnish-tools/regress/lib/Varnish/Test.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm
trunk/varnish-tools/regress/varnish-regress.pl
Log:
Add reporting functionality.


Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-15 09:18:06 UTC (rev 1521)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-15 09:23:25 UTC (rev 1522)
@@ -36,6 +36,7 @@

use HTTP::Request;
use HTTP::Response;
+use Time::HiRes qw(gettimeofday tv_interval);

sub new($$) {
my ($this, $engine) = @_;
@@ -113,6 +114,7 @@
if (!@tests) {
@tests = sort grep {/^test(\w+)/} (keys %{ref($self) . '::'});
}
+ $self->{'start'} = [gettimeofday()];
foreach my $method (@tests) {
eval {
$self->{'count'} += 1;
@@ -127,6 +129,7 @@
$self->{'count'}, $method, $@));
}
}
+ $self->{'stop'} = [gettimeofday()];
}

sub run_loop($@) {
@@ -141,6 +144,22 @@
return Varnish::Test::Client->new($self->{'engine'});
}

+sub results($) {
+ my ($self) = @_;
+
+ no strict 'refs';
+ my $name = ${ref($self)."::NAME"} || (split('::', ref($self)))[-1];
+ my $descr = ${ref($self)."::DESCR"} || "N/A";
+ return {
+ 'name' => $name,
+ 'descr' => $descr,
+ 'count' => $self->{'count'},
+ 'pass' => $self->{'successful'},
+ 'fail' => $self->{'failed'},
+ 'time' => tv_interval($self->{'start'}, $self->{'stop'}),
+ };
+}
+
sub ev_client_response($$$) {
my ($self, $client, $response) = @_;


Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm (rev 0)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm 2007-06-15 09:23:25 UTC (rev 1522)
@@ -0,0 +1,44 @@
+#!/usr/bin/perl -w
+#-
+# Copyright (c) 2006 Linpro AS
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer
+# in this position and unchanged.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $Id$
+#
+
+package Varnish::Test::Report::HTML;
+
+use strict;
+
+use base 'Varnish::Test::Report';
+
+sub init($) {
+ my ($self) = @_;
+
+ $self->{'template'} = 'report.html';
+ $self->{'config'}->{'TAG_STYLE'} = 'html';
+}
+
+1;


Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm
___________________________________________________________________
Name: svn:keywords
+ Id

Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html (rev 0)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-06-15 09:23:25 UTC (rev 1522)
@@ -0,0 +1,43 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Varnish test report</title>
+ <meta name="svnid" content="$Id$"/>
+ <style type="text/css">
+ table { border-collapse: collapse; border: none; }
+ td, th { border: thin solid black; padding: 3pt; }
+ th { background-color: #eeeeff; }
+ tr.pass { background-color: #eeffee; }
+ tr.fail { background-color: #ffeeee; }
+ </style>
+ </head>
+ <body>
+ <h1 class="title">Varnish test report</h1>
+ <table>
+ <tr>
+ <th>Name</th>
+ <th>Time</th>
+ <th>Tests</th>
+ <th>Passed</th>
+ <th>Failed</th>
+ <th>Description</th>
+ </tr>
+<!-- FOREACH case = cases -->
+<!-- IF case.pass == case.count -->
+ <tr class="pass">
+<!-- ELSE -->
+ <tr class="fail">
+<!-- END -->
+ <td><!-- case.name --></td>
+ <td><!-- case.time --></td>
+ <td><!-- case.count --></td>
+ <td><!-- case.pass --></td>
+ <td><!-- case.fail --></td>
+ <td><!-- case.descr --></td>
+ </tr>
+<!-- END -->
+ </table>
+ </body>
+</html>


Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html
___________________________________________________________________
Name: svn:keywords
+ Id

Added: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm (rev 0)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm 2007-06-15 09:23:25 UTC (rev 1522)
@@ -0,0 +1,64 @@
+#!/usr/bin/perl -w
+#-
+# Copyright (c) 2006 Linpro AS
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer
+# in this position and unchanged.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $Id$
+#
+
+package Varnish::Test::Report;
+
+use strict;
+
+use Template;
+
+sub new($) {
+ my ($this) = @_;
+ my $class = ref($this) || $this;
+
+ my $self = bless({
+ 'config' => {
+ },
+ 'template' => undef,
+ }, $class);
+
+ ($self->{'config'}->{'INCLUDE_PATH'} = $INC{'Varnish/Test/Report.pm'}) =~ s/\.pm$//;
+
+ $self->init();
+
+ return $self;
+}
+
+sub run($@) {
+ my ($self, @cases) = @_;
+
+ die "No template defined\n"
+ unless defined($self->{'template'});
+ my $template = new Template($self->{'config'});
+ $template->process($self->{'template'}, { 'cases' => \@cases })
+ or die $template->error();
+}
+
+1;


Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm
___________________________________________________________________
Name: svn:keywords
+ Id

Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-15 09:18:06 UTC (rev 1521)
+++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-15 09:23:25 UTC (rev 1522)
@@ -132,4 +132,10 @@
}
}

+sub results($) {
+ my ($self) = @_;
+
+ map { $_->results() } @{$self->{'cases'}};
+}
+
1;

Modified: trunk/varnish-tools/regress/varnish-regress.pl
===================================================================
--- trunk/varnish-tools/regress/varnish-regress.pl 2007-06-15 09:18:06 UTC (rev 1521)
+++ trunk/varnish-tools/regress/varnish-regress.pl 2007-06-15 09:23:25 UTC (rev 1522)
@@ -36,17 +36,20 @@

use Getopt::Long;
use Varnish::Test;
+use Varnish::Test::Report::HTML;

sub usage() {
print STDERR <<EOU;
USAGE:

- $0 CASE1 [ CASE2 ... ]
+ $0 [CASE ...]

- where CASEn is either a full case name or a ticket number
+ where CASE is either a full case name or a ticket number. By
+ default, all available test cases will be run.

Examples:

+ $0
$0 Ticket102
$0 102

@@ -72,10 +75,6 @@
}
$controller->stop_engine();

- foreach my $case (@{$controller->{'cases'}}) {
- (my $name = ref($case)) =~ s/.*://;
-
- printf("%s: Successful: %d Failed: %d\n",
- $name, $case->{'successful'}, $case->{'failed'});
- }
+ my $report = new Varnish::Test::Report::HTML;
+ $report->run($controller->results());
}