[Http-webtest-commits] HTTP-WebTest/lib/HTTP/WebTest SelfTest.pm,NONE,1.1
Brought to you by:
m_ilya,
richardanderson
From: Ilya M. <m_...@pr...> - 2002-11-18 07:45:39
|
Update of /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest In directory sc8-pr-cvs1:/tmp/cvs-serv25517/lib/HTTP/WebTest Added Files: SelfTest.pm Log Message: Added (half finished port of t/config.pl and t/utils.pl) --- NEW FILE: SelfTest.pm --- # $Id: SelfTest.pm,v 1.1 2002/11/18 07:45:36 m_ilya Exp $ package HTTP::WebTest::SelfTest; =head1 NAME HTTP::WebTest::SelfTest - Helper package for HTTP::WebTest test suite =head1 SYNOPSIS use HTTP::WebTest::SelfTest; =head1 DESCRIPTION This module provides helper routines used by L<HTTP::WebTest> self test suite. Plugin writers may find this module useful for implementation of test suites for their plugins. =cut use strict; use base qw(Exporter); =head1 GLOBAL VARIABLES This module imports in namespace of test script following global variables. =cut use vars qw(@EXPORT $HOSTNAME $PORT $URL); @EXPORT = qw($HOSTNAME $PORT $URL); use Sys::Hostname; use URI; use HTTP::WebTest::Utils qw(find_port); =head2 $HOSTNAME The hostname of the test webserver. =cut $HOSTNAME = $ENV{TEST_HOSTNAME} || hostname; =head2 $PORT The port of the test webserver. =cut $PORT = find_port(hostname => $HOSTNAME); die "Can't find free port" unless defined $PORT; =head2 $URL The URL of the test webserer. =cut $URL = "http://$HOSTNAME:$PORT/"; =head1 SUBROUTINES This module imports in namespace of test script following helper subroutines. =head2 abs_url($base, $rel) =head3 Return Returns absolute URL based on pair of base and relative URLs. =cut sub abs_url { my $abs = shift; my $rel = shift; return URI->new_abs($rel, $abs); } =head2 read_file($filename, $ignore_errors) Reads a file. =head3 Parameters =over 4 =item $filename Name of the file. =item $ignore_errors (Optional) If true then open file errors are ignored, otherwise they raise an exception. If omit defaults to true. =back =head3 Returns Whole content of the file as a string. =cut sub read_file { my $filename = shift; my $ignore_errors = shift; local *FILE; if(open FILE, "< $filename") { my $data = join '', <FILE>; close FILE; return $data; } else { die "Can't open file '$filename': $!" unless $ignore_errors; } return ''; } =head2 write_file($filename, $data) Writes into a file. =head3 Parameters =over 4 =item $filename Name of the file. =item $data Data to write into the file. =back =cut sub write_file { my $file = shift; my $data = shift; local *FILE; open FILE, "> $file" or die "Can't open file '$file': $!"; print FILE $data; close FILE; } =head2 check_webtest(%params) Runs a test sequence and compares output with a reference file. =head3 Parameters =over 4 =item webtest => $webtest L<HTTP::WebTest> object to be used for running the test sequence. =item tests => $tests The test sequence. =item tests => $opts The global parameters for the test sequence. =item out_filter => $out_filter =back =cut =head1 COPYRIGHT Copyright (c) 2001-2002 Ilya Martynov. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L<HTTP::WebTest|HTTP::WebTest> L<HTTP::WebTest::API|HTTP::WebTest::API> L<HTTP::WebTest::Plugins|HTTP::WebTest::Plugins> =cut 1; |