Torsten Foertsch wrote:
[...]
Let's start with a short explanation what I was trying to do. I wanted to
test a module with mod_ssl loaded in the first run and without it in the
second one. Hence my TEST.PL looks:

-----------------------------------------
use strict;
use warnings FATAL => 'all';

use lib qw(lib);

use Apache::TestRunPerl ();

my $I=Apache::TestRunPerl->new;

my @[EMAIL PROTECTED];                  # save
$I->run(@ARGV);

@[EMAIL PROTECTED];                     # restore
Apache::TestConfig::autoconfig_skip_module_add('mod_ssl.c');

$I->refresh;

$I->run(@ARGV);
-----------------------------------------

Both test runs work fine if put each in a separate TEST.PL. But I want
them in the same TEST.PL. To recreate the t/conf/httpd.conf between the
runs refresh() is called. Before the second run mod_ssl is skipped from
the configuration.

Now I also have to check whether mod_ssl is loaded from within my tests.
I tried to use need_module() for that.

What happens?

t/conf/httpd.conf is correctly recreated between the runs but
need_module() does not reflect the skipped module.

need_module() works on $cfg->{modules}. Hence this array must not contain
mod_ssl.

How is the configuration built?

I thought that calling t/TEST first inherits the configuration from an
existing httpd.conf and stores it into t/conf/apache_test_config.pm.
Subsequent calls from the actual tests the restore and use the cached
configuration.

But this was wrong particularly for the module list.

Apache::TestConfig::Parse::inherit_load_module() fetches the module list
from an existing httpd.conf. It is called once from t/TEST to generate
t/conf/httpd.conf and once for each test that uses the configuration. For
each test the inherited configuration is the merged with the cached one.
Hence, even if the cached configuration would reflect a skipped module
the one actually used by need_module would not anymore.

To avoid this problem I have introduced a new config attribute "thawed"
that is set in Apache::TestConfig::thaw. If it is set
Apache::TestConfig::Parse::inherit_load_module will immediately return
leaving the cached module list intact. That is not a satisfying solution
because there should be no need to inherit from a httpd.conf for each
test. The cached config should provide any information needed.

But a skipped module is not reflected even in the cached configuration.
The reason is the order of the should_kip_module-test and the inclusion
in the module list (also Apache::TestConfigParse::inherit_load_module).
The patch reverses that order.

The patch is against Apache::Test 1.22 that comes with RC5. All RC5 tests
pass with the patch applied.

I think it is worth to have an interface to do this kind of testing. Or
is there another way to get a module tested both with and without a
particular module loaded?

Of course there is still necessary a check for the compiled-in case.

If it doesn't break existing test suites, I've no problem putting it in. Mind to create a new patch for the latest version? Please observe the coding guidelines (no tabs). Also please add a comment in the code of why you return and document the refresh method giving an example on why and how one may want to use it. Thanks Torsten.


diff -Naur mod_perl-2.0.0-RC5/Apache-Test/lib/Apache/TestConfigParse.pm 
mod_perl-2.0.0-RC5.new/Apache-Test/lib/Apache/TestConfigParse.pm
--- mod_perl-2.0.0-RC5/Apache-Test/lib/Apache/TestConfigParse.pm        
2005-04-14 14:20:29.000000000 +0200
+++ mod_perl-2.0.0-RC5.new/Apache-Test/lib/Apache/TestConfigParse.pm    
2005-04-29 21:03:41.801355900 +0200
@@ -190,6 +190,7 @@
sub inherit_load_module {
    my($self, $c, $directive) = @_;

+    return if( $self->{thawed} );
    for my $args (@{ $c->{$directive} }) {
        my $modname = $args->[0];
        my $file = $self->server_file_rel2abs($args->[1]);
@@ -205,8 +206,6 @@

        $name = $modname_alias{$name} if $modname_alias{$name};

-        # remember all found modules
-        $self->{modules}->{$name} = $file;
        debug "Found: $modname => $name";

        if ($self->should_skip_module($name)) {
@@ -214,6 +213,9 @@
            next;
        }

+        # remember all found modules
+        $self->{modules}->{$name} = $file;
+
        debug "LoadModule $modname $name";

        # sometimes people have broken system-wide httpd.conf files,
diff -Naur mod_perl-2.0.0-RC5/Apache-Test/lib/Apache/TestConfig.pm 
mod_perl-2.0.0-RC5.new/Apache-Test/lib/Apache/TestConfig.pm
--- mod_perl-2.0.0-RC5/Apache-Test/lib/Apache/TestConfig.pm     2005-04-14 
14:20:26.000000000 +0200
+++ mod_perl-2.0.0-RC5.new/Apache-Test/lib/Apache/TestConfig.pm 2005-04-29 
20:58:01.272674035 +0200
@@ -226,6 +226,7 @@
            require "$_/apache_test_config.pm";
            $thaw = 'apache_test_config'->new;
            delete $thaw->{save};
+           $thaw->{thawed}=1;
            #incase class that generated the config was
            #something else, which we can't be sure how to load
            bless $thaw, 'Apache::TestConfig';


--
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Reply via email to