You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Fred Moyer <fr...@redhotpenguin.com> on 2010/09/30 03:39:04 UTC
[patch] Apache::Test - taking the pain away
Here's my attempt at removing the interactive and custom config, and
instead gathering all configuration data from the current environment.
It should save us a *huge* amount of support headache, and fixup a
lot of false positive failing tests.
I realize this is an enormous paradigm shift, but I think anyone who
has dealt with Apache::TestConfigData knows the pain of persistent
custom config data doing things that you don't expect. Please take a
look through this patch with an open mind :)
Index: Makefile.PL
===================================================================
--- Makefile.PL (revision 1002818)
+++ Makefile.PL (working copy)
@@ -47,12 +47,10 @@
add_Apache__test_target();
}
-Apache::TestConfig::custom_config_file_stub_write();
-
my @clean_files =
- qw(lib/Apache/TestConfigData.pm
- .mypacklist
+ qw(.mypacklist
t/TEST
+ t/REPORT
Makefile.old
);
Index: MANIFEST
===================================================================
--- MANIFEST (revision 1002545)
+++ MANIFEST (working copy)
@@ -42,15 +42,33 @@
lib/Apache/TestTrace.pm
lib/Apache/TestUtil.pm
lib/Bundle/ApacheTest.pm
-t/TEST.PL
+t/alltest/01bang.t
+t/alltest/all.t
+t/alltest2/01bang.t
+t/alltest2/all.t
t/bad_coding.t
+t/cgi-bin/cookies.pl
t/cgi-bin/cookies.pl.PL
+t/cgi-bin/next_available_port.pl
t/cgi-bin/next_available_port.pl.PL
t/conf/extra.conf.in
+t/conf/modperl_extra.pl.in
t/cookies.t
+t/htdocs/index.html
+t/log_watch.t
+t/more/01testpm.t
+t/more/02testmore.t
+t/more/03testpm.t
+t/more/04testmore.t
+t/more/all.t
t/next_available_port.t
t/ping.t
t/redirect.t
t/request.t
+t/response/TestMore/testmorepm.pm
+t/response/TestMore/testpm.pm
+t/TEST.PL
+
META.yml Module meta-data (added by MakeMaker)
+
Index: lib/Apache/TestRun.pm
===================================================================
--- lib/Apache/TestRun.pm (revision 1002818)
+++ lib/Apache/TestRun.pm (working copy)
@@ -89,7 +89,6 @@
'proxy' => 'proxy requests (default proxy is localhost)',
'trace=T' => 'change tracing default to: warning, notice, ' .
'info, debug, ...',
- 'save' => 'save test paramaters into Apache::TestConfigData',
'one-process' => 'run the server in single process mode',
(map { $_, "\U$_\E url" } @request_opts),
);
@@ -506,13 +505,6 @@
$test_config->generate_httpd_conf;
$test_config->save;
- # custom config save if
- # 1) requested to save
- # 2) no saved config yet
- if ($self->{opts}->{save} or
- !Apache::TestConfig::custom_config_exists()) {
- $test_config->custom_config_save($self->{conf_opts});
- }
}
sub try_exit_opts {
@@ -685,9 +677,6 @@
$self->getopts(\@argv);
- # must be called after getopts so the tracing will be set right
- Apache::TestConfig::custom_config_load();
-
$self->pre_configure();
# can't setup the httpd-specific parts of the config object yet
@@ -1146,44 +1135,6 @@
CORE::exit $_[0];
}
-# successfully abort the test suite execution (to allow automatic
-# tools like CPAN.pm, to continue with installation).
-#
-# if a true value is passed, quit right away
-# otherwise ask the user, if they may want to change their mind which
-# will return them back to where they left
-sub skip_test_suite {
- my $no_doubt = shift;
-
- # we can't prompt when STDIN is not attached to tty, unless we
- # were told that's it OK via env var (in which case some program
- # will feed the interactive prompts). Also skip the prompt if the
- # automated testing environment variable is set.
- unless (-t STDIN || $ENV{APACHE_TEST_INTERACTIVE_PROMPT_OK}
- || !$ENV{AUTOMATED_TESTING} ) {
- $no_doubt = 1;
- }
-
- print qq[
-
-Running the test suite is important to make sure that the module that
-you are about to install works on your system. If you choose not to
-run the test suite and you have a problem using this module, make sure
-to return and run this test suite before reporting any problems to the
-developers of this module.
-
-];
- unless ($no_doubt) {
- my $default = 'No';
- my $prompt = 'Skip the test suite?';
- my $ans = ExtUtils::MakeMaker::prompt($prompt, $default);
- return if lc($ans) =~ /no/;
- }
-
- error "Skipping the test suite execution, while returning success status";
- exit_perl 1;
-}
-
1;
__END__
@@ -1270,153 +1221,4 @@
META: to be completed
-
-
-=head1 Persistent Custom Configuration
-
-When C<Apache::Test> is first installed or used, it will save the
-values of C<httpd>, C<apxs>, C<port>, 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 of
-C<Apache-Test> unless temprorarily overridden, either by setting the
-appropriate environment variable (C<APACHE_TEST_HTTPD>,
-C<APACHE_TEST_APXS>, C<APACHE_TEST_PORT>, C<APACHE_TEST_USER>, and
-C<APACHE_TEST_GROUP>) or by giving the relevant option (C<-httpd>,
-C<-apxs>, C<-port>, C<-user>, and C<-group>) when the C<TEST> script
-is run.
-
-To avoid either using previous persistent configurations or saving
-current configurations, set the C<APACHE_TEST_NO_STICKY_PREFERENCES>
-environment variable to a true value.
-
-Finally it's possible to permanently override the previously saved
-options by passing C<L<-save|/Saving_Custom_Configuration_Options>>.
-
-Here is the algorithm of how and when options are saved for the first
-time and when they are used. We will use a few variables to simplify
-the pseudo-code/pseudo-chart flow:
-
-C<$config_exists> - custom configuration has already been saved, to
-get this setting run C<custom_config_exists()>, which tests whether
-either C<apxs> or C<httpd> values are set. It doesn't check for other
-values, since all we need is C<apxs> or C<httpd> to get the test suite
-running. custom_config_exists() checks in the following order
-F<lib/Apache/TestConfigData.pm> (if during Apache-Test build) ,
-F<~/.apache-test/Apache/TestConfigData.pm> and
-F<Apache/TestConfigData.pm> in the perl's libraries.
-
-C<$config_overriden> - that means that we have either C<apxs> or
-C<httpd> values provided by user, via env vars or command line options.
-
-=over
-
-=item 1 Building Apache-Test or modperl-2.0 (or any other project that
-bundles Apache-Test).
-
- 1) perl Apache-Test/Makefile.PL
- (for bundles top-level Makefile.PL will run this as well)
-
- if $config_exists
- do nothing
- else
- create lib/Apache/TestConfigData.pm w/ empty config: {}
-
- 2) make
-
- 3) make test
-
- if $config_exists
- if $config_overriden
- override saved options (for those that were overriden)
- else
- use saved options
- else
- if $config_overriden
- save them in lib/Apache/TestConfigData.pm
- (which will be installed on 'make install')
- else
- - run interactive prompt for C<httpd> and optionally for C<apxs>
- - save the custom config in lib/Apache/TestConfigData.pm
- - restart the currently run program
-
- modperl-2.0 is a special case in (3). it always overrides 'httpd'
- and 'apxs' settings. Other settings like 'port', can be used from
- the saved config.
-
- 4) make install
-
- if $config_exists only in lib/Apache/TestConfigData.pm
- it will be installed system-wide
- else
- nothing changes (since lib/Apache/TestConfigData.pm won't exist)
-
-=item 2 Testing 3rd party modules (after Apache-Test was installed)
-
-Notice that the following situation is quite possible:
-
- cd Apache-Test
- perl Makefile.PL && make install
-
-so that Apache-Test was installed but no custom configuration saved
-(since its C<make test> wasn't run). In which case the interactive
-configuration should kick in (unless config options were passed) and
-in any case saved once configured.
-
-C<$custom_config_path> - perl's F<Apache/TestConfigData.pm> (at the
-same location as F<Apache/TestConfig.pm>) if that area is writable by
-that user (e.g. perl's lib is not owned by 'root'). If not, in
-F<~/.apache-test/Apache/TestConfigData.pm>.
-
- 1) perl Apache-Test/Makefile.PL
- 2) make
- 3) make test
-
- if $config_exists
- if $config_overriden
- override saved options (for those that were overriden)
- else
- use saved options
- else
- if $config_overriden
- save them in $custom_config_path
- else
- - run interactive prompt for C<httpd> and optionally for C<apxs>
- - save the custom config in $custom_config_path
- - restart the currently run program
-
- 4) make install
-
-=back
-
-
-
-=head2 Saving Custom Configuration Options
-
-If you want to override the existing custom configurations 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
Index: lib/Apache/TestConfig.pm
===================================================================
--- lib/Apache/TestConfig.pm (revision 1002545)
+++ lib/Apache/TestConfig.pm (working copy)
@@ -38,8 +38,6 @@
grep { -e "$_/lib/Apache/TestConfig.pm" }
qw(Apache-Test . .. ../Apache-Test);
-use constant CUSTOM_CONFIG_FILE => 'Apache/TestConfigData.pm';
-
use lib ();
use File::Copy ();
use File::Find qw(finddepth);
@@ -59,18 +57,6 @@
use vars qw(%Usage);
-# variables stored in $Apache::TestConfigData::vars
-my @data_vars_must = qw(httpd apxs);
-my @data_vars_opt = qw(user group port);
-# mapping from $Apache::TestConfigData::vars to $ENV settings
-my %vars_to_env = (
- httpd => 'APACHE_TEST_HTTPD',
- apxs => 'APACHE_TEST_APXS',
- user => 'APACHE_TEST_USER',
- group => 'APACHE_TEST_GROUP',
- port => 'APACHE_TEST_PORT',
-);
-
%Usage = (
top_dir => 'top-level directory (default is $PWD)',
t_dir => 'the t/ test directory (default is $top_dir/t)',
@@ -181,10 +167,6 @@
my $server = ref $self ? $self->server : new_test_server();
- # we don't want to get mp2 preconfigured data in order to be able
- # to get the interactive tests running.
- return undef if $ENV{APACHE_TEST_INTERACTIVE_CONFIG_TEST};
-
# we can't do this if we're using httpd 1.3.X
# even if mod_perl2 is installed on the box
# similarly, we shouldn't be loading mp2 if we're not
@@ -195,6 +177,7 @@
eval {
require Apache2::Build;
} or return;
+
return Apache2::Build->build_config;
}
@@ -264,10 +247,6 @@
}
}
- # custom config options from Apache::TestConfigData
- # again, this should force reconfiguration
- custom_config_add_conf_opts($args);
-
my $self = bless {
clean => {},
vhosts => {},
@@ -298,12 +277,13 @@
#help to find libmodperl.so
unless ($vars->{src_dir}) {
my $src_dir = catfile $vars->{top_dir}, qw(.. src modules perl);
- if (-d $src_dir) {
- $vars->{src_dir} = $src_dir;
- } else {
- $src_dir = catfile $vars->{top_dir}, qw(src modules perl);
- $vars->{src_dir} = $src_dir if -d $src_dir;
- }
+
+ if (-d $src_dir) {
+ $vars->{src_dir} = $src_dir;
+ } else {
+ $src_dir = catfile $vars->{top_dir}, qw(src modules perl);
+ $vars->{src_dir} = $src_dir if -d $src_dir;
+ }
}
$vars->{t_dir} ||= catfile $vars->{top_dir}, 't';
@@ -399,29 +379,18 @@
"bug report";
}
- if ($ENV{APACHE_TEST_NO_STICKY_PREFERENCES}) {
- error "You specified APACHE_TEST_NO_STICKY_PREFERENCES=1 " .
- "in which case you must explicitly specify -httpd " .
- "and/or -apxs options";
- Apache::TestRun::exit_perl(0);
- }
-
$self->clean(1);
- # this method restarts the whole program via exec
- # so it never returns
- $self->custom_config_first_time($self->{vars});
+
+ error "You must explicitly specify -httpd and/or -apxs options, " .
+ "or set \$ENV{APACHE_TEST_HTTPD} and \$ENV{APACHE_TEST_APXS}, " .
+ "or set your \$PATH to include the httpd and apxs binaries.";
+ Apache::TestRun::exit_perl(1);
+
}
else {
debug "Using httpd: $vars->{httpd}";
}
- # if we have gotten that far we know at least about the location
- # of httpd and or apxs, so let's save it if we haven't saved any
- # custom configs yet
- unless (custom_config_exists()) {
- $self->custom_config_save($self->{vars});
- }
-
$self->inherit_config; #see TestConfigParse.pm
$self->configure_httpd_eapi; #must come after inherit_config
@@ -434,7 +403,7 @@
$self->{server}->post_config;
- $self;
+ return $self;
}
sub default_module {
@@ -694,7 +663,7 @@
}
}
- $user;
+ return $user;
}
sub default_serveradmin {
@@ -711,7 +680,18 @@
return $build_config->{MP_APXS};
}
- $ENV{APACHE_TEST_APXS};
+ if ($ENV{APACHE_TEST_APXS}) {
+ return $ENV{APACHE_TEST_APXS};
+ }
+
+ # look in PATH as a last resort
+ if (my $apxs = which('apxs')) {
+ return $apxs;
+ } elsif ($apxs = which('apxs2')) {
+ return $apxs;
+ }
+
+ return;
}
sub default_httpd {
@@ -737,7 +717,22 @@
}
}
- $ENV{APACHE_TEST_HTTPD};
+ if ($ENV{APACHE_TEST_HTTPD}) {
+ return $ENV{APACHE_TEST_HTTPD};
+ }
+
+ # look in PATH as a last resort
+ if (my $httpd = which('httpd')) {
+ return $httpd;
+ } elsif ($httpd = which('httpd2')) {
+ return $httpd;
+ } elsif ($httpd = which('apache')) {
+ return $httpd;
+ } elsif ($httpd = which('apache2')) {
+ return $httpd;
+ }
+
+ return;
}
my $localhost;
@@ -1952,525 +1947,11 @@
return qq["$arg"];
}
-### Permanent custom configuration functions ###
-# determine which configuration file Apache/TestConfigData.pm to use
-# (as there could be several). The order searched is:
-# 1) $ENV{HOME}/.apache-test/
-# 2) in @INC
-my $custom_config_path;
-sub custom_config_path {
-
- return $custom_config_path if $custom_config_path;
-
- my @inc = ();
-
- # XXX $ENV{HOME} isn't propagated in mod_perl
- push @inc, catdir $ENV{HOME}, '.apache-test' if $ENV{HOME};
-
- push @inc, @INC;
-
- for (@inc) {
- my $candidate = File::Spec->rel2abs(catfile $_, CUSTOM_CONFIG_FILE);
- next unless -e $candidate;
- # launder for -T
- ($candidate) = $candidate =~ /^(.*)/;
- return $custom_config_path = $candidate;
- }
-
- return '';
-}
-
-# tries to nuke all occurences of custom config
-# used by things outside the A-T test suite
-sub custom_config_nuke {
- my $cwd = fastcwd();
-
- # 1) create a fake empty (blib/)?lib/Apache/TestConfigData.pm
- # (don't delete it since it may mess up with MakeMaker)
- my $path = catfile $cwd, "lib", Apache::TestConfig::CUSTOM_CONFIG_FILE;
- # overwrite the empty stub
- Apache::TestConfig::custom_config_write($path, '') if -e $path;
-
- $path = catfile $cwd, "blib", "lib",
- Apache::TestConfig::CUSTOM_CONFIG_FILE;
- if (-e $path) {
- my $mode = (stat _)[2];
- my $mode_new = $mode | 0200;
- chmod $mode_new, $path;
- debug "emptying $path";
- Apache::TestConfig::custom_config_write($path, '');
- chmod $mode, $path;
- }
-
- # 2) go through @INC = ~/.apache-test and nuke any occurences of
- # CUSTOM_CONFIG_FILE
- my @inc = ();
-
- push @inc, catdir $ENV{HOME}, '.apache-test' if $ENV{HOME};
-
- push @inc, @INC;
-
- for (@inc) {
- my $victim = File::Spec->rel2abs(catfile $_, CUSTOM_CONFIG_FILE);
- next unless -e $victim;
- debug "unlinking $victim";
- unlink $victim;
- }
-}
-
-sub custom_config_exists {
- # try to load custom config if it wasn't loaded yet (there are
- # many entry points to this API)
- custom_config_load();
-
- # it's enough to check whether we have a custom
- # config for 'httpd' or 'apxs'.
- my $httpd = $Apache::TestConfigData::vars->{httpd} || '';
- return 1 if $httpd && -e $httpd && -x _;
-
- my $apxs = $Apache::TestConfigData::vars->{apxs} || '';
- return 1 if $apxs && -e $apxs && -x _;
-
- return 0;
-}
-
-# to be used only from Apache-Test/Makefile.PL to write the custom
-# configuration module so it'll be copied to blib during 'make' and
-# updated to use custom config data during 'make test' and then
-# installed system-wide via 'make install'
-#
-# it gets written only if the custom configuration didn't exist
-# already
-sub custom_config_file_stub_write {
-
- return if custom_config_exists();
-
- # It doesn't matter whether it gets written under modperl-2.0/lib
- # or Apache-Test/lib root, since Apache::TestRun uses the same
- # logic and will update that file with real config data, which
- # 'make install' will then pick and install system-wide. but
- # remember that $FindBin::Bin is the location of top-level
- # 'Makefile.PL'
- require FindBin; # load it only for this particular use
- my $path = catfile $FindBin::Bin, "lib",
- Apache::TestConfig::CUSTOM_CONFIG_FILE;
-
- # write an empty stub
- Apache::TestConfig::custom_config_write($path, '');
-}
-
-sub custom_config_save {
- my $self = shift;
- my $conf_opts = shift;
-
- if ($ENV{APACHE_TEST_NO_STICKY_PREFERENCES}) {
- debug "APACHE_TEST_NO_STICKY_PREFERENCES=1 => " .
- "skipping save of custom config data";
- return;
- }
-
- my $vars = $self->{vars};
- my $config_dump = '';
-
- # minimum httpd and/or apxs needs to be set
- return 0 unless $vars->{httpd} or $Apache::TestConfigData::vars->{httpd}
- or $vars->{apxs} or $Apache::TestConfigData::vars->{apxs};
-
- # it doesn't matter how these vars were set (httpd may or may not
- # get set using the path to apxs, w/o an explicit -httpd value)
- for (@data_vars_must) {
- next unless my $var = $vars->{$_} || $conf_opts->{$_};
- $config_dump .= qq{ '$_' => '$var',\n};
- }
-
- # save these vars only if they were explicitly set via command line
- # options. For example if someone builds A-T as user 'foo', then
- # installs it as root and we save it, all users will now try to
- # configure under that user 'foo' which won't quite work.
- for (@data_vars_opt) {
- next unless my $var = $conf_opts->{$_};
- $config_dump .= qq{ '$_' => '$var',\n};
- }
-
- if (IS_APACHE_TEST_BUILD) {
- my $path = catfile $vars->{top_dir}, 'lib', CUSTOM_CONFIG_FILE;
- # if it doesn't exist, then we already have a global config file
- # if it does, then we have need to update it and its blib/ copy
- if (-e $path and custom_config_path_is_writable($path)) {
- custom_config_write($path, $config_dump);
- # also update blib/lib, since usually that's the one that
- # appears in @INC when t/TEST is run. and it won't be
- # synced with blib/ unless 'make' was run
- my $blib_path = catfile $vars->{top_dir},
- 'blib', 'lib', CUSTOM_CONFIG_FILE;
- if (-e $blib_path and custom_config_path_is_writable($blib_path)) {
- custom_config_write($blib_path, $config_dump);
- }
- return 1;
- }
- }
-
- my $path;
- if ($path = custom_config_path() ) {
- # do nothing, the config file already exists (global)
- debug "Found custom config '$path'";
- }
- elsif (File::Spec->file_name_is_absolute(__FILE__)) {
- # next try a global location, as if it was configured before
- # Apache::Test's 'make install' (install in the same dir as
- # Apache/TestRun.pm)
- # if the filename is not absolute that means that we are still
- # in Apache-Test build (could just test for IS_APACHE_TEST_BUILD)
- my $base = dirname dirname __FILE__;
- $path = catdir $base, CUSTOM_CONFIG_FILE;
- }
-
- # check whether we can write to the directory of the chosen path
- # (e.g. root-owned directory)
- if ($path and custom_config_path_is_writable($path)) {
- custom_config_write($path, $config_dump);
- return 1;
- }
- # if we have no writable path yet, try to use ~
- elsif ($ENV{HOME}) {
- $path = catfile $ENV{HOME}, '.apache-test', CUSTOM_CONFIG_FILE;
- if ($path and custom_config_path_is_writable($path)) {
- custom_config_write($path, $config_dump);
- return 1;
- }
- }
-
- # XXX: should we croak since we failed to write config
- error "Failed to find a config file to save the custom " .
- "configuration in";
- return 0;
-}
-
-sub custom_config_path_is_writable {
- my $path = shift;
-
- return 0 unless $path;
-
- my $file_created = '';
- my $top_dir_created = '';
- # first make sure that the file is writable if it exists
- # already (it might be non-writable if installed via EU::MM or in
- # blib/)
- if (-e $path) {
- my $mode = (stat _)[2];
- $mode |= 0200;
- chmod $mode, $path; # it's ok if we fail
- # keep it writable if we have changed it from not being one
- # so that custom_config_save will be able to just overwrite it
- }
- else {
- my $dir = dirname $path;
- if ($dir and !-e $dir) {
- my @dirs = File::Path::mkpath($dir, 0, 0755);
- # the top level dir to nuke on cleanup if it was created
- $top_dir_created = shift @dirs if @dirs;
- }
- # not really create yet, but will be in the moment
- $file_created = 1;
- }
-
- # try to open for append (even though it may not exist
- my $fh = Symbol::gensym;
- if (open $fh, ">>$path") {
- close $fh;
- # cleanup if we just created the file
- unlink $path if $file_created;
- File::Path::rmtree([$top_dir_created], 0, 0) if $top_dir_created;
- return 1;
- }
-
- return 0;
-}
-
-sub custom_config_write {
- my($path, $config_dump) = @_;
-
- my $pkg = << "EOC";
-package Apache::TestConfigData;
-
-use strict;
-use warnings;
-
-\$Apache::TestConfigData::vars = {
-$config_dump
-};
-
1;
=head1 NAME
-Apache::TestConfigData - Configuration file for Apache::Test
-
-=cut
-EOC
-
- debug "Writing custom config $path";
- my $dir = dirname $path;
- File::Path::mkpath($dir, 0, 0755) unless -e $dir;
- my $fh = Symbol::gensym;
- open $fh, ">$path" or die "Cannot open $path: $!";
- print $fh $pkg;
- close $fh;
-}
-
-sub custom_config_add_conf_opts {
- my $args = shift;
-
- return unless $Apache::TestConfigData::vars and
- keys %$Apache::TestConfigData::vars;
-
- debug "overlaying custom config data";
-
- # the logic is quite complicated with 'httpd' and 'apxs', since
- # one is enough to run the test suite, and we need to avoid the
- # situation where both are saved in custom config but only one
- # (let's say httpd) is overriden by the command line /env var and
- # a hell may break loose if we take that overriden httpd value and
- # also use apxs from custom config which could point to a different
- # server. So if there is an override of apxs or httpd, do not use
- # the custom config for apxs or httpd.
- my $vars_must_overriden = grep {
- $ENV{ $vars_to_env{$_} } || $args->{$_}
- } @data_vars_must;
-
- # mod_perl 2.0 build always knows the right httpd location (and
- # optionally apxs)
- $vars_must_overriden++ if IS_MOD_PERL_2_BUILD();
-
- unless ($vars_must_overriden) {
- for (@data_vars_must) {
- next unless $Apache::TestConfigData::vars->{$_};
- $args->{$_} = $Apache::TestConfigData::vars->{$_};
- }
- }
-
- for (@data_vars_opt) {
- next unless $Apache::TestConfigData::vars->{$_};
- # env vars override custom config
- my $env_value = $ENV{ $vars_to_env{$_} };
- next unless defined $env_value and length $env_value;
- $args->{$_} ||= $Apache::TestConfigData::vars->{$_};
- }
-}
-
-my $custom_config_loaded = 0;
-sub custom_config_load {
-
- if ($ENV{APACHE_TEST_NO_STICKY_PREFERENCES}) {
- debug "APACHE_TEST_NO_STICKY_PREFERENCES=1 => " .
- "skipping load of custom config data";
- return;
- }
-
- if ($ENV{APACHE_TEST_INTERACTIVE_CONFIG_TEST}) {
- debug "APACHE_TEST_INTERACTIVE_CONFIG_TEST=1 => " .
- "skipping load of custom config data";
- return;
- }
-
- return if $custom_config_loaded;
-
- if (my $custom_config_path = custom_config_path()) {
- debug "loading custom config data from: '$custom_config_path'";
- $custom_config_loaded++;
- require $custom_config_path;
- }
- else {
- debug "no custom config data was loaded";
- }
-}
-
-sub custom_config_first_time {
- my $self = shift;
- my $conf_opts = shift;
-
- # we can't prompt when STDIN is not attached to tty, unless we
- # were told that's it OK via env var (in which case some program
- # will feed the interactive prompts
- unless (-t STDIN || $ENV{APACHE_TEST_INTERACTIVE_PROMPT_OK}) {
- error "STDIN is not attached to tty, skip interactive config";
- Apache::TestRun::skip_test_suite();
- }
-
- my $vars = $self->{vars};
-
- print qq[
-
-We are now going to configure the Apache-Test framework.
-This configuration process needs to be done only once.
-
-];
-
- print qq[
-
-First we need to know where the 'httpd' executable is located.
-If you have more than one Apache server is installed, make sure
-you supply the path to the one you are going to use for testing.
-You can always override this setting at run time via the '-httpd'
-option. For example:
-
- % t/TEST -httpd /path/to/alternative/httpd
-
-or via the environment variable APACHE_TEST_HTTPD. For example:
-
- % APACHE_TEST_HTTPD=/path/to/alternative/httpd t/TEST
-
-If for some reason you want to skip the test suite, type: skip
-];
-
- {
- my %choices = ();
- my @tries = qw(httpd httpd2);
- # Win32 uses Apache not apache
- push @tries, WIN32 ? qw(Apache) : qw(apache);
- for (grep defined $_,
- map({ catfile $vars->{$_}, $vars->{target} } qw(sbindir bindir)),
- $self->default_httpd, which($vars->{target}),
- $ENV{APACHE}, $ENV{APACHE2},
- $ENV{APACHE_TEST_HTTPD}, $ENV{APACHE_TEST_HTTPD2},
- map {which($_)} @tries) {
- $choices{$_}++ if -e $_ && -x _;
- }
- my $optional = 0;
- my $wanted = 'httpd';
- $vars->{$wanted} =
- _custom_config_prompt_path($wanted, \%choices, $optional);
- }
-
- print qq[
-
-Next we need to know where the 'apxs' script is located. This script
-provides a lot of information about the apache installation, and makes
-it easier to find things. However it's not available on all platforms,
-therefore it's optional.
-
-If you don't have it installed it's not a problem. Just press Enter.
-
-Notice that if you have Apache 2.x installed that script could be
-called as 'apxs2'.
-
-If you have more than one Apache server is installed, make sure you
-supply the path to the apxs script you are going to use for testing.
-You can always override this setting at run time via the '-apxs'
-option. For example:
-
- % t/TEST -apxs /path/to/alternative/apxs
-
-or via the environment variable APACHE_TEST_APXS. For example:
-
- % APACHE_TEST_APXS=/path/to/alternative/apxs t/TEST
-
-];
- {
- my %choices = ();
- for (grep defined $_,
- map({ catfile $vars->{$_}, 'apxs' } qw(sbindir bindir)),
- $self->default_apxs,
- $ENV{APXS}, $ENV{APACHE_TEST_APXS}, which('apxs'),
- $ENV{APXS2}, $ENV{APACHE_TEST_APXS2}, which('apxs2')) {
- $choices{$_}++ if -e $_ && -x _;
- }
- my $optional = 1;
- my $wanted = 'apxs';
- $vars->{$wanted} =
- _custom_config_prompt_path($wanted, \%choices, $optional);
- }
-
- $self->custom_config_save($conf_opts);
-
- # we probably could reconfigure on the fly ($self->configure), but
- # the problem is various cached data which won't be refreshed. so
- # the simplest is just to restart the run from scratch
- Apache::TestRun::rerun($vars);
-}
-
-sub _custom_config_prompt_path {
- my($wanted, $rh_choices, $optional) = @_;
-
- my $ans;
- my $default = '';
- my $optional_str = $optional ? " (optional)" : '';
- my $prompt =
- "\nPlease provide a full path to$optional_str '$wanted' executable";
-
- my @choices = ();
- if (%$rh_choices) {
- $prompt .= " or choose from the following options:\n\n";
- my $c = 0;
- for (sort keys %$rh_choices) {
- $c++;
- $prompt .= " [$c] $_\n";
- push @choices, $_;
- }
- $prompt .= " \n";
- $default = 1; # a wild guess
- }
- else {
- $prompt .= ":\n\n";
- }
-
- my $i = 0;
- while (1) {
-
- # prevent infinite loops in smoke tests, only give the user
- # five chances to specify httpd or apxs before giving up
- if ($i++ == 5) {
-
- Apache::TestRun::skip_test_suite('y');
- return;
- }
-
- $ans = ExtUtils::MakeMaker::prompt($prompt, $default);
-
- # strip leading/closing spaces
- $ans =~ s/^\s*|\s*$//g;
-
- # convert the item number to the path
- if ($ans =~ /^(\d+)$/) {
- if ($1 > 0 and $choices[$1-1]) {
- $ans = $choices[$1-1];
- }
- else {
- warn "The choice '$ans' doesn't exist\n";
- next;
- }
- }
-
- if ($optional) {
- return '' unless $ans;
- }
-
- # stop the test suite without an error (so automatic tools
- # like CPAN.pm will be able to continue)
- if (lc($ans) eq 'skip' && !$optional) {
- Apache::TestRun::skip_test_suite();
- next; # in case they change their mind
- }
-
- unless (File::Spec->file_name_is_absolute($ans)) {
- warn "The path '$ans' is not an absolute path. " .
- "Please specify an absolute path\n";
- next;
- }
-
- warn("'$ans' doesn't exist.\n"), next unless -e $ans;
- warn("'$ans' is not a file.\n"), next unless -f _;
- warn("'$ans' is not executable.\n"), next unless -x _;
-
- return $ans;
- }
-}
-
-1;
-
-=head1 NAME
-
Apache::TestConfig -- Test Configuration setup module
=head1 SYNOPSIS
@@ -2605,14 +2086,7 @@
automatically unshift the I<project/lib> directory into C<@INC>, via
the autogenerated I<t/conf/modperl_inc.pl> file.
-=head2 APACHE_TEST_INTERACTIVE_PROMPT_OK
-Normally interactive prompts aren't run when STDIN is not attached to
-a tty. But sometimes there is a program that can answer the prompts
-(e.g. when testing A-T itself). If this variable is true the
-interactive config won't be skipped (if needed).
-
-
=head1 Special Placeholders
When generating configuration files from the I<*.in> templates,
Index: Changes
===================================================================
--- Changes (revision 1002818)
+++ Changes (working copy)
@@ -8,6 +8,10 @@
=item 1.34-dev
+Remove the custom config feature, and instead use inline directives,
+ENV vars, and look for apxs et al in PATH.
+[Fred Moyer]
+
Don't attempt to run the test suite as root. The workarounds needed
to facilitate root testing cause large maintenance costs, and return
no tangible benefits.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [patch] Apache::Test - taking the pain away
Posted by Fred Moyer <fr...@redhotpenguin.com>.
2010/9/30 Torsten Förtsch <to...@gmx.net>:
> On Thursday, September 30, 2010 03:39:04 Fred Moyer wrote:
>> Here's my attempt at removing the interactive and custom config, and
>> instead gathering all configuration data from the current environment.
>
> I like that a lot!
The testmore tests are still skipping unless it is run from the
mod_perl build root. I haven't figured that out yet, but at least
this helps clear the way so we can work on those issues.
>
> Nevertheless, perhaps we should ask on modperl@ or maybe even on users@httpd
> if there is anyone out there using them consciously.
>
> I'll have a closer look on the weekend.
>
> Torsten Förtsch
>
> --
> Need professional modperl support? Hire me! (http://foertsch.name)
>
> Like fantasy? http://kabatinte.net
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [patch] Apache::Test - taking the pain away
Posted by Torsten Förtsch <to...@gmx.net>.
On Thursday, September 30, 2010 03:39:04 Fred Moyer wrote:
> Here's my attempt at removing the interactive and custom config, and
> instead gathering all configuration data from the current environment.
I like that a lot!
Nevertheless, perhaps we should ask on modperl@ or maybe even on users@httpd
if there is anyone out there using them consciously.
I'll have a closer look on the weekend.
Torsten Förtsch
--
Need professional modperl support? Hire me! (http://foertsch.name)
Like fantasy? http://kabatinte.net
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [patch] Apache::Test - taking the pain away
Posted by Fred Moyer <fr...@redhotpenguin.com>.
Note that this will require additional releases of SizeLimit and
Reload to deal with the API change. But it makes the bootstrapping
process a bit simpler also.
On Wed, Sep 29, 2010 at 6:39 PM, Fred Moyer <fr...@redhotpenguin.com> wrote:
> Here's my attempt at removing the interactive and custom config, and
> instead gathering all configuration data from the current environment.
> It should save us a *huge* amount of support headache, and fixup a
> lot of false positive failing tests.
>
> I realize this is an enormous paradigm shift, but I think anyone who
> has dealt with Apache::TestConfigData knows the pain of persistent
> custom config data doing things that you don't expect. Please take a
> look through this patch with an open mind :)
>
> Index: Makefile.PL
> ===================================================================
> --- Makefile.PL (revision 1002818)
> +++ Makefile.PL (working copy)
> @@ -47,12 +47,10 @@
> add_Apache__test_target();
> }
>
> -Apache::TestConfig::custom_config_file_stub_write();
> -
> my @clean_files =
> - qw(lib/Apache/TestConfigData.pm
> - .mypacklist
> + qw(.mypacklist
> t/TEST
> + t/REPORT
> Makefile.old
> );
>
> Index: MANIFEST
> ===================================================================
> --- MANIFEST (revision 1002545)
> +++ MANIFEST (working copy)
> @@ -42,15 +42,33 @@
> lib/Apache/TestTrace.pm
> lib/Apache/TestUtil.pm
> lib/Bundle/ApacheTest.pm
> -t/TEST.PL
> +t/alltest/01bang.t
> +t/alltest/all.t
> +t/alltest2/01bang.t
> +t/alltest2/all.t
> t/bad_coding.t
> +t/cgi-bin/cookies.pl
> t/cgi-bin/cookies.pl.PL
> +t/cgi-bin/next_available_port.pl
> t/cgi-bin/next_available_port.pl.PL
> t/conf/extra.conf.in
> +t/conf/modperl_extra.pl.in
> t/cookies.t
> +t/htdocs/index.html
> +t/log_watch.t
> +t/more/01testpm.t
> +t/more/02testmore.t
> +t/more/03testpm.t
> +t/more/04testmore.t
> +t/more/all.t
> t/next_available_port.t
> t/ping.t
> t/redirect.t
> t/request.t
> +t/response/TestMore/testmorepm.pm
> +t/response/TestMore/testpm.pm
> +t/TEST.PL
>
> +
> META.yml Module meta-data (added by MakeMaker)
> +
> Index: lib/Apache/TestRun.pm
> ===================================================================
> --- lib/Apache/TestRun.pm (revision 1002818)
> +++ lib/Apache/TestRun.pm (working copy)
> @@ -89,7 +89,6 @@
> 'proxy' => 'proxy requests (default proxy is localhost)',
> 'trace=T' => 'change tracing default to: warning, notice, ' .
> 'info, debug, ...',
> - 'save' => 'save test paramaters into Apache::TestConfigData',
> 'one-process' => 'run the server in single process mode',
> (map { $_, "\U$_\E url" } @request_opts),
> );
> @@ -506,13 +505,6 @@
> $test_config->generate_httpd_conf;
> $test_config->save;
>
> - # custom config save if
> - # 1) requested to save
> - # 2) no saved config yet
> - if ($self->{opts}->{save} or
> - !Apache::TestConfig::custom_config_exists()) {
> - $test_config->custom_config_save($self->{conf_opts});
> - }
> }
>
> sub try_exit_opts {
> @@ -685,9 +677,6 @@
>
> $self->getopts(\@argv);
>
> - # must be called after getopts so the tracing will be set right
> - Apache::TestConfig::custom_config_load();
> -
> $self->pre_configure();
>
> # can't setup the httpd-specific parts of the config object yet
> @@ -1146,44 +1135,6 @@
> CORE::exit $_[0];
> }
>
> -# successfully abort the test suite execution (to allow automatic
> -# tools like CPAN.pm, to continue with installation).
> -#
> -# if a true value is passed, quit right away
> -# otherwise ask the user, if they may want to change their mind which
> -# will return them back to where they left
> -sub skip_test_suite {
> - my $no_doubt = shift;
> -
> - # we can't prompt when STDIN is not attached to tty, unless we
> - # were told that's it OK via env var (in which case some program
> - # will feed the interactive prompts). Also skip the prompt if the
> - # automated testing environment variable is set.
> - unless (-t STDIN || $ENV{APACHE_TEST_INTERACTIVE_PROMPT_OK}
> - || !$ENV{AUTOMATED_TESTING} ) {
> - $no_doubt = 1;
> - }
> -
> - print qq[
> -
> -Running the test suite is important to make sure that the module that
> -you are about to install works on your system. If you choose not to
> -run the test suite and you have a problem using this module, make sure
> -to return and run this test suite before reporting any problems to the
> -developers of this module.
> -
> -];
> - unless ($no_doubt) {
> - my $default = 'No';
> - my $prompt = 'Skip the test suite?';
> - my $ans = ExtUtils::MakeMaker::prompt($prompt, $default);
> - return if lc($ans) =~ /no/;
> - }
> -
> - error "Skipping the test suite execution, while returning success status";
> - exit_perl 1;
> -}
> -
> 1;
>
> __END__
> @@ -1270,153 +1221,4 @@
>
> META: to be completed
>
> -
> -
> -=head1 Persistent Custom Configuration
> -
> -When C<Apache::Test> is first installed or used, it will save the
> -values of C<httpd>, C<apxs>, C<port>, 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 of
> -C<Apache-Test> unless temprorarily overridden, either by setting the
> -appropriate environment variable (C<APACHE_TEST_HTTPD>,
> -C<APACHE_TEST_APXS>, C<APACHE_TEST_PORT>, C<APACHE_TEST_USER>, and
> -C<APACHE_TEST_GROUP>) or by giving the relevant option (C<-httpd>,
> -C<-apxs>, C<-port>, C<-user>, and C<-group>) when the C<TEST> script
> -is run.
> -
> -To avoid either using previous persistent configurations or saving
> -current configurations, set the C<APACHE_TEST_NO_STICKY_PREFERENCES>
> -environment variable to a true value.
> -
> -Finally it's possible to permanently override the previously saved
> -options by passing C<L<-save|/Saving_Custom_Configuration_Options>>.
> -
> -Here is the algorithm of how and when options are saved for the first
> -time and when they are used. We will use a few variables to simplify
> -the pseudo-code/pseudo-chart flow:
> -
> -C<$config_exists> - custom configuration has already been saved, to
> -get this setting run C<custom_config_exists()>, which tests whether
> -either C<apxs> or C<httpd> values are set. It doesn't check for other
> -values, since all we need is C<apxs> or C<httpd> to get the test suite
> -running. custom_config_exists() checks in the following order
> -F<lib/Apache/TestConfigData.pm> (if during Apache-Test build) ,
> -F<~/.apache-test/Apache/TestConfigData.pm> and
> -F<Apache/TestConfigData.pm> in the perl's libraries.
> -
> -C<$config_overriden> - that means that we have either C<apxs> or
> -C<httpd> values provided by user, via env vars or command line options.
> -
> -=over
> -
> -=item 1 Building Apache-Test or modperl-2.0 (or any other project that
> -bundles Apache-Test).
> -
> - 1) perl Apache-Test/Makefile.PL
> - (for bundles top-level Makefile.PL will run this as well)
> -
> - if $config_exists
> - do nothing
> - else
> - create lib/Apache/TestConfigData.pm w/ empty config: {}
> -
> - 2) make
> -
> - 3) make test
> -
> - if $config_exists
> - if $config_overriden
> - override saved options (for those that were overriden)
> - else
> - use saved options
> - else
> - if $config_overriden
> - save them in lib/Apache/TestConfigData.pm
> - (which will be installed on 'make install')
> - else
> - - run interactive prompt for C<httpd> and optionally for C<apxs>
> - - save the custom config in lib/Apache/TestConfigData.pm
> - - restart the currently run program
> -
> - modperl-2.0 is a special case in (3). it always overrides 'httpd'
> - and 'apxs' settings. Other settings like 'port', can be used from
> - the saved config.
> -
> - 4) make install
> -
> - if $config_exists only in lib/Apache/TestConfigData.pm
> - it will be installed system-wide
> - else
> - nothing changes (since lib/Apache/TestConfigData.pm won't exist)
> -
> -=item 2 Testing 3rd party modules (after Apache-Test was installed)
> -
> -Notice that the following situation is quite possible:
> -
> - cd Apache-Test
> - perl Makefile.PL && make install
> -
> -so that Apache-Test was installed but no custom configuration saved
> -(since its C<make test> wasn't run). In which case the interactive
> -configuration should kick in (unless config options were passed) and
> -in any case saved once configured.
> -
> -C<$custom_config_path> - perl's F<Apache/TestConfigData.pm> (at the
> -same location as F<Apache/TestConfig.pm>) if that area is writable by
> -that user (e.g. perl's lib is not owned by 'root'). If not, in
> -F<~/.apache-test/Apache/TestConfigData.pm>.
> -
> - 1) perl Apache-Test/Makefile.PL
> - 2) make
> - 3) make test
> -
> - if $config_exists
> - if $config_overriden
> - override saved options (for those that were overriden)
> - else
> - use saved options
> - else
> - if $config_overriden
> - save them in $custom_config_path
> - else
> - - run interactive prompt for C<httpd> and optionally for C<apxs>
> - - save the custom config in $custom_config_path
> - - restart the currently run program
> -
> - 4) make install
> -
> -=back
> -
> -
> -
> -=head2 Saving Custom Configuration Options
> -
> -If you want to override the existing custom configurations 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
> Index: lib/Apache/TestConfig.pm
> ===================================================================
> --- lib/Apache/TestConfig.pm (revision 1002545)
> +++ lib/Apache/TestConfig.pm (working copy)
> @@ -38,8 +38,6 @@
> grep { -e "$_/lib/Apache/TestConfig.pm" }
> qw(Apache-Test . .. ../Apache-Test);
>
> -use constant CUSTOM_CONFIG_FILE => 'Apache/TestConfigData.pm';
> -
> use lib ();
> use File::Copy ();
> use File::Find qw(finddepth);
> @@ -59,18 +57,6 @@
>
> use vars qw(%Usage);
>
> -# variables stored in $Apache::TestConfigData::vars
> -my @data_vars_must = qw(httpd apxs);
> -my @data_vars_opt = qw(user group port);
> -# mapping from $Apache::TestConfigData::vars to $ENV settings
> -my %vars_to_env = (
> - httpd => 'APACHE_TEST_HTTPD',
> - apxs => 'APACHE_TEST_APXS',
> - user => 'APACHE_TEST_USER',
> - group => 'APACHE_TEST_GROUP',
> - port => 'APACHE_TEST_PORT',
> -);
> -
> %Usage = (
> top_dir => 'top-level directory (default is $PWD)',
> t_dir => 'the t/ test directory (default is $top_dir/t)',
> @@ -181,10 +167,6 @@
>
> my $server = ref $self ? $self->server : new_test_server();
>
> - # we don't want to get mp2 preconfigured data in order to be able
> - # to get the interactive tests running.
> - return undef if $ENV{APACHE_TEST_INTERACTIVE_CONFIG_TEST};
> -
> # we can't do this if we're using httpd 1.3.X
> # even if mod_perl2 is installed on the box
> # similarly, we shouldn't be loading mp2 if we're not
> @@ -195,6 +177,7 @@
> eval {
> require Apache2::Build;
> } or return;
> +
> return Apache2::Build->build_config;
> }
>
> @@ -264,10 +247,6 @@
> }
> }
>
> - # custom config options from Apache::TestConfigData
> - # again, this should force reconfiguration
> - custom_config_add_conf_opts($args);
> -
> my $self = bless {
> clean => {},
> vhosts => {},
> @@ -298,12 +277,13 @@
> #help to find libmodperl.so
> unless ($vars->{src_dir}) {
> my $src_dir = catfile $vars->{top_dir}, qw(.. src modules perl);
> - if (-d $src_dir) {
> - $vars->{src_dir} = $src_dir;
> - } else {
> - $src_dir = catfile $vars->{top_dir}, qw(src modules perl);
> - $vars->{src_dir} = $src_dir if -d $src_dir;
> - }
> +
> + if (-d $src_dir) {
> + $vars->{src_dir} = $src_dir;
> + } else {
> + $src_dir = catfile $vars->{top_dir}, qw(src modules perl);
> + $vars->{src_dir} = $src_dir if -d $src_dir;
> + }
> }
>
> $vars->{t_dir} ||= catfile $vars->{top_dir}, 't';
> @@ -399,29 +379,18 @@
> "bug report";
> }
>
> - if ($ENV{APACHE_TEST_NO_STICKY_PREFERENCES}) {
> - error "You specified APACHE_TEST_NO_STICKY_PREFERENCES=1 " .
> - "in which case you must explicitly specify -httpd " .
> - "and/or -apxs options";
> - Apache::TestRun::exit_perl(0);
> - }
> -
> $self->clean(1);
> - # this method restarts the whole program via exec
> - # so it never returns
> - $self->custom_config_first_time($self->{vars});
> +
> + error "You must explicitly specify -httpd and/or -apxs options, " .
> + "or set \$ENV{APACHE_TEST_HTTPD} and \$ENV{APACHE_TEST_APXS}, " .
> + "or set your \$PATH to include the httpd and apxs binaries.";
> + Apache::TestRun::exit_perl(1);
> +
> }
> else {
> debug "Using httpd: $vars->{httpd}";
> }
>
> - # if we have gotten that far we know at least about the location
> - # of httpd and or apxs, so let's save it if we haven't saved any
> - # custom configs yet
> - unless (custom_config_exists()) {
> - $self->custom_config_save($self->{vars});
> - }
> -
> $self->inherit_config; #see TestConfigParse.pm
> $self->configure_httpd_eapi; #must come after inherit_config
>
> @@ -434,7 +403,7 @@
>
> $self->{server}->post_config;
>
> - $self;
> + return $self;
> }
>
> sub default_module {
> @@ -694,7 +663,7 @@
> }
> }
>
> - $user;
> + return $user;
> }
>
> sub default_serveradmin {
> @@ -711,7 +680,18 @@
> return $build_config->{MP_APXS};
> }
>
> - $ENV{APACHE_TEST_APXS};
> + if ($ENV{APACHE_TEST_APXS}) {
> + return $ENV{APACHE_TEST_APXS};
> + }
> +
> + # look in PATH as a last resort
> + if (my $apxs = which('apxs')) {
> + return $apxs;
> + } elsif ($apxs = which('apxs2')) {
> + return $apxs;
> + }
> +
> + return;
> }
>
> sub default_httpd {
> @@ -737,7 +717,22 @@
> }
> }
>
> - $ENV{APACHE_TEST_HTTPD};
> + if ($ENV{APACHE_TEST_HTTPD}) {
> + return $ENV{APACHE_TEST_HTTPD};
> + }
> +
> + # look in PATH as a last resort
> + if (my $httpd = which('httpd')) {
> + return $httpd;
> + } elsif ($httpd = which('httpd2')) {
> + return $httpd;
> + } elsif ($httpd = which('apache')) {
> + return $httpd;
> + } elsif ($httpd = which('apache2')) {
> + return $httpd;
> + }
> +
> + return;
> }
>
> my $localhost;
> @@ -1952,525 +1947,11 @@
> return qq["$arg"];
> }
>
> -### Permanent custom configuration functions ###
>
> -# determine which configuration file Apache/TestConfigData.pm to use
> -# (as there could be several). The order searched is:
> -# 1) $ENV{HOME}/.apache-test/
> -# 2) in @INC
> -my $custom_config_path;
> -sub custom_config_path {
> -
> - return $custom_config_path if $custom_config_path;
> -
> - my @inc = ();
> -
> - # XXX $ENV{HOME} isn't propagated in mod_perl
> - push @inc, catdir $ENV{HOME}, '.apache-test' if $ENV{HOME};
> -
> - push @inc, @INC;
> -
> - for (@inc) {
> - my $candidate = File::Spec->rel2abs(catfile $_, CUSTOM_CONFIG_FILE);
> - next unless -e $candidate;
> - # launder for -T
> - ($candidate) = $candidate =~ /^(.*)/;
> - return $custom_config_path = $candidate;
> - }
> -
> - return '';
> -}
> -
> -# tries to nuke all occurences of custom config
> -# used by things outside the A-T test suite
> -sub custom_config_nuke {
> - my $cwd = fastcwd();
> -
> - # 1) create a fake empty (blib/)?lib/Apache/TestConfigData.pm
> - # (don't delete it since it may mess up with MakeMaker)
> - my $path = catfile $cwd, "lib", Apache::TestConfig::CUSTOM_CONFIG_FILE;
> - # overwrite the empty stub
> - Apache::TestConfig::custom_config_write($path, '') if -e $path;
> -
> - $path = catfile $cwd, "blib", "lib",
> - Apache::TestConfig::CUSTOM_CONFIG_FILE;
> - if (-e $path) {
> - my $mode = (stat _)[2];
> - my $mode_new = $mode | 0200;
> - chmod $mode_new, $path;
> - debug "emptying $path";
> - Apache::TestConfig::custom_config_write($path, '');
> - chmod $mode, $path;
> - }
> -
> - # 2) go through @INC = ~/.apache-test and nuke any occurences of
> - # CUSTOM_CONFIG_FILE
> - my @inc = ();
> -
> - push @inc, catdir $ENV{HOME}, '.apache-test' if $ENV{HOME};
> -
> - push @inc, @INC;
> -
> - for (@inc) {
> - my $victim = File::Spec->rel2abs(catfile $_, CUSTOM_CONFIG_FILE);
> - next unless -e $victim;
> - debug "unlinking $victim";
> - unlink $victim;
> - }
> -}
> -
> -sub custom_config_exists {
> - # try to load custom config if it wasn't loaded yet (there are
> - # many entry points to this API)
> - custom_config_load();
> -
> - # it's enough to check whether we have a custom
> - # config for 'httpd' or 'apxs'.
> - my $httpd = $Apache::TestConfigData::vars->{httpd} || '';
> - return 1 if $httpd && -e $httpd && -x _;
> -
> - my $apxs = $Apache::TestConfigData::vars->{apxs} || '';
> - return 1 if $apxs && -e $apxs && -x _;
> -
> - return 0;
> -}
> -
> -# to be used only from Apache-Test/Makefile.PL to write the custom
> -# configuration module so it'll be copied to blib during 'make' and
> -# updated to use custom config data during 'make test' and then
> -# installed system-wide via 'make install'
> -#
> -# it gets written only if the custom configuration didn't exist
> -# already
> -sub custom_config_file_stub_write {
> -
> - return if custom_config_exists();
> -
> - # It doesn't matter whether it gets written under modperl-2.0/lib
> - # or Apache-Test/lib root, since Apache::TestRun uses the same
> - # logic and will update that file with real config data, which
> - # 'make install' will then pick and install system-wide. but
> - # remember that $FindBin::Bin is the location of top-level
> - # 'Makefile.PL'
> - require FindBin; # load it only for this particular use
> - my $path = catfile $FindBin::Bin, "lib",
> - Apache::TestConfig::CUSTOM_CONFIG_FILE;
> -
> - # write an empty stub
> - Apache::TestConfig::custom_config_write($path, '');
> -}
> -
> -sub custom_config_save {
> - my $self = shift;
> - my $conf_opts = shift;
> -
> - if ($ENV{APACHE_TEST_NO_STICKY_PREFERENCES}) {
> - debug "APACHE_TEST_NO_STICKY_PREFERENCES=1 => " .
> - "skipping save of custom config data";
> - return;
> - }
> -
> - my $vars = $self->{vars};
> - my $config_dump = '';
> -
> - # minimum httpd and/or apxs needs to be set
> - return 0 unless $vars->{httpd} or $Apache::TestConfigData::vars->{httpd}
> - or $vars->{apxs} or $Apache::TestConfigData::vars->{apxs};
> -
> - # it doesn't matter how these vars were set (httpd may or may not
> - # get set using the path to apxs, w/o an explicit -httpd value)
> - for (@data_vars_must) {
> - next unless my $var = $vars->{$_} || $conf_opts->{$_};
> - $config_dump .= qq{ '$_' => '$var',\n};
> - }
> -
> - # save these vars only if they were explicitly set via command line
> - # options. For example if someone builds A-T as user 'foo', then
> - # installs it as root and we save it, all users will now try to
> - # configure under that user 'foo' which won't quite work.
> - for (@data_vars_opt) {
> - next unless my $var = $conf_opts->{$_};
> - $config_dump .= qq{ '$_' => '$var',\n};
> - }
> -
> - if (IS_APACHE_TEST_BUILD) {
> - my $path = catfile $vars->{top_dir}, 'lib', CUSTOM_CONFIG_FILE;
> - # if it doesn't exist, then we already have a global config file
> - # if it does, then we have need to update it and its blib/ copy
> - if (-e $path and custom_config_path_is_writable($path)) {
> - custom_config_write($path, $config_dump);
> - # also update blib/lib, since usually that's the one that
> - # appears in @INC when t/TEST is run. and it won't be
> - # synced with blib/ unless 'make' was run
> - my $blib_path = catfile $vars->{top_dir},
> - 'blib', 'lib', CUSTOM_CONFIG_FILE;
> - if (-e $blib_path and custom_config_path_is_writable($blib_path)) {
> - custom_config_write($blib_path, $config_dump);
> - }
> - return 1;
> - }
> - }
> -
> - my $path;
> - if ($path = custom_config_path() ) {
> - # do nothing, the config file already exists (global)
> - debug "Found custom config '$path'";
> - }
> - elsif (File::Spec->file_name_is_absolute(__FILE__)) {
> - # next try a global location, as if it was configured before
> - # Apache::Test's 'make install' (install in the same dir as
> - # Apache/TestRun.pm)
> - # if the filename is not absolute that means that we are still
> - # in Apache-Test build (could just test for IS_APACHE_TEST_BUILD)
> - my $base = dirname dirname __FILE__;
> - $path = catdir $base, CUSTOM_CONFIG_FILE;
> - }
> -
> - # check whether we can write to the directory of the chosen path
> - # (e.g. root-owned directory)
> - if ($path and custom_config_path_is_writable($path)) {
> - custom_config_write($path, $config_dump);
> - return 1;
> - }
> - # if we have no writable path yet, try to use ~
> - elsif ($ENV{HOME}) {
> - $path = catfile $ENV{HOME}, '.apache-test', CUSTOM_CONFIG_FILE;
> - if ($path and custom_config_path_is_writable($path)) {
> - custom_config_write($path, $config_dump);
> - return 1;
> - }
> - }
> -
> - # XXX: should we croak since we failed to write config
> - error "Failed to find a config file to save the custom " .
> - "configuration in";
> - return 0;
> -}
> -
> -sub custom_config_path_is_writable {
> - my $path = shift;
> -
> - return 0 unless $path;
> -
> - my $file_created = '';
> - my $top_dir_created = '';
> - # first make sure that the file is writable if it exists
> - # already (it might be non-writable if installed via EU::MM or in
> - # blib/)
> - if (-e $path) {
> - my $mode = (stat _)[2];
> - $mode |= 0200;
> - chmod $mode, $path; # it's ok if we fail
> - # keep it writable if we have changed it from not being one
> - # so that custom_config_save will be able to just overwrite it
> - }
> - else {
> - my $dir = dirname $path;
> - if ($dir and !-e $dir) {
> - my @dirs = File::Path::mkpath($dir, 0, 0755);
> - # the top level dir to nuke on cleanup if it was created
> - $top_dir_created = shift @dirs if @dirs;
> - }
> - # not really create yet, but will be in the moment
> - $file_created = 1;
> - }
> -
> - # try to open for append (even though it may not exist
> - my $fh = Symbol::gensym;
> - if (open $fh, ">>$path") {
> - close $fh;
> - # cleanup if we just created the file
> - unlink $path if $file_created;
> - File::Path::rmtree([$top_dir_created], 0, 0) if $top_dir_created;
> - return 1;
> - }
> -
> - return 0;
> -}
> -
> -sub custom_config_write {
> - my($path, $config_dump) = @_;
> -
> - my $pkg = << "EOC";
> -package Apache::TestConfigData;
> -
> -use strict;
> -use warnings;
> -
> -\$Apache::TestConfigData::vars = {
> -$config_dump
> -};
> -
> 1;
>
> =head1 NAME
>
> -Apache::TestConfigData - Configuration file for Apache::Test
> -
> -=cut
> -EOC
> -
> - debug "Writing custom config $path";
> - my $dir = dirname $path;
> - File::Path::mkpath($dir, 0, 0755) unless -e $dir;
> - my $fh = Symbol::gensym;
> - open $fh, ">$path" or die "Cannot open $path: $!";
> - print $fh $pkg;
> - close $fh;
> -}
> -
> -sub custom_config_add_conf_opts {
> - my $args = shift;
> -
> - return unless $Apache::TestConfigData::vars and
> - keys %$Apache::TestConfigData::vars;
> -
> - debug "overlaying custom config data";
> -
> - # the logic is quite complicated with 'httpd' and 'apxs', since
> - # one is enough to run the test suite, and we need to avoid the
> - # situation where both are saved in custom config but only one
> - # (let's say httpd) is overriden by the command line /env var and
> - # a hell may break loose if we take that overriden httpd value and
> - # also use apxs from custom config which could point to a different
> - # server. So if there is an override of apxs or httpd, do not use
> - # the custom config for apxs or httpd.
> - my $vars_must_overriden = grep {
> - $ENV{ $vars_to_env{$_} } || $args->{$_}
> - } @data_vars_must;
> -
> - # mod_perl 2.0 build always knows the right httpd location (and
> - # optionally apxs)
> - $vars_must_overriden++ if IS_MOD_PERL_2_BUILD();
> -
> - unless ($vars_must_overriden) {
> - for (@data_vars_must) {
> - next unless $Apache::TestConfigData::vars->{$_};
> - $args->{$_} = $Apache::TestConfigData::vars->{$_};
> - }
> - }
> -
> - for (@data_vars_opt) {
> - next unless $Apache::TestConfigData::vars->{$_};
> - # env vars override custom config
> - my $env_value = $ENV{ $vars_to_env{$_} };
> - next unless defined $env_value and length $env_value;
> - $args->{$_} ||= $Apache::TestConfigData::vars->{$_};
> - }
> -}
> -
> -my $custom_config_loaded = 0;
> -sub custom_config_load {
> -
> - if ($ENV{APACHE_TEST_NO_STICKY_PREFERENCES}) {
> - debug "APACHE_TEST_NO_STICKY_PREFERENCES=1 => " .
> - "skipping load of custom config data";
> - return;
> - }
> -
> - if ($ENV{APACHE_TEST_INTERACTIVE_CONFIG_TEST}) {
> - debug "APACHE_TEST_INTERACTIVE_CONFIG_TEST=1 => " .
> - "skipping load of custom config data";
> - return;
> - }
> -
> - return if $custom_config_loaded;
> -
> - if (my $custom_config_path = custom_config_path()) {
> - debug "loading custom config data from: '$custom_config_path'";
> - $custom_config_loaded++;
> - require $custom_config_path;
> - }
> - else {
> - debug "no custom config data was loaded";
> - }
> -}
> -
> -sub custom_config_first_time {
> - my $self = shift;
> - my $conf_opts = shift;
> -
> - # we can't prompt when STDIN is not attached to tty, unless we
> - # were told that's it OK via env var (in which case some program
> - # will feed the interactive prompts
> - unless (-t STDIN || $ENV{APACHE_TEST_INTERACTIVE_PROMPT_OK}) {
> - error "STDIN is not attached to tty, skip interactive config";
> - Apache::TestRun::skip_test_suite();
> - }
> -
> - my $vars = $self->{vars};
> -
> - print qq[
> -
> -We are now going to configure the Apache-Test framework.
> -This configuration process needs to be done only once.
> -
> -];
> -
> - print qq[
> -
> -First we need to know where the 'httpd' executable is located.
> -If you have more than one Apache server is installed, make sure
> -you supply the path to the one you are going to use for testing.
> -You can always override this setting at run time via the '-httpd'
> -option. For example:
> -
> - % t/TEST -httpd /path/to/alternative/httpd
> -
> -or via the environment variable APACHE_TEST_HTTPD. For example:
> -
> - % APACHE_TEST_HTTPD=/path/to/alternative/httpd t/TEST
> -
> -If for some reason you want to skip the test suite, type: skip
> -];
> -
> - {
> - my %choices = ();
> - my @tries = qw(httpd httpd2);
> - # Win32 uses Apache not apache
> - push @tries, WIN32 ? qw(Apache) : qw(apache);
> - for (grep defined $_,
> - map({ catfile $vars->{$_}, $vars->{target} } qw(sbindir bindir)),
> - $self->default_httpd, which($vars->{target}),
> - $ENV{APACHE}, $ENV{APACHE2},
> - $ENV{APACHE_TEST_HTTPD}, $ENV{APACHE_TEST_HTTPD2},
> - map {which($_)} @tries) {
> - $choices{$_}++ if -e $_ && -x _;
> - }
> - my $optional = 0;
> - my $wanted = 'httpd';
> - $vars->{$wanted} =
> - _custom_config_prompt_path($wanted, \%choices, $optional);
> - }
> -
> - print qq[
> -
> -Next we need to know where the 'apxs' script is located. This script
> -provides a lot of information about the apache installation, and makes
> -it easier to find things. However it's not available on all platforms,
> -therefore it's optional.
> -
> -If you don't have it installed it's not a problem. Just press Enter.
> -
> -Notice that if you have Apache 2.x installed that script could be
> -called as 'apxs2'.
> -
> -If you have more than one Apache server is installed, make sure you
> -supply the path to the apxs script you are going to use for testing.
> -You can always override this setting at run time via the '-apxs'
> -option. For example:
> -
> - % t/TEST -apxs /path/to/alternative/apxs
> -
> -or via the environment variable APACHE_TEST_APXS. For example:
> -
> - % APACHE_TEST_APXS=/path/to/alternative/apxs t/TEST
> -
> -];
> - {
> - my %choices = ();
> - for (grep defined $_,
> - map({ catfile $vars->{$_}, 'apxs' } qw(sbindir bindir)),
> - $self->default_apxs,
> - $ENV{APXS}, $ENV{APACHE_TEST_APXS}, which('apxs'),
> - $ENV{APXS2}, $ENV{APACHE_TEST_APXS2}, which('apxs2')) {
> - $choices{$_}++ if -e $_ && -x _;
> - }
> - my $optional = 1;
> - my $wanted = 'apxs';
> - $vars->{$wanted} =
> - _custom_config_prompt_path($wanted, \%choices, $optional);
> - }
> -
> - $self->custom_config_save($conf_opts);
> -
> - # we probably could reconfigure on the fly ($self->configure), but
> - # the problem is various cached data which won't be refreshed. so
> - # the simplest is just to restart the run from scratch
> - Apache::TestRun::rerun($vars);
> -}
> -
> -sub _custom_config_prompt_path {
> - my($wanted, $rh_choices, $optional) = @_;
> -
> - my $ans;
> - my $default = '';
> - my $optional_str = $optional ? " (optional)" : '';
> - my $prompt =
> - "\nPlease provide a full path to$optional_str '$wanted' executable";
> -
> - my @choices = ();
> - if (%$rh_choices) {
> - $prompt .= " or choose from the following options:\n\n";
> - my $c = 0;
> - for (sort keys %$rh_choices) {
> - $c++;
> - $prompt .= " [$c] $_\n";
> - push @choices, $_;
> - }
> - $prompt .= " \n";
> - $default = 1; # a wild guess
> - }
> - else {
> - $prompt .= ":\n\n";
> - }
> -
> - my $i = 0;
> - while (1) {
> -
> - # prevent infinite loops in smoke tests, only give the user
> - # five chances to specify httpd or apxs before giving up
> - if ($i++ == 5) {
> -
> - Apache::TestRun::skip_test_suite('y');
> - return;
> - }
> -
> - $ans = ExtUtils::MakeMaker::prompt($prompt, $default);
> -
> - # strip leading/closing spaces
> - $ans =~ s/^\s*|\s*$//g;
> -
> - # convert the item number to the path
> - if ($ans =~ /^(\d+)$/) {
> - if ($1 > 0 and $choices[$1-1]) {
> - $ans = $choices[$1-1];
> - }
> - else {
> - warn "The choice '$ans' doesn't exist\n";
> - next;
> - }
> - }
> -
> - if ($optional) {
> - return '' unless $ans;
> - }
> -
> - # stop the test suite without an error (so automatic tools
> - # like CPAN.pm will be able to continue)
> - if (lc($ans) eq 'skip' && !$optional) {
> - Apache::TestRun::skip_test_suite();
> - next; # in case they change their mind
> - }
> -
> - unless (File::Spec->file_name_is_absolute($ans)) {
> - warn "The path '$ans' is not an absolute path. " .
> - "Please specify an absolute path\n";
> - next;
> - }
> -
> - warn("'$ans' doesn't exist.\n"), next unless -e $ans;
> - warn("'$ans' is not a file.\n"), next unless -f _;
> - warn("'$ans' is not executable.\n"), next unless -x _;
> -
> - return $ans;
> - }
> -}
> -
> -1;
> -
> -=head1 NAME
> -
> Apache::TestConfig -- Test Configuration setup module
>
> =head1 SYNOPSIS
> @@ -2605,14 +2086,7 @@
> automatically unshift the I<project/lib> directory into C<@INC>, via
> the autogenerated I<t/conf/modperl_inc.pl> file.
>
> -=head2 APACHE_TEST_INTERACTIVE_PROMPT_OK
>
> -Normally interactive prompts aren't run when STDIN is not attached to
> -a tty. But sometimes there is a program that can answer the prompts
> -(e.g. when testing A-T itself). If this variable is true the
> -interactive config won't be skipped (if needed).
> -
> -
> =head1 Special Placeholders
>
> When generating configuration files from the I<*.in> templates,
> Index: Changes
> ===================================================================
> --- Changes (revision 1002818)
> +++ Changes (working copy)
> @@ -8,6 +8,10 @@
>
> =item 1.34-dev
>
> +Remove the custom config feature, and instead use inline directives,
> +ENV vars, and look for apxs et al in PATH.
> +[Fred Moyer]
> +
> Don't attempt to run the test suite as root. The workarounds needed
> to facilitate root testing cause large maintenance costs, and return
> no tangible benefits.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [patch] Apache::Test - taking the pain away
Posted by Torsten Förtsch <to...@gmx.net>.
Hi Fred,
On Thursday, September 30, 2010 03:39:04 Fred Moyer wrote:
> Here's my attempt at removing the interactive and custom config, and
> instead gathering all configuration data from the current environment.
With Test::More 0.96 I get 2 prototype mismatches:
Prototype mismatch: sub Apache::Test::ok ($;$$) vs ($;$) at
/home/r2/work/mp2/trunk/Apache-Test/t/../lib/Apache/Test.pm line 88
Prototype mismatch: sub Apache::Test::skip ($;$$$) vs none at
/home/r2/work/mp2/trunk/Apache-Test/t/../lib/Apache/Test.pm line 88
Then sometimes t/more/03testpm.t fails apparently if it hits the same
interpreter again, see the "ok 2" below where it should read "ok 1".
1..1
# Running under perl version 5.012001 for linux
# Current time local: Mon Oct 4 19:43:03 2010
# Current time GMT: Mon Oct 4 17:43:03 2010
# Using Test.pm version 1.25_02
# Using Apache/Test.pm version 1.34
# testing : called Apache::Test::ok()
# expected: 1
# received: 1
ok 1
ok
t/more/02testmore.t ..
1..2
# Using Apache/Test.pm version 1.34
ok 1 - called Test::More::is()
ok 2 - called Test::More::like()
ok
t/more/03testpm.t ....
1..1
# Using Apache/Test.pm version 1.34
# testing : called Apache::Test::ok()
# expected: 1
# received: 1
ok 2
All 1 subtests passed
t/more/04testmore.t ..
1..2
# Using Apache/Test.pm version 1.34
ok 1 - called Test::More::is()
ok 2 - called Test::More::like()
ok
Torsten Förtsch
--
Need professional modperl support? Hire me! (http://foertsch.name)
Like fantasy? http://kabatinte.net
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org