Hi, Below is a modified diff to allow for preferences to be saved to an Apache::TestConfigData for later use within Apache::Test. In this version, a user can create a $HOME/.apache-test/Apache/TestConfigData.pm to specify the preferences; this will be used, if it exists, before a system Apache::TestConfigData. The diff is applied against the cvs Apache-Test sources; as well, an empty Apache-Test/lib/Apache/TestConfigData.pm file should be created: ======================================================= package Apache::TestConfigData; use strict; use warnings; use vars qw($vars);
$vars = { }; 1; =head1 NAME Apache::TestConfigData - Configuration file for Apache::Test =cut ==================================================================== The intent of how this is supposed to work is in the pod of Apache::TestRun. =================================================================== Index: lib/Apache/TestRun.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v retrieving revision 1.114 diff -u -r1.114 TestRun.pm --- lib/Apache/TestRun.pm 12 Sep 2003 02:21:32 -0000 1.114 +++ lib/Apache/TestRun.pm 24 Sep 2003 21:52:08 -0000 @@ -10,20 +10,24 @@ use Apache::TestRequest (); use Apache::TestHarness (); use Apache::TestTrace; +use Apache::TestUtil qw(expand_path); +use Cwd; 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 qw(dirname); use Config; use constant STARTUP_TIMEOUT => 300; # secs (good for extreme debug cases) + use subs qw(exit_shell exit_perl); 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,9 +59,22 @@ '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), ); +# variables stored in $Apache::TestConfigData::vars +my @data_vars = qw(httpd port user group apxs); +# mapping from $Apache::TestConfigData::vars to $ENV settings +my %vars_to_env = (httpd => 'APACHE', + user => 'APACHE_USER', + group => 'APACHE_GROUP', + apxs => 'APXS', + port => 'APACHE_PORT', + ); +my $IN_APACHE_TEST = in_apache_test(); +my $CONFIG_DATA = config_data(); + sub fixup { #make sure we use an absolute path to perl #else Test::Harness uses the perl in our PATH @@ -407,6 +424,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 +528,10 @@ sub new_test_config { my $self = shift; + for (@data_vars) { + next unless $Apache::TestConfigData::vars->{$_}; + $self->{conf_opts}->{$_} ||= $Apache::TestConfigData::vars->{$_}; + } Apache::TestConfig->new($self->{conf_opts}); } @@ -953,6 +976,102 @@ CORE::exit $_[0]; } +# Are we building things within Apache-Test? +sub in_apache_test { + my $cwd = expand_path(cwd); + return ($cwd =~ m{Apache-Test}) ? 1 : 0; +} + +# 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'; + # XXX $ENV{HOME} isn't propagated in mod_perl + unshift @INC, catdir($ENV{HOME}, '.apache-test') if $ENV{HOME}; + for (@INC) { + my $candidate = catfile($_, 'Apache', $file); + if (-e $candidate) { + eval {require $candidate}; + next if $@; + if (config_has_data()) { + $config = $candidate; + last; + } + } + } + unless ($IN_APACHE_TEST) { + die 'Could not find a valid Apache::TestConfigData' + unless config_has_data(); + } + shift @INC if $ENV{HOME}; + # preferentially use environment variables + for (@data_vars) { + next unless my $value = $ENV{$vars_to_env{$_}}; + $Apache::TestConfigData::vars->{$_} = $value; + } + + return $config; +} + +sub config_has_data { + return ($Apache::TestConfigData::vars and + %{$Apache::TestConfigData::vars}) ? 1 : 0; +} + +sub write_config { + my $self = shift; + my $vars = $self->{test_config}->{vars}; + my $conf_opts = $self->{conf_opts}; + my $config_dump = ''; + if ($vars->{httpd} or $Apache::TestConfigData::vars->{httpd}) { + for (@data_vars) { + next unless my $var = $vars->{$_} || $conf_opts->{$_} || + $Apache::TestConfigData::vars->{$_}; + $config_dump .= qq{ '$_' => } . qq{'$var',\n}; + } + } + my $pkg = << "EOC"; +package Apache::TestConfigData; +use strict; +use warnings; +use vars qw(\$vars); + +\$vars = { +$config_dump +}; +1; + +=head1 NAME + +Apache::TestConfigData - Configuration file for Apache::Test + +=cut +EOC + + my $fh = Symbol::gensym; + my $file; + if ($IN_APACHE_TEST) { + $file = catfile($vars->{top_dir}, 'lib/Apache/TestConfigData.pm'); + die "Cannot open $file: $!" unless (open($fh, ">$file")); + warn "Writing $file.\n"; + print $fh $pkg; + close $fh; + } + + if ($CONFIG_DATA) { + $file = $CONFIG_DATA; + die "Cannot open $file: $!" unless (open($fh, ">$file")); + warn "Writing $file.\n"; + print $fh $pkg; + close $fh; + } + return 1; +} + 1; __END__ @@ -999,5 +1118,42 @@ Notice that the extension is I<.c>, and not I<.so>. +=head1 Saving options + +When C<Apache::Test> is first installed, it will save the +values of C<httpd>, C<port>, C<apxs>, C<user>, and C<group>, +if set, to a configuration file C<Apache::TestConfigData>. +This information will then be used in setting these options +for subsequent uses. + +The values stored in C<Apache::TestConfigData> can be overriden +temporarily either by setting the appropriate environment +variable or by giving the relevant option when the C<TEST> +script is run. If you want to save these options to +C<Apache::TestConfigData>, use the C<-save> flag when +running C<TEST>. + +If you are running C<Apache::Test> as a +user who does not have permission to alter the system +C<Apache::TestConfigData>, you can place your +own private configuration file F<TestConfigData.pm> +under C<$ENV{HOME}/.apache-test/Apache/>, +which C<Apache::Test> will use, if present. An example +of such a configuration file is + + # file $ENV{HOME}/.apache-test/Apache/TestConfigData.pm + package Apache::TestConfigData; + use strict; + use warnings; + use vars qw($vars); + + $vars = { + 'group' => 'me', + 'user' => 'myself', + 'port' => '8529', + 'httpd' => '/usr/local/apache/bin/httpd', + + }; + 1; =cut ======================================================================== -- best regards, randy