perl-modperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: modperl-2.0/t/response/TestAPI aplog.pm
Date Thu, 16 Sep 2004 23:59:16 GMT
stas        2004/09/16 16:59:16

  Modified:    t/response/TestAPI aplog.pm
  Log:
  deploy TestCommon::LogDiff to actually verify that the logging is done
  correctly
  
  Revision  Changes    Path
  1.19      +82 -23    modperl-2.0/t/response/TestAPI/aplog.pm
  
  Index: aplog.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/aplog.pm,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -u -r1.18 -r1.19
  --- aplog.pm	16 Sep 2004 16:36:29 -0000	1.18
  +++ aplog.pm	16 Sep 2004 23:59:16 -0000	1.19
  @@ -3,26 +3,34 @@
   use strict;
   use warnings FATAL => 'all';
   
  -use Apache::Test;
  -use Apache::TestUtil;
  -
   use Apache::ServerRec qw(warn); # override warn locally
   use Apache::RequestRec ();
   use Apache::RequestUtil ();
   use Apache::Log ();
   use Apache::MPM ();
   
  +use File::Spec::Functions qw(catfile);
  +
  +use Apache::Test;
  +use Apache::TestUtil;
  +use TestCommon::LogDiff;
  +
   use Apache::Const -compile => qw(OK :log);
   use APR::Const    -compile => qw(:error SUCCESS);
   
   my @LogLevels = qw(emerg alert crit error warn notice info debug);
   my $package = __PACKAGE__;
   
  +my $path = catfile Apache::Test::vars('serverroot'),
  +    qw(logs error_log);
  +
   sub handler {
       my $r = shift;
       my $s = $r->server;
   
  -    plan $r, tests => (@LogLevels * 2) + 5;
  +    plan $r, tests => (@LogLevels * 2) + 17;
  +
  +    my $logdiff = TestCommon::LogDiff->new($path);
   
       my $rlog = $r->log;
   
  @@ -32,38 +40,71 @@
   
       ok $slog->isa('Apache::Log::Server');
   
  +    t_server_log_warn_is_expected();
       $rlog->info($package, " test in progress");
  +    ok t_cmp $logdiff->diff,
  +        qr/... TestAPI::aplog test in progress/,
  +        '$r->log->info';
   
       my($file, $line) = Apache::Log::LOG_MARK;
       ok $file eq __FILE__;
       ok $line == __LINE__ - 2;
   
       for my $method (@LogLevels) {
  -        #wrap in sub {}, else Test.pm tries to run the return value of ->can
  +        # wrap in sub {}, else Test.pm tries to run the return value
  +        # of ->can
           ok sub { $rlog->can($method) };
           ok sub { $slog->can($method) };
       }
   
  -    $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_INFO|Apache::LOG_STARTUP,
  -                   APR::SUCCESS, "This log message comes with no header");
  +    # log_serror
  +    {
  +        t_server_log_warn_is_expected();
  +        $s->log_serror(Apache::Log::LOG_MARK,
  +                       Apache::LOG_INFO|Apache::LOG_STARTUP,
  +                       APR::SUCCESS, "This log message comes with no header");
  +        ok t_cmp $logdiff->diff,
  +            qr/^This log message comes with no header$/m,
  +            '$s->log_serror(LOG_MARK, LOG_INFO|LOG_STARTUP...)';
   
  -    t_server_log_warn_is_expected();
  -    $s->log_serror(__FILE__, __LINE__, Apache::LOG_DEBUG,
  -                   APR::SUCCESS, "log_serror test ok");
  +        t_server_log_warn_is_expected();
  +        $s->log_serror(__FILE__, __LINE__, Apache::LOG_DEBUG,
  +                       APR::SUCCESS, "log_serror test 1");
  +        ok t_cmp $logdiff->diff,
  +            qr/: log_serror test 1$/m,
  +            '$s->log_serror(__FILE__, __LINE__, LOG_DEBUG...)';
   
  -    t_server_log_warn_is_expected();
  -    $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_DEBUG,
  -                   APR::EGENERAL, "log_serror test 2 ok");
  +        t_server_log_warn_is_expected();
  +        $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_DEBUG,
  +                       APR::EGENERAL, "log_serror test 2");
  +        ok t_cmp $logdiff->diff,
  +            qr/Error string not specified yet: log_serror test 2/,
  +            '$s->log_serror(LOG_MARK, LOG_DEBUG, APR::EGENERAL...)';
  +    }
   
  +    # log_rerror
       t_server_log_error_is_expected();
       $r->log_rerror(Apache::Log::LOG_MARK, Apache::LOG_CRIT,
  -                   APR::ENOTIME, "log_rerror test ok");
  -
  -    t_server_log_error_is_expected();
  -    $r->log_error('$r->log_error test ok');
  +                   APR::ENOTIME, "log_rerror test");
  +    # can't match against the error string, since a locale may kick in
  +    ok t_cmp $logdiff->diff,
  +        qr/\[crit\] .*?: log_rerror test/,
  +        '$r->log_rerror(LOG_MARK, LOG_CRIT, APR::ENOTIME...)';
   
  -    t_server_log_error_is_expected();
  -    $s->log_error('$s->log_error test ok');
  +    # log_error
  +    {
  +        t_server_log_error_is_expected();
  +        $r->log_error('$r->log_error test');
  +        ok t_cmp $logdiff->diff,
  +            qr/\[error\] \$r->log_error test/,
  +            '$r->log_error(...)';
  +
  +        t_server_log_error_is_expected();
  +        $s->log_error('$s->log_error test');
  +        ok t_cmp $logdiff->diff,
  +            qr/\[error\] \$s->log_error test/,
  +            '$s->log_error(...)';
  +    }
   
       # XXX: at the moment we can't change loglevel after server startup
       # in a threaded mpm environment
  @@ -73,31 +114,49 @@
           if ($s->error_fname) {
               #XXX: does not work under t/TEST -ssl
               $slog->debug(sub { die "set loglevel no workie" });
  +            # ok t_cmp $logdiff->diff...
           }
   
           $s->loglevel(Apache::LOG_DEBUG);
           $slog->debug(sub { ok 1; "$package test done" });
  +        ok t_cmp $logdiff->diff,
  +            qr/\$slog->debug\(sub \{/,
  +            '$slog->debug(sub { })';
  +
       }
       else {
           ok 1;
  +        ok 1;
       }
   
       t_server_log_warn_is_expected();
  -    $s->warn('$s->warn test ok');
  +    $s->warn('$s->warn test');
  +    ok t_cmp $logdiff->diff,
  +        qr/\[warn\] \$s->warn test/,
  +        '$s->warn()';
   
       {
           t_server_log_warn_is_expected();
           # this uses global server to get $s internally
  -        Apache::ServerRec::warn("Apache::ServerRec::warn test ok");
  +        Apache::ServerRec::warn("Apache::ServerRec::warn test");
  +        ok t_cmp $logdiff->diff,
  +            qr/\[warn\] Apache::ServerRec::warn test/,
  +            'Apache::ServerRec::warn() w/o Apache->request ';
   
           Apache->request($r);
           t_server_log_warn_is_expected();
           # this uses the global $r to get $s internally
  -        Apache::ServerRec::warn("Apache::ServerRec::warn test ok");
  +        Apache::ServerRec::warn("Apache::ServerRec::warn test");
  +        ok t_cmp $logdiff->diff,
  +            qr/\[warn\] Apache::ServerRec::warn test/,
  +            'Apache::ServerRec::warn() w/ Apache->request ';
       }
   
       t_server_log_warn_is_expected();
  -    warn "warn test ok";
  +    warn "warn test";
  +    ok t_cmp $logdiff->diff,
  +        qr/\[warn\] warn test/,
  +        'overriden via export warn()';
   
       Apache::OK;
   }
  
  
  

Mime
View raw message