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 Thu, 04 Sep 2003 21:06:06 GMT
On Wed, 3 Sep 2003, Stas Bekman wrote:

> Randy Kobes wrote:
> > On Tue, 2 Sep 2003, Stas Bekman wrote:
[ .. ]
> It should work during 'make test' as well, since it already runs t/TEST
> -config. And also whenever you provide any options to t/TEST it reconfigures,
> so I believe the normal run will do the same:
>
>   t/TEST -save -httpd /usr/local/httpd/bin/httpd
>
> I haven't tested that though.

I've checked that (with the diff below), and it seems to
work now as you say, both within Apache-Test and for a 3rd
party package. Without the -save the new -httpd is used,
but not saved into Apache::TestConfigData.
[ .. ]
> > 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.
>
> If I remember correctly 'make install' will complain about
> the mismatch in sizes since 'make' has already put the
> files into blib? Did it work for you just fine? Purhaps we
> do need to update the two.

On linux, I tried installing Apache-Test, and then changing
the settings via
   t/TEST -save -httpd /path/to/some/other/httpd
This wrote a new lib/Apache/TestConfigData.pm, and
   make install
did recognize the change, copied it over to blib/, and
installed the new copy.

The diff below also includes a change to better get the
location of Apache::TestConfigData.
==============================================================
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	4 Sep 2003 21:02:44 -0000
@@ -11,19 +11,69 @@
 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 $sys_config;
+    my $file = 'TestConfigData.pm';
+    for (@INC) {
+	my $candidate = File::Spec->catfile($_, 'Apache', $file);
+	if (-e $candidate) {
+	    $sys_config = $candidate;
+	    last;
+	}
+    }
+    if ($sys_config) {
+	eval {require $sys_config};
+	return $sys_config if (not $@ and IN_APACHE_TEST);
+	$sys_config = undef if $@;
+    }
+    # XXX $ENV{HOME} isn't propagated in mod_perl
+    if ($ENV{HOME}) {
+	my $priv_config = File::Spec->catfile($ENV{HOME},
+					      '.apache-test',
+					      $file);
+        eval {require $priv_config};
+	return $priv_config unless $@;
+    }
+    return $sys_config ? $sys_config : undef;
+}
+
+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);

+die 'Could not find a suitable Apache::TestConfigData'
+    unless defined CONFIG_DATA;
+
 my %core_files  = ();
 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 +105,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 +458,8 @@
     $test_config->cmodules_configure;
     $test_config->generate_httpd_conf;
     $test_config->save;
+    $self->write_config() if
+        (not %{$Apache::TestConfigData} or $self->{opts}->{save});
 }

 sub try_exit_opts {
@@ -509,6 +562,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 +671,7 @@
     $self->run_tests;

     $self->stop;
+
 }

 my @oh = qw(jeez golly gosh darn shucks dangit rats nuts dangnabit crap);
@@ -915,6 +973,41 @@
 #    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 $conf_opts = $self->{conf_opts};
+    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 = '';
+    if ($self->{test_config}->{vars}->{httpd}) {
+	for (qw(group user apxs port httpd)) {
+	    next unless my $var = $conf_opts->{$_} || $vars->{$_};
+	    $config_dump .= qq{    '$_' => } . qq{'$var',\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 kobes


Mime
View raw message