httpd-test-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestUtil.pm
Date Tue, 01 Apr 2003 04:12:55 GMT
stas        2003/03/31 20:12:55

  Modified:    perl-framework/Apache-Test/lib/Apache TestUtil.pm
  Log:
  add new helper functions:
      t_server_log_error_is_expected t_server_log_warn_is_expected
      t_client_log_error_is_expected t_client_log_warn_is_expected
  to markup the error_log file when errors/warnings are expected
  
  Revision  Changes    Path
  1.29      +127 -2    httpd-test/perl-framework/Apache-Test/lib/Apache/TestUtil.pm
  
  Index: TestUtil.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestUtil.pm,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- TestUtil.pm	3 Feb 2003 06:27:39 -0000	1.28
  +++ TestUtil.pm	1 Apr 2003 04:12:55 -0000	1.29
  @@ -9,8 +9,11 @@
   use Carp ();
   use Config;
   use File::Basename qw(dirname);
  +use File::Spec::Functions qw(catfile);
  +use Symbol ();
   
  -use Apache::TestConfig;
  +use Apache::Test ();
  +use Apache::TestConfig ();
   
   use vars qw($VERSION @ISA @EXPORT %CLEAN);
   
  @@ -18,7 +21,10 @@
   @ISA     = qw(Exporter);
   
   @EXPORT = qw(t_cmp t_debug t_append_file t_write_file t_open_file
  -             t_mkdir t_rmtree t_is_equal);
  +    t_mkdir t_rmtree t_is_equal
  +    t_server_log_error_is_expected t_server_log_warn_is_expected
  +    t_client_log_error_is_expected t_client_log_warn_is_expected
  +);
   
   %CLEAN = ();
   
  @@ -261,6 +267,26 @@
       return 1;
   }
   
  +my $banner_format = 
  +    "\n*** The following %s entry is expected and it is harmless ***\n";
  +sub t_server_log_is_expected { printf STDERR $banner_format, $_[0]; }
  +
  +sub t_client_log_is_expected {
  +    my $vars = Apache::Test::config()->{vars};
  +    my $log_file = catfile $vars->{serverroot}, "logs", "error_log";
  +
  +    my $fh = Symbol::gensym();
  +    open $fh, ">>$log_file" or die "Can't open $log_file: $!";
  +    my $oldfh = select($fh); $| = 1; select($oldfh);
  +    printf $fh $banner_format, $_[0];
  +    close $fh;
  +}
  +
  +sub t_server_log_error_is_expected { t_server_log_is_expected("error");}
  +sub t_server_log_warn_is_expected  { t_server_log_is_expected("warn"); }
  +sub t_client_log_error_is_expected { t_client_log_is_expected("error");}
  +sub t_client_log_warn_is_expected  { t_client_log_is_expected("warn"); }
  +
   END {
       # remove files that were created via this package
       for (grep {-e $_ && -f _ } keys %{ $CLEAN{files} } ) {
  @@ -487,6 +513,105 @@
   
   If comparing non-scalars make sure to pass the references to the
   datastructures.
  +
  +This function is exported by default.
  +
  +=item t_server_log_error_is_expected()
  +
  +If the handler's execution results in an error or a warning logged to
  +the I<error_log> file which is expected, it's a good idea to have a
  +disclaimer printed before the error itself, so one can tell real
  +problems with tests from expected errors. For example when testing how
  +the package behaves under error conditions the I<error_log> file might
  +be loaded with errors, most of which are expected.
  +
  +For example if a handler is about to generate a run-time error, this
  +function can be used as:
  +
  +  use Apache::TestUtil;
  +  ...
  +  sub handler {
  +      my $r = shift;
  +      ...
  +      t_server_log_error_is_expected();
  +      die "failed because ...";
  +  }
  +
  +After running this handler the I<error_log> file will include:
  +
  +  *** The following error entry is expected and it is harmless ***
  +  [Tue Apr 01 14:00:21 2003] [error] failed because ...
  +
  +If the error is generated at compile time, the logging must be done in
  +the BEGIN block at the very beginning of the file:
  +
  +  BEGIN {
  +      use Apache::TestUtil;
  +      t_server_log_error_is_expected();
  +  }
  +  use DOES_NOT_exist;
  +
  +After attempting to run this handler the I<error_log> file will
  +include:
  +
  +  *** The following error entry is expected and it is harmless ***
  +  [Tue Apr 01 14:04:49 2003] [error] Can't locate "DOES_NOT_exist.pm"
  +  in @INC (@INC contains: ...
  +
  +Also see C<t_server_log_warn_is_expected()> which is similar but used
  +for warnings.
  +
  +This function is exported by default.
  +
  +=item t_server_log_warn_is_expected()
  +
  +C<t_server_log_warn_is_expected()> generates a disclaimer for expected
  +warnings.
  +
  +See the explanation for C<t_server_log_error_is_expected()> for more
  +details.
  +
  +This function is exported by default.
  +
  +=item t_client_log_error_is_expected()
  +
  +C<t_client_log_error_is_expected()> generates a disclaimer for
  +expected errors. But in contrast to
  +C<t_server_log_error_is_expected()> called by the client side of the
  +script.
  +
  +See the explanation for C<t_server_log_error_is_expected()> for more
  +details.
  +
  +For example the following client script fails to find the handler:
  +
  +  use Apache::Test;
  +  use Apache::TestUtil;
  +  use Apache::TestRequest qw(GET);
  +  
  +  plan tests => 1;
  +  
  +  t_client_log_error_is_expected();
  +  my $url = "/error_document/cannot_be_found";
  +  my $res = GET($url);
  +  ok t_cmp(404, $res->code, "test 404");
  +
  +After running this test the I<error_log> file will include an entry
  +similar to the following snippet:
  +
  +  *** The following error entry is expected and it is harmless ***
  +  [Tue Apr 01 14:02:55 2003] [error] [client 127.0.0.1] 
  +  File does not exist: /tmp/test/t/htdocs/error
  +
  +This function is exported by default.
  +
  +=item t_client_log_warn_is_expected()
  +
  +C<t_client_log_warn_is_expected()> generates a disclaimer for expected
  +warnings on the client side.
  +
  +See the explanation for C<t_client_log_error_is_expected()> for more
  +details.
   
   This function is exported by default.
   
  
  
  

Mime
View raw message