httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Kobes <ra...@theoryx5.uwinnipeg.ca>
Subject Re: need help to add per-user config to Apache::Test
Date Wed, 03 Sep 2003 15:39:20 GMT
On Tue, 2 Sep 2003, Stas Bekman wrote:

> Randy Kobes wrote:
[ .. ]
> Very good, a few more comments following
>
> > ===========================================================
> > Index: TestRun.pm
> [...]
>  > +    $self->write_config() if
>
> probably better to do that right after $self->configure is
> completed, as the very last thing in:
> Apache::TestRun::configure

OK - this is done in the diff at the end. For this, to
override a setting within Apache::TestConfigData from some
external package, one has to do
   t/TEST -config -save -httpd /usr/local/httpd/bin/httpd

> [...]
> > +use Symbol qw(gensym);
> [...]
> > +    my $fh = Symbol::gensym();
>
> then probably don't need to import it.

Right - thanks.

> > +    my $file = catfile($dir, 'TestConfigData.pm');
> > +    unless (open($fh, ">$file")) {
> > +        warn "Cannot open $file: $!";
> > +        return;
> > +    }
[ .. ]
> Ahm, so you write that file twice if inside the
> Apache-Test build dir because Makefile.PL has been run
> long time ago. We will have problems with MakeMaker
> picking this file for 'make install', so we must provide a
> placeholder for that file. I suppose
> Apache/TestConfigData.pm always needs to be in the
> distribution but include an empty:
>
>    $Apache::TestConfigData = {};
>
> So now instead of trying to eval {} for the module in @_
> we can simply require it, and then test whether
> %$Apache::TestConfigData has something in it?

Good idea - that's much simpler. The following assumes
that an empty Apache/TestConfigData.pm is present, and
then, as you say, 'make install' will pick up any changes
that have been made to it.
===============================================================
Index: lib/Apache/TestRun.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
retrieving revision 1.113
diff -u -r1.113 TestRun.pm
--- lib/Apache/TestRun.pm	22 Jul 2003 11:21:36 -0000	1.113
+++ lib/Apache/TestRun.pm	3 Sep 2003 06:56:29 -0000
@@ -11,10 +11,54 @@
 use Apache::TestHarness ();
 use Apache::TestTrace;

+use constant WIN32 => Apache::TestConfig::WIN32;
+require Win32 if WIN32;
+
+use Cwd;
+# Are we building things within Apache-Test?
+sub in_apache_test {
+    my $cwd =  WIN32 ? Win32::GetLongPathName(cwd) : cwd;
+    return ($cwd =~ m{Apache-Test}) ? 1 : 0;
+}
+use constant IN_APACHE_TEST => in_apache_test();
+
+require File::Spec;
+# routine to determine where the configuration file
+# Apache::TestConfigData lives. The order searched is
+# 1) a path within Apache-Test, if we are building things there
+# 2) an $ENV{HOME}/.apache-test/ directory;
+# 3) somewhere in @INC, other than a path within Apache-Test.
+sub config_data {
+    my $config;
+    my $file = 'TestConfigData.pm';
+    for (@INC) {
+	my $candidate = File::Spec->catfile($_, 'Apache', $file);
+	if (-e $candidate) {
+	    $config = $candidate;
+	    last;
+	}
+    }
+    eval {require $config};
+    return $config if (not $@ and IN_APACHE_TEST);
+    # XXX $HOME isn't propagated in mod_perl
+    if ($ENV{HOME}) {
+	$config = File::Spec->catfile($ENV{HOME},
+				      '.apache-test',
+				      $file);
+        eval {require $config};
+	return $config unless $@;
+    }
+    return $@ ? undef : $config;
+}
+
+use constant CONFIG_DATA => config_data();
+
 use File::Find qw(finddepth);
-use File::Spec::Functions qw(catfile);
+use File::Spec::Functions qw(catfile catdir);
 use Getopt::Long qw(GetOptions);
+use File::Basename;
 use Config;
+use Symbol;

 use constant STARTUP_TIMEOUT => 300; # secs (good for extreme debug cases)
 use subs qw(exit_shell exit_perl);
@@ -23,7 +67,7 @@
 my %original_t_perms = ();

 my @std_run      = qw(start-httpd run-tests stop-httpd);
-my @others       = qw(verbose configure clean help ssl http11);
+my @others       = qw(verbose configure clean help ssl http11 save);
 my @flag_opts    = (@std_run, @others);
 my @string_opts  = qw(order trace);
 my @ostring_opts = qw(proxy ping);
@@ -55,6 +99,7 @@
    'ssl'             => 'run tests through ssl',
    'proxy'           => 'proxy requests (default proxy is localhost)',
    'trace=T'         => 'change tracing default to: warning, notice, info, debug, ...',
+   'save'            => 'save test paramaters into Apache::TestConfigData',
    (map { $_, "\U$_\E url" } @request_opts),
 );

@@ -407,6 +452,8 @@
     $test_config->cmodules_configure;
     $test_config->generate_httpd_conf;
     $test_config->save;
+    $self->write_config() if
+        (IN_APACHE_TEST or $self->{opts}->{save});
 }

 sub try_exit_opts {
@@ -509,6 +556,10 @@

 sub new_test_config {
     my $self = shift;
+    for (qw(httpd port user group apxs)) {
+        next unless $Apache::TestConfigData->{$_};
+        $self->{conf_opts}->{$_} ||= $Apache::TestConfigData->{$_};
+    }
     Apache::TestConfig->new($self->{conf_opts});
 }

@@ -614,6 +665,7 @@
     $self->run_tests;

     $self->stop;
+
 }

 my @oh = qw(jeez golly gosh darn shucks dangit rats nuts dangnabit crap);
@@ -915,6 +967,39 @@
 #    require Carp;
 #    Carp::cluck('exiting');
     CORE::exit $_[0];
+}
+
+sub write_config {
+    my $self = shift;
+    my $fh = Symbol::gensym();
+    my $vars = $self->{test_config}->{vars};
+    my $file = IN_APACHE_TEST ?
+	catfile($vars->{top_dir}, CONFIG_DATA) :
+	CONFIG_DATA;
+    die "Cannot open $file: $!" unless (open($fh, ">$file"));
+    warn "Writing $file.\n";
+    my $config_dump;
+    for (qw(group user apxs port httpd)) {
+        next unless $vars->{$_};
+        $config_dump .= qq{    '$_' => } . qq{'$vars->{$_}',\n};
+    }
+
+    my $pkg = << "EOC";
+package Apache::TestConfigData;
+\$Apache::TestConfigData = {
+$config_dump
+};
+1;
+
+=head1 NAME
+
+Apache::TestConfigData - Configuration file for Apache::Test
+
+=cut
+EOC
+    print $fh $pkg;
+    close $fh;
+    return 1;
 }

 1;
=================================================================

-- 
best regards,
randy

Mime
View raw message