Return-Path: Delivered-To: apmail-httpd-test-dev-archive@www.apache.org Received: (qmail 72776 invoked from network); 3 Sep 2003 16:23:03 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 3 Sep 2003 16:23:03 -0000 Received: (qmail 53885 invoked by uid 500); 3 Sep 2003 16:04:03 -0000 Delivered-To: apmail-httpd-test-dev-archive@httpd.apache.org Received: (qmail 53753 invoked by uid 500); 3 Sep 2003 16:04:01 -0000 Mailing-List: contact test-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: test-dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list test-dev@httpd.apache.org Received: (qmail 53383 invoked from network); 3 Sep 2003 16:03:56 -0000 Received: from unknown (HELO theoryx5.uwinnipeg.ca) (142.132.1.82) by daedalus.apache.org with SMTP; 3 Sep 2003 16:03:55 -0000 Received: from theoryx5.uwinnipeg.ca (localhost.localdomain [127.0.0.1]) by theoryx5.uwinnipeg.ca (8.12.8/8.12.8) with ESMTP id h83FdK8l023204 for ; Wed, 3 Sep 2003 10:39:20 -0500 Received: from localhost (randy@localhost) by theoryx5.uwinnipeg.ca (8.12.8/8.12.8/Submit) with ESMTP id h83FdKpZ023200 for ; Wed, 3 Sep 2003 10:39:20 -0500 Date: Wed, 3 Sep 2003 10:39:20 -0500 (CDT) From: Randy Kobes To: test-dev@httpd.apache.org Subject: Re: need help to add per-user config to Apache::Test In-Reply-To: <3F554304.2050501@stason.org> Message-ID: References: <3F4DBAF5.1000007@stason.org> <3F54FE10.80906@stason.org> <3F554304.2050501@stason.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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