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/TestError runtime.pm
Date Tue, 04 May 2004 06:19:59 GMT
stas        2004/05/03 23:19:59

  Modified:    t/error  runtime.t
               t/response/TestError runtime.pm
  Log:
  new tests for exception objects
  
  Revision  Changes    Path
  1.3       +27 -8     modperl-2.0/t/error/runtime.t
  
  Index: runtime.t
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/error/runtime.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- runtime.t	18 Apr 2003 06:18:56 -0000	1.2
  +++ runtime.t	4 May 2004 06:19:59 -0000	1.3
  @@ -5,13 +5,32 @@
   use Apache::TestUtil;
   use Apache::TestRequest;
   
  -plan tests => 1;
  -
   my $location = "/TestError__runtime";
  -my $res = GET($location);
  -#t_debug($res->content);
  -ok t_cmp(
  -    500,
  -    $res->code,
  -    "500 error on runtime error",
  +
  +my @untrapped = qw(plain_mp_error            plain_non_mp_error
  +                   die_hook_confess_mp_error die_hook_confess_non_mp_error
  +                   die_hook_custom_mp_error  die_hook_custom_non_mp_error);
  +my @trapped   = qw(eval_block_mp_error       eval_block_non_mp_error
  +                   eval_string_mp_error      eval_block_non_error);
  +
  +plan tests => @untrapped + @trapped;
  +
  +for my $type (@untrapped) {
  +    my $res = GET("$location?$type");
  +    #t_debug($res->content);
  +    ok t_cmp(
  +        500,
  +        $res->code,
  +        "500 error on $type exception",
      );
  +}
  +
  +for my $type (@trapped) {
  +    my $body = GET_BODY("$location?$type");
  +    ok t_cmp(
  +        "ok $type",
  +        $body,
  +        "200 on $type exception",
  +   );
  +}
  +
  
  
  
  1.3       +104 -3    modperl-2.0/t/response/TestError/runtime.pm
  
  Index: runtime.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/response/TestError/runtime.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- runtime.pm	1 Apr 2003 04:39:30 -0000	1.2
  +++ runtime.pm	4 May 2004 06:19:59 -0000	1.3
  @@ -5,22 +5,123 @@
   
   use Apache::RequestRec ();
   use Apache::RequestIO ();
  +use Apache::Connection ();
  +use APR::Socket ();
   
   use Apache::TestUtil;
   
   use Apache::Const -compile => qw(OK);
  +use APR::Const    -compile => qw(TIMEUP);
  +
  +use constant SIZE => 2048;
   
   sub handler {
       my $r = shift;
  +    my $socket = $r->connection->client_socket;
  +    my $args = $r->args;
   
       $r->content_type('text/plain');
   
  -    t_server_log_error_is_expected();
  -    no_such_func();
  +    # set timeout to 1 usec (microsec!) which makes sure that any
  +    # socket read call will fail
  +    $socket->timeout_set(1);
   
  -    $r->print('ok');
  +    no strict 'refs';
  +    $args->($r, $socket);
   
       return Apache::OK;
  +}
  +
  +sub plain_mp_error {
  +    my($r, $socket) = @_;
  +    t_server_log_error_is_expected();
  +    mp_error($socket);
  +}
  +
  +sub plain_non_mp_error {
  +    my($r, $socket) = @_;
  +    t_server_log_error_is_expected();
  +    non_mp_error($socket);
  +}
  +
  +sub die_hook_confess_mp_error {
  +    my($r, $socket) = @_;
  +    local $SIG{__DIE__} = \&APR::Error::confess;
  +    t_server_log_error_is_expected();
  +    mp_error($socket);
  +}
  +
  +sub die_hook_confess_non_mp_error {
  +    my($r, $socket) = @_;
  +    local $SIG{__DIE__} = \&APR::Error::confess;
  +    t_server_log_error_is_expected();
  +    non_mp_error($socket);
  +}
  +
  +sub die_hook_custom_mp_error {
  +    my($r, $socket) = @_;
  +    local $SIG{__DIE__} = sub { die "custom die hook: $_[0]" };
  +    t_server_log_error_is_expected();
  +    mp_error($socket);
  +}
  +
  +sub die_hook_custom_non_mp_error {
  +    my($r, $socket) = @_;
  +    local $SIG{__DIE__} = sub { die "custom die hook: $_[0]" };
  +    t_server_log_error_is_expected();
  +    non_mp_error($socket);
  +}
  +
  +sub eval_block_mp_error {
  +    my($r, $socket) = @_;
  +    eval { mp_error($socket) };
  +    if ($@ && ref($@) && $@ == APR::TIMEUP) {
  +        $r->print("ok eval_block_mp_error");
  +    }
  +    else {
  +        die "eval block has failed: $@";
  +    }
  +}
  +
  +sub eval_string_mp_error {
  +    my($r, $socket) = @_;
  +    eval "\$socket->recv(SIZE)";
  +    if ($@ && ref($@) && $@ == APR::TIMEUP) {
  +        $r->print("ok eval_string_mp_error");
  +    }
  +    else {
  +        die "eval string has failed: $@";
  +    }
  +}
  +
  +sub eval_block_non_mp_error {
  +    my($r, $socket) = @_;
  +    eval { non_mp_error($socket) };
  +    if ($@ && !ref($@)) {
  +        $r->print("ok eval_block_non_mp_error");
  +    }
  +    else {
  +        die "eval eval_non_mp_error has failed: $@";
  +    }
  +}
  +
  +sub eval_block_non_error {
  +    my($r, $socket) = @_;
  +    eval { 1; };
  +    if ($@) {
  +        die "eval eval_block_non_mp_error has failed";
  +    }
  +    $r->print("ok eval_block_non_error");
  +}
  +
  +sub non_mp_error {
  +    no_such_func();
  +}
  +
  +# fails because of the timeout set earlier in the handler
  +sub mp_error {
  +    my $socket = shift;
  +    $socket->recv(SIZE);
   }
   
   1;
  
  
  

Mime
View raw message