You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2001/09/10 11:59:03 UTC

failing to require some of the test .pms

OK, so now when bootstrapping is available I'm trying to require all .pm
files in ./t and search for Apache_TEST_CONFIGURE and run it if found.

Index: Apache-Test/lib/Apache/TestConfigPerl.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfigPerl.pm,v
retrieving revision 1.22
diff -u -r1.22 TestConfigPerl.pm
--- Apache-Test/lib/Apache/TestConfigPerl.pm	2001/09/06 05:16:25	1.22
+++ Apache-Test/lib/Apache/TestConfigPerl.pm	2001/09/10 09:53:50
@@ -245,12 +245,21 @@
             my @args;

             my $pm = $_;
-            my $module = catfile $File::Find::dir, $pm;
-            $self->add_module_config($module, \@args);
-            $module = abs2rel $module, $dir;
+            my $file = catfile $File::Find::dir, $pm;
+            $self->add_module_config($file, \@args);
+            my $module = abs2rel $file, $dir;
             $module =~ s,\.pm$,,;
             $module = join '::', splitdir $module;

+            require $file;
+            {
+                no strict 'refs';
+                my $configure_sub = *{$module."::APACHE_TEST_CONFIGURE"}{CODE};
+                if (defined $configure_sub) {
+                    eval {$self->$configure_sub};
+                    warn $@ if $@;
+                }
+            }
             my($base, $sub) =
               map { s/^test//i; $_ } split '::', $module;


require of some test files fails:

----------
TestModules::cgiupload barks at Apache::OK undefined, patched with:

+use Apache::Const -compile => 'OK';

----------
t/response/TestAPI/aplog.pm barks at Apache::LOG_MARK undefined,

I don't know how to make it available at require() time. We explicitly
don't import the APLOG_MARK from Apache headers, but then I cannot find
where it's done. I have found this:

./xs/maps/modperl_functions.map:DEFINE_LOG_MARK   | MPXS_Apache_LOG_MARK       | ...

and these are autogenerated:
./xs/Apache/Log/Apache__Log.h:static XS(MPXS_Apache_LOG_MARK)
./WrapXS/Apache/Log/Log.xs:   cv = newXS("Apache::LOG_MARK", MPXS_Apache_LOG_MARK, __FILE__);

where is the code that does return (__FILE__, __LINE__) ?

----------
t/response/TestAPI/send_fd.pm doesn't have SERVER_ERROR and NOT_FOUND
defined, cured with:

 use Apache::compat ();
+use Apache::Const -compile => ':common';

---------
t/response/TestAPI/sendfile.pm doesn't feach APR::SUCCESS, fixed with:

+ use Apache::Const -compile => ':common';
+ use APR::Const    -compile => 'SUCCESS';

since other constants weren't there too, but it didn't complain about
these.

---------
t/filter/TestFilter/input_body.pm seem not to have attributes inherited
via require()

Invalid CODE attribute: FilterRequestHandler at
/home/stas/apache.org/registry/t/filter/TestFilter/input_body.pm line 15

---------

I've stopped here... cannot get through the last one.

also, does ModPerl::Const::compile accepts only a single arg in the
string on purpose? e.g. it's not possible to say: -compile 'foo bar';

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 11 Sep 2001, Stas Bekman wrote:
 
> ah, OK, now I recall why did we want to have APACHE_TEST_CONFIGURE at the
> test startup time. We want to access the config object. If I use
> Apache::TestUtil I have no access for example to all the dirs. So if I
> want to write some files which rely on the server layout I need to access
> these vars.

there is already read access to these vars, used quite a bit in the *.t
files.

my $config = Apache::TestRequest::test_config();

my $vars = $config->{vars};
or
my $vars = Apache::TestRequest::vars();

i think i'd rather see:
Apache::Test::config();
and
Apache::Test::vars();

but the main thing is to avoid calling Apache::TestConfig->thaw more than
once per-process.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Stas Bekman <st...@stason.org>.
On Mon, 10 Sep 2001, Doug MacEachern wrote:

> On Tue, 11 Sep 2001, Stas Bekman wrote:

> > doh! I didn't expect code in .h :) sure should have checked that. thanks!
>
> most of the xs/ *.h files have code in them.  they are .h because they are
> always #include-d, never compiled into their own object file.  and only
> the file that #include-s a .h file from xs/ should be able to see what's
> in there.  anything else belongs in a src/modules/perl/foo.c public api.

ok.

> > But this can be a problem. Since the file will be in %INC already, it'll
> > keep on using bogus *Apache::LOG_MARK . Unless you actually suggest to
> > implement it in what you've placed as a comment.
>
> it's not a problem in this case, since Apache::LOG_MARK will never be
> called outside of httpd.  it just needs to be defined.  so you could
> actually just do this:
> unless (defined &Apache::LOG_MARK) {
>     *Apache::LOG_MARK = sub {};
> }
>
> > Ditto, the test may not work later, unless we delete $INC{...}
>
> i don't understand the %INC problem you're talking about.  %INC has
> nothing to do with a subroutine being defined or not.

right, I've decided that the files that I require won't be required again.
Of course this is wrong, since they get required again with a new
interpreter when the server is started. Of couse *Apache::LOG_MARK = sub
{}; from above makes sense then. we just need to make require() happy.

> > But can you please explain why require() doesn't work here? Is it because
> > something else happens behind the walls when the server is up?
>
> both are subroutines defined in the .xs which are not bootstrapped outside
> of httpd.

that's clear now.

> > So should I just give up the idea of APACHE_TEST_CONFIGURE and move on
> > with Apache::TestUtil like vhost_alias does?
>
> i think so.

ah, OK, now I recall why did we want to have APACHE_TEST_CONFIGURE at the
test startup time. We want to access the config object. If I use
Apache::TestUtil I have no access for example to all the dirs. So if I
want to write some files which rely on the server layout I need to access
these vars.

May be we should provide a method in Apache::TestUtil that reads the
config vars and makes them available to users of Apache::TestUtil?

> > Let's just think for a sec, whether we may have some other reason for
> > having something like APACHE_TEST_CONFIGURE? Was the creation of the files
> > on the fly the only reason for wanting this?
>
> we can always revisit later if needed.
> would be nice if the .t files do something like this in any case to make
> things clear:
>
> configure();
>
> sub configure {
>     t_mkdir ...;
> }

sure.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 13 Sep 2001, Stas Bekman wrote:
 
> would slurping and matching would be faster?

maybe.  doesn't matter, whatever works is fine for now.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Stas Bekman <st...@stason.org>.
On Wed, 12 Sep 2001, Doug MacEachern wrote:

>
> > $run_configure = 0;
> > while (<IN>) {
>
> i didn't want to scan every .pm line-by-line.  doesn't matter, either way
> can be changed later.

would slurping and matching would be faster?


_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Doug MacEachern <do...@covalent.net>.
> $run_configure = 0;
> while (<IN>) {

i didn't want to scan every .pm line-by-line.  doesn't matter, either way
can be changed later.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Stas Bekman <st...@stason.org>.
On Wed, 12 Sep 2001, Doug MacEachern wrote:

> On Tue, 11 Sep 2001, Stas Bekman wrote:
>
> > I need to autogenerate files which are needed during server startup. The
> > test's configure won't be run before the server gets started. It's an egg
> > and chicken problem.
> >
> > So should I try to make all tests require'able outside httpd and get the
> > APACHE_TEST_CONFIGURE working or do you have any other ideas?
> >
> > Of course I can just cvs commit the files, but it makes the test spread
> > out across too many files, and I don't like it.
>
> how about having a list of tests that need APACHE_TEST_CONFIGURE:
>
> my @needs_configure = qw(TestFoo::bar);
>
> and just require those?  yeah, it'd be nice not to maintain such a list,
> but considering the number of .pm tests who will have
> APACHE_TEST_CONFIGURE are far less than those without.  and we can always
> drop that later if needed.

That doesn't sound good. Changing the build code when a new test is added,
or an old test gets changed. ugly.

OK, how about this.

$run_configure = 0;
while (<IN>) {
    $run_configure++, last if m/APACHE_TEST_CONFIGURE/;
}
if ($run_configure) {
  require $file;
  if ($module->can('APACHE_TEST_CONFIGURE')){
       eval { $module->APACHE_TEST_CONFIGURE(); };
       warn $@ if $@;
  }
}

of course the code is not tested.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 11 Sep 2001, Stas Bekman wrote:
 
> I need to autogenerate files which are needed during server startup. The
> test's configure won't be run before the server gets started. It's an egg
> and chicken problem.
> 
> So should I try to make all tests require'able outside httpd and get the
> APACHE_TEST_CONFIGURE working or do you have any other ideas?
> 
> Of course I can just cvs commit the files, but it makes the test spread
> out across too many files, and I don't like it.

how about having a list of tests that need APACHE_TEST_CONFIGURE:

my @needs_configure = qw(TestFoo::bar);

and just require those?  yeah, it'd be nice not to maintain such a list,
but considering the number of .pm tests who will have
APACHE_TEST_CONFIGURE are far less than those without.  and we can always
drop that later if needed.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Stas Bekman <st...@stason.org>.
> > So should I just give up the idea of APACHE_TEST_CONFIGURE and move on
> > with Apache::TestUtil like vhost_alias does?
>
> i think so.
>
> > Let's just think for a sec, whether we may have some other reason for
> > having something like APACHE_TEST_CONFIGURE? Was the creation of the files
> > on the fly the only reason for wanting this?
>
> we can always revisit later if needed.
> would be nice if the .t files do something like this in any case to make
> things clear:
>
> configure();
>
> sub configure {
>     t_mkdir ...;
> }

It doesn't work ;(

I need to autogenerate files which are needed during server startup. The
test's configure won't be run before the server gets started. It's an egg
and chicken problem.

So should I try to make all tests require'able outside httpd and get the
APACHE_TEST_CONFIGURE working or do you have any other ideas?

Of course I can just cvs commit the files, but it makes the test spread
out across too many files, and I don't like it.


_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 11 Sep 2001, Stas Bekman wrote:
 
> Yup, I was thinking about that, but figured it'd be more expensive. I know
> we don't care much about speed in tests :) so can() should be fine.

yeah, the difference in speed here isn't worth it for tests.

> > yeah, the common ones normally compiled in modperl_startup.pl
> 
> But at this point modperl_extra.pl (where it actually happens) is not
> loaded yet :)

i realize that.
 
> What do you think is the right position for writing tests? Should these be
> standalone or rely on the fact that somebody else maybe has compiled
> constants for them. I'm fine with adding these compile calls as I find
> problems, so if it makes tests cleaner I'm willing to clean up.

i'm fine with assuming they've been compiled.  in fact, that itself is a
test, constants compiled in one file should be able to be seen in another.

> doh! I didn't expect code in .h :) sure should have checked that. thanks!

most of the xs/ *.h files have code in them.  they are .h because they are
always #include-d, never compiled into their own object file.  and only
the file that #include-s a .h file from xs/ should be able to see what's
in there.  anything else belongs in a src/modules/perl/foo.c public api.

> But this can be a problem. Since the file will be in %INC already, it'll
> keep on using bogus *Apache::LOG_MARK . Unless you actually suggest to
> implement it in what you've placed as a comment.

it's not a problem in this case, since Apache::LOG_MARK will never be
called outside of httpd.  it just needs to be defined.  so you could
actually just do this:
unless (defined &Apache::LOG_MARK) {
    *Apache::LOG_MARK = sub {};
}
 
> Ditto, the test may not work later, unless we delete $INC{...}

i don't understand the %INC problem you're talking about.  %INC has
nothing to do with a subroutine being defined or not.
 
> But can you please explain why require() doesn't work here? Is it because
> something else happens behind the walls when the server is up?

both are subroutines defined in the .xs which are not bootstrapped outside
of httpd.
 
> So should I just give up the idea of APACHE_TEST_CONFIGURE and move on
> with Apache::TestUtil like vhost_alias does?

i think so.
 
> Let's just think for a sec, whether we may have some other reason for
> having something like APACHE_TEST_CONFIGURE? Was the creation of the files
> on the fly the only reason for wanting this?

we can always revisit later if needed.
would be nice if the .t files do something like this in any case to make
things clear:

configure();

sub configure {
    t_mkdir ...;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Stas Bekman <st...@stason.org>.
On Mon, 10 Sep 2001, Doug MacEachern wrote:

> On Mon, 10 Sep 2001, Stas Bekman wrote:
>
> > +                my $configure_sub = *{$module."::APACHE_TEST_CONFIGURE"}{CODE};
>
> would prefer using $module->can('APACHE_TEST_CONFIGURE') here.

Yup, I was thinking about that, but figured it'd be more expensive. I know
we don't care much about speed in tests :) so can() should be fine.

> > TestModules::cgiupload barks at Apache::OK undefined, patched with:
> >
> > +use Apache::Const -compile => 'OK';
>
> yeah, the common ones normally compiled in modperl_startup.pl

But at this point modperl_extra.pl (where it actually happens) is not
loaded yet :)

What do you think is the right position for writing tests? Should these be
standalone or rely on the fact that somebody else maybe has compiled
constants for them. I'm fine with adding these compile calls as I find
problems, so if it makes tests cleaner I'm willing to clean up.

> > t/response/TestAPI/aplog.pm barks at Apache::LOG_MARK undefined,
> >
> > I don't know how to make it available at require() time. We explicitly
> > don't import the APLOG_MARK from Apache headers, but then I cannot find
> > where it's done. I have found this:
> >
> > ./xs/maps/modperl_functions.map:DEFINE_LOG_MARK   | MPXS_Apache_LOG_MARK       | ...
> >
> > and these are autogenerated:
> > ./xs/Apache/Log/Apache__Log.h:static XS(MPXS_Apache_LOG_MARK)
> > ./WrapXS/Apache/Log/Log.xs:   cv = newXS("Apache::LOG_MARK", MPXS_Apache_LOG_MARK, __FILE__);
> >
> > where is the code that does return (__FILE__, __LINE__) ?
>
> Apache__Log.h:
>         EXTEND(SP, 2);
>         PUSHs_mortal_pv(CopFILE(cop));
>         PUSHs_mortal_iv(CopLINE(cop));

doh! I didn't expect code in .h :) sure should have checked that. thanks!

> you can do something like:
> unless (defined &Apache::LOG_MARK) {
>      *Apache::LOG_MARK = sub { #get file/line using caller() }
> }

But this can be a problem. Since the file will be in %INC already, it'll
keep on using bogus *Apache::LOG_MARK . Unless you actually suggest to
implement it in what you've placed as a comment.

> > ---------
> > t/filter/TestFilter/input_body.pm seem not to have attributes inherited
> > via require()
> >
> > Invalid CODE attribute: FilterRequestHandler at
> > /home/stas/apache.org/registry/t/filter/TestFilter/input_body.pm line 15
>
> and similar:
> unless (defined &Apache::Filter::MODIFY_CODE_ATTRIBUTES) {
>     ...
> }

Ditto, the test may not work later, unless we delete $INC{...}

But can you please explain why require() doesn't work here? Is it because
something else happens behind the walls when the server is up?

> > also, does ModPerl::Const::compile accepts only a single arg in the
> > string on purpose? e.g. it's not possible to say: -compile 'foo bar';
>
> why should it be possible?  Exporter.pm doesn't support that.  just use
> the standard calling convention:
> -compile => qw(foo bar);

That's correct. my wrong.

> i'm starting to think supporting APACHE_TEST_CONFIGURE is going to be
> more trouble than its worth.  it is also going to slow things down
> having to require/compile every .pm on the client side before running
> tests. the majority of .pm tests will not have an
> APACHE_TEST_CONFIGURE. i'd rather see, if possible, the .t files that
> need setup of directories/files use your new Apache::TestUtil
> functions instead. what do you think?

Yup, I was exactly thinking about that. It'll be so much simpler to use
Apache::TestUtil. I don't think it makes things slower.

So should I just give up the idea of APACHE_TEST_CONFIGURE and move on
with Apache::TestUtil like vhost_alias does?

Let's just think for a sec, whether we may have some other reason for
having something like APACHE_TEST_CONFIGURE? Was the creation of the files
on the fly the only reason for wanting this?

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: failing to require some of the test .pms

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 10 Sep 2001, Stas Bekman wrote:

> +                my $configure_sub = *{$module."::APACHE_TEST_CONFIGURE"}{CODE};

would prefer using $module->can('APACHE_TEST_CONFIGURE') here.

> TestModules::cgiupload barks at Apache::OK undefined, patched with:
> 
> +use Apache::Const -compile => 'OK';

yeah, the common ones normally compiled in modperl_startup.pl
 
> ----------
> t/response/TestAPI/aplog.pm barks at Apache::LOG_MARK undefined,
> 
> I don't know how to make it available at require() time. We explicitly
> don't import the APLOG_MARK from Apache headers, but then I cannot find
> where it's done. I have found this:
> 
> ./xs/maps/modperl_functions.map:DEFINE_LOG_MARK   | MPXS_Apache_LOG_MARK       | ...
> 
> and these are autogenerated:
> ./xs/Apache/Log/Apache__Log.h:static XS(MPXS_Apache_LOG_MARK)
> ./WrapXS/Apache/Log/Log.xs:   cv = newXS("Apache::LOG_MARK", MPXS_Apache_LOG_MARK, __FILE__);
> 
> where is the code that does return (__FILE__, __LINE__) ?

Apache__Log.h:
        EXTEND(SP, 2);
        PUSHs_mortal_pv(CopFILE(cop));
        PUSHs_mortal_iv(CopLINE(cop));

you can do something like:
unless (defined &Apache::LOG_MARK) {
     *Apache::LOG_MARK = sub { #get file/line using caller() }
}
 
> ---------
> t/filter/TestFilter/input_body.pm seem not to have attributes inherited
> via require()
> 
> Invalid CODE attribute: FilterRequestHandler at
> /home/stas/apache.org/registry/t/filter/TestFilter/input_body.pm line 15

and similar:
unless (defined &Apache::Filter::MODIFY_CODE_ATTRIBUTES) {
    ...
}
 
> also, does ModPerl::Const::compile accepts only a single arg in the
> string on purpose? e.g. it's not possible to say: -compile 'foo bar';

why should it be possible?  Exporter.pm doesn't support that.  just use
the standard calling convention:
-compile => qw(foo bar);

i'm starting to think supporting APACHE_TEST_CONFIGURE is going to be more
trouble than its worth.  it is also going to slow things down having to
require/compile every .pm on the client side before running tests.
the majority of .pm tests will not have an APACHE_TEST_CONFIGURE.
i'd rather see, if possible, the .t files that need setup of
directories/files use your new Apache::TestUtil functions instead.
what do you think?




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org