X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Fhttp_exceptions.t;h=ad6544abc2405970040ad38df6de8c7b1b3a84ee;hp=460769d2a296fe5037ec8155d64b23fa25e43810;hb=6b9f9ef742c1ee771df336eed1db42d807c8c59c;hpb=6e94698dcf3a2dca78fd6f572c0860a1e386b118 diff --git a/t/http_exceptions.t b/t/http_exceptions.t index 460769d..ad6544a 100644 --- a/t/http_exceptions.t +++ b/t/http_exceptions.t @@ -12,10 +12,6 @@ use Plack::Test; { package MyApp::Exception; - use overload - # Use the overloading thet HTTP::Exception uses - bool => sub { 1 }, '""' => 'as_string', fallback => 1; - sub new { my ($class, $code, $headers, $body) = @_; return bless +{res => [$code, $headers, $body]}, $class; @@ -35,8 +31,14 @@ use Plack::Test; }; } + package MyApp::AnotherException; + + sub new { bless +{}, shift } + + sub code { 400 } + sub as_string { 'bad stringy bad' } - + package MyApp::Controller::Root; use base 'Catalyst::Controller'; @@ -60,6 +62,11 @@ use Plack::Test; 403, ['content-type'=>'text/plain'], ['Forbidden']); } + sub from_code_type :Local { + my $e = MyApp::AnotherException->new; + die $e; + } + sub classic_error :Local { my ($self, $c) = @_; Catalyst::Exception->throw("Ex Parrot"); @@ -70,15 +77,19 @@ use Plack::Test; die "I'm not dead yet"; } + sub end :Private { die "We should never hit end for HTTPExceptions" } + package MyApp; use Catalyst; + MyApp->config(abort_chain_on_error_fix=>1); + sub debug { 1 } MyApp->setup_log('fatal'); } -$INC{'MyApp/Controller/Root.pm'} = '1'; # sorry... +$INC{'MyApp/Controller/Root.pm'} = __FILE__; # sorry... MyApp->setup_log('error'); Test::More::ok(MyApp->setup); @@ -90,6 +101,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/from_psgi_app"); is $res->code, 404; is $res->content, 'Not Found', 'NOT FOUND'; + unlike $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; test_psgi $psgi, sub { @@ -97,6 +109,15 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/from_catalyst"); is $res->code, 403; is $res->content, 'Forbidden', 'Forbidden'; + unlike $res->content, qr'HTTPExceptions', 'HTTPExceptions'; +}; + +test_psgi $psgi, sub { + my $cb = shift; + my $res = $cb->(GET "/root/from_code_type"); + is $res->code, 400; + is $res->content, 'bad stringy bad', 'bad stringy bad'; + unlike $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; test_psgi $psgi, sub { @@ -104,6 +125,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/classic_error"); is $res->code, 500; like $res->content, qr'Ex Parrot', 'Ex Parrot'; + like $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; test_psgi $psgi, sub { @@ -111,6 +133,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/just_die"); is $res->code, 500; like $res->content, qr'not dead yet', 'not dead yet'; + like $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; @@ -119,5 +142,5 @@ test_psgi $psgi, sub { # in the callbacks might never get run (thus all ran tests pass but not all # required tests run). -done_testing(10); +done_testing(17);