Apache-Test
view release on metacpan or search on metacpan
lib/Apache/Test.pm view on Meta::CPAN
elsif ($ref eq 'ARRAY') {
#plan tests $n, [qw(php4 rewrite)];
$meets_condition = need_module($condition);
}
else {
die "don't know how to handle a condition of type $ref";
}
}
else {
# we have the verdict already: true/false
$meets_condition = $condition ? 1 : 0;
}
# trying to emulate a dual variable (ala errno)
unless ($meets_condition) {
my $reason = join ', ',
@SkipReasons ? @SkipReasons : "no reason given";
print "1..0 # skipped: $reason\n";
@SkipReasons = (); # reset
exit; #XXX: Apache->exit
}
}
@SkipReasons = (); # reset
my ($caller,$f,$l)=cp;
%SubTests=();
if (my $subtests=$ENV{HTTPD_TEST_SUBTESTS}) {
%SubTests=map { $_, 1 } split /\s+/, $subtests;
}
if (exists $wtm{$caller} and $wtm{$caller}->[0]==1) { # -withtestmore
Test::More::plan(@_);
}
else { # -withouttestmore
unless (exists $wtm{$caller}) {
warn "You forgot to 'use Apache::Test' in package $caller\n";
$wtm{$caller}=[0,$f,$l];
}
Test::plan(@_);
}
# add to Test.pm verbose output
print "# Using Apache/Test.pm version $VERSION\n";
}
sub need_http11 {
require Apache::TestRequest;
if (Apache::TestRequest::install_http11()) {
return 1;
}
else {
push @SkipReasons,
"LWP version 5.60+ required for HTTP/1.1 support";
return 0;
}
}
sub need_ssl {
my $vars = vars();
need_module([$vars->{ssl_module_name}, 'IO::Socket::SSL']);
}
sub need_lwp {
require Apache::TestRequest;
if (Apache::TestRequest::has_lwp()) {
return 1;
}
else {
push @SkipReasons, "libwww-perl is not installed";
return 0;
}
}
sub need {
my $need_all = 1;
for my $cond (@_) {
if (ref $cond eq 'HASH') {
while (my($reason, $value) = each %$cond) {
$value = $value->() if ref $value eq 'CODE';
next if $value;
push @SkipReasons, $reason;
$need_all = 0;
}
}
elsif ($cond =~ /^(0|1)$/) {
$need_all = 0 if $cond == 0;
}
else {
$need_all = 0 unless need_module($cond);
}
}
return $need_all;
}
sub need_module {
my $cfg = config();
my @modules = grep defined $_,
ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_;
my @reasons = ();
for (@modules) {
if (/^[a-z0-9_.]+$/) {
my $mod = $_;
$mod .= '.c' unless $mod =~ /\.c$/;
next if $cfg->{modules}->{$mod};
$mod = 'mod_' . $mod unless $mod =~ /^mod_/;
next if $cfg->{modules}->{$mod};
if (exists $cfg->{cmodules_disabled}->{$mod}) {
push @reasons, $cfg->{cmodules_disabled}->{$mod};
next;
}
}
die "bogus module name $_" unless /^[\w:.]+$/;
# if the module was explicitly passed with a .c extension,
# do not try to eval it as a Perl module
my $not_found = 1;
unless (/\.c$/) {
( run in 1.553 second using v1.01-cache-2.11-cpan-39bf76dae61 )