Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure blocks after 'success' / 'exception' are executed

  • Loading branch information...
commit ff806bfc07adaa81091e33ab1f6431ee8784945f 1 parent 213bb6d
@joelbernstein joelbernstein authored committed
Showing with 25 additions and 9 deletions.
  1. +8 −8 lib/Test/Fatal.pm
  2. +17 −1 t/basic.t
View
16 lib/Test/Fatal.pm
@@ -72,18 +72,18 @@ C<Sub::Uplevel> mechanism.
=cut
-sub exception (&) {
- my ($code) = @_;
+sub exception (&;@) {
+ my $code = shift;
return try {
$code->();
return undef;
- } catch {
+ } catch( sub {
return $_ if $_;
my $problem = defined $_ ? 'false' : 'undef';
Carp::confess("$problem exception caught by Test::Fatal::exception");
- };
+ }, @_);
}
=func success
@@ -105,12 +105,12 @@ success blocks may sometimes help organize complex testing.
=cut
-sub success (&) {
- my ($code) = @_;
- return finally {
+sub success (&;@) {
+ my $code = shift;
+ return finally( sub {
return if @_; # <-- only run on success
$code->();
- }
+ }, @_ );
}
1;
View
18 t/basic.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 5 + ($] >= 5.013001 ? 0 : 1);
+use Test::More tests => 7 + ($] >= 5.013001 ? 0 : 1);
use Test::Fatal qw(exception success);
use Try::Tiny 0.07;
@@ -31,6 +31,22 @@ try {
pass("a success block runs, passing");
};
+{
+ my $i = 0;
+ try {
+ die { foo => 42 };
+ } catch {
+ 1;
+ } success {
+ fail("never get here");
+ } finally {
+ $i++;
+ pass("finally block after success block");
+ };
+
+ is($i, 1, "finally block after success block still runs");
+};
+
# TODO: test for fatality of undef exception?
{
Please sign in to comment.
Something went wrong with that request. Please try again.