Add test case for $c->state and exceptions inside $c->execute
Chase Venters [Tue, 7 Jun 2016 14:55:21 +0000 (09:55 -0500)]
See: https://github.com/perl-catalyst/catalyst-runtime/issues/136

Signed-off-by: Chase Venters <chase.venters@gmail.com>

README.mkdn
lib/Catalyst.pm
t/execute_exception.t [new file with mode: 0644]

index ad3aa2d..7889225 100644 (file)
@@ -2032,6 +2032,8 @@ Caelum: Rafael Kitover <rkitover@io.com>
 
 chansen: Christian Hansen
 
+Chase Venters <chase.venters@gmail.com>
+
 chicks: Christopher Hicks
 
 Chisel Wright `pause@herlpacker.co.uk`
index 602316a..8184a98 100644 (file)
@@ -4828,6 +4828,8 @@ Caelum: Rafael Kitover <rkitover@io.com>
 
 chansen: Christian Hansen
 
+Chase Venters C<chase.venters@gmail.com>
+
 chicks: Christopher Hicks
 
 Chisel Wright C<pause@herlpacker.co.uk>
diff --git a/t/execute_exception.t b/t/execute_exception.t
new file mode 100644 (file)
index 0000000..b880b06
--- /dev/null
@@ -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;
+