You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@perl.apache.org by Torsten Foertsch <to...@gmx.net> on 2005/05/20 22:02:43 UTC

check if an expected error_log line has arrived?

Hi,

is there a way to check it an expected line in error_log has arrived?

If not is it worth to add something similar to the following 2 functions to 
Apache::TestUtil.

========================================================
{
  my $f;
  sub t_start_error_log_watch {
    my $name=File::Spec->catfile
      ( Apache::Test::vars->{serverroot},
	Apache::Test::config->{httpd_defines}->{DEFAULT_ERRORLOG} );
    open $f, "$name" or die "ERROR: Cannot open $name: $!\n";
    seek $f, 0, 2;          # seek to EOF
  }

  sub t_finish_error_log_watch {
    local $/="\n";
    my @lines=<$f>;
    undef $f;
    return @lines;
  }
}
========================================================

Torsten

Re: check if an expected error_log line has arrived?

Posted by Stas Bekman <st...@stason.org>.
Torsten Foertsch wrote:
> Hi,
> 
> is there a way to check it an expected line in error_log has arrived?
> 
> If not is it worth to add something similar to the following 2 functions to 
> Apache::TestUtil.
> 
> ========================================================
> {
>   my $f;
>   sub t_start_error_log_watch {
>     my $name=File::Spec->catfile
>       ( Apache::Test::vars->{serverroot},
> 	Apache::Test::config->{httpd_defines}->{DEFAULT_ERRORLOG} );
>     open $f, "$name" or die "ERROR: Cannot open $name: $!\n";
>     seek $f, 0, 2;          # seek to EOF
>   }
> 
>   sub t_finish_error_log_watch {
>     local $/="\n";
>     my @lines=<$f>;
>     undef $f;
>     return @lines;
>   }
> }
> ========================================================

Not in Apache::Test, but the mod_perl 2 test suite provides a module to do 
that (under t/lib)

   use TestCommon::LogDiff;
   use Apache::Test;

   plan tests => 2;

   my $path = "/tmp/mylog";
   open my $fh, ">>$path" or die "Can't open $path: $!";

   my $logdiff = TestCommon::LogDiff->new($path);

   print $fh "foo 123\n";
   my $expected = qr/^foo/;
   ok t_cmp $logdiff->diff, $expected;

   print $fh "bar\n";
   my $expected = 'bar';
   ok t_cmp $logdiff->diff, $expected;

If others find this useful we should migrate it to Apache::Test. May be 
the API could use some polish.

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