Apache-AppCluster
view release on metacpan or search on metacpan
Server/t/lib/Apache/test.pm view on Meta::CPAN
if ($net::httpserver) {
# Validate that the OS knows the name of the server in $net::httpserver
# if 'localhost' is not defined, the tests wouldn't pass
(my $hostname) = ($net::httpserver =~ /(.*?):/);
warn qq{\n*** [Crucial] You must define "$hostname" (e.g. in /etc/hosts) in order for 'make test' to pass\n}
unless gethostbyname $hostname;
}
}
$PERL_DIR = $ENV{PERL_DIR} if exists $ENV{PERL_DIR};
$USE_THREAD = ($Config{extensions} =~ /Thread/) || $Config{usethreads};
$USE_SFIO = (($Config{'usesfio'} || '') eq 'true');
my $Is_Win32 = ($^O eq "MSWin32");
sub WIN32 () { $Is_Win32 };
my $UA;
eval {
require LWP::UserAgent;
$UA = LWP::UserAgent->new;
};
unless (defined &Apache::bootstrap) {
*Apache::bootstrap = sub {};
*Apache::Constants::bootstrap = sub {};
}
sub write_httpd_conf {
my $pkg = shift;
my %args = (conf_file => 't/httpd.conf', @_);
my $DIR = `pwd`; chomp $DIR;
local *CONF;
open CONF, ">$args{conf_file}" or die "Can't create $args{conf_file}: $!";
print CONF <<EOF;
Port $args{port}
User $args{user}
Group $args{group}
ServerName localhost
DocumentRoot $DIR/t
$args{modules}
ErrorLog $DIR/t/error_log
PidFile $DIR/t/httpd.pid
AccessConfig /dev/null
ResourceConfig /dev/null
LockFile $DIR/t/httpd.lock
TypesConfig /dev/null
TransferLog /dev/null
ScoreBoardFile /dev/null
AddType text/html .html
# Look in ./blib/lib
#PerlModule ExtUtils::testlib
<Perl>
use lib "$DIR/blib/lib", "$DIR/t/lib";
</Perl>
$args{include}
EOF
return 1;
}
sub _ask {
# Just a function for asking the user questions
my ($prompt, $default, $mustfind, $canskip) = @_;
my $skip = defined $canskip ? " ('$canskip' to skip)" : '';
my $response;
do {
print "$prompt [$default]$skip: ";
chomp($response = <STDIN>);
$response ||= $default;
} until (!$mustfind || ($response eq $canskip) || (-e $response || !print("$response not found\n")));
return $response;
}
sub get_test_params {
my $pkg = shift;
print("\nFor testing purposes, please give the full path to an httpd\n",
"with mod_perl enabled. The path defaults to \$ENV{APACHE}, if present.");
my %conf;
my $httpd = $ENV{'APACHE'} || which('apache') || which('httpd') || '/usr/lib/httpd/httpd';
$httpd = _ask("\n", $httpd, 1, '!');
if ($httpd eq '!') {
print "Skipping.\n";
return;
}
system "$Config{lns} $httpd t/httpd";
# Default: search for dynamic dependencies if mod_so is present, don't bother otherwise.
my $default = (`t/httpd -l` =~ /mod_so\.c/ ? 'y' : 'n');
if (lc _ask("Search existing config file for dynamic module dependencies?", $default) eq 'y') {
my %compiled;
for (`t/httpd -V`) {
if (/([\w]+)="(.*)"/) {
$compiled{$1} = $2;
}
}
$compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
my $file = _ask(" Config file", $compiled{SERVER_CONFIG_FILE}, 1);
$conf{modules} = $pkg->_read_existing_conf($file);
}
# Get default user (apache doesn't like to run as root, special-case it)
my $defuser = ($< && getpwuid $<) || 'nobody';
$conf{user} = _ask("User to run tests under", $defuser);
( run in 1.219 second using v1.01-cache-2.11-cpan-39bf76dae61 )