From: Chase Venters Date: Tue, 7 Jun 2016 14:55:21 +0000 (-0500) Subject: Add test case for $c->state and exceptions inside $c->execute X-Git-Tag: 5.90105~3^2^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=68b4caec7950a4dc7ed003fe0e78f73baf81f9d3 Add test case for $c->state and exceptions inside $c->execute See: https://github.com/perl-catalyst/catalyst-runtime/issues/136 Signed-off-by: Chase Venters --- diff --git a/README.mkdn b/README.mkdn index ad3aa2d..7889225 100644 --- a/README.mkdn +++ b/README.mkdn @@ -2032,6 +2032,8 @@ Caelum: Rafael Kitover chansen: Christian Hansen +Chase Venters + chicks: Christopher Hicks Chisel Wright `pause@herlpacker.co.uk` diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 602316a..8184a98 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -4828,6 +4828,8 @@ Caelum: Rafael Kitover chansen: Christian Hansen +Chase Venters C + chicks: Christopher Hicks Chisel Wright C diff --git a/t/execute_exception.t b/t/execute_exception.t new file mode 100644 index 0000000..b880b06 --- /dev/null +++ b/t/execute_exception.t @@ -0,0 +1,60 @@ +use warnings; +use strict; +use Test::More; +use HTTP::Request::Common; + +{ + package MyApp::Controller::Root; + $INC{'MyApp/Controller/Root.pm'} = __FILE__; + + use base 'Catalyst::Controller'; + + MyApp::Controller::Root->config(namespace=>''); + + sub could_throw :Private { + my ($self, $c) = @_; + if ($c->req->args->[0] eq 'y') { + die 'Bad stuff happened'; + } + else { + return 5; + } + } + + sub do_throw :Local { + my ($self, $c) = @_; + + my $ret = $c->forward('/could_throw/y'); + Test::More::is($c->state, 0, 'Throwing: state is correct'); + Test::More::is($ret, 0, 'Throwing: return is correct'); + Test::More::ok($c->has_errors, 'Throwing: has errors'); + } + + sub dont_throw :Local { + my ($self, $c) = @_; + + my $ret = $c->forward('/could_throw/n'); + Test::More::is($c->state, 5, 'Not throwing: state is correct'); + Test::More::is($ret, 5, 'Not throwing: return is correct'); + Test::More::ok(!$c->has_errors, 'Throwing: no errors'); + } + + package MyApp; + use Catalyst; + + MyApp->config(show_internal_actions=>1); + MyApp->setup; +} + +use Catalyst::Test 'MyApp'; + +{ + my ($res, $c); + + ctx_request("/dont_throw"); + ctx_request("/do_throw"); + ctx_request("/dont_throw"); +} + +done_testing; +