-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
209 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
use strict; | ||
use warnings; | ||
use Test::More tests => 20; | ||
use Test::More tests => 21; | ||
|
||
use Try::Catch; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 3; | ||
use Try::Catch; | ||
|
||
{ | ||
package WithCatch; | ||
use Try::Catch; | ||
|
||
sub DESTROY { | ||
try {} | ||
catch {}; | ||
return; | ||
} | ||
} | ||
|
||
{ | ||
package WithFinally; | ||
use Try::Catch; | ||
|
||
sub DESTROY { | ||
try {} | ||
finally {}; | ||
return; | ||
} | ||
} | ||
|
||
my $parent = $$; | ||
|
||
try { | ||
my $pid = fork; | ||
unless ($pid) { | ||
my $o = bless {}, 'WithCatch'; | ||
$SIG{__DIE__} = sub { | ||
exit 1 | ||
if $_[0] =~ /A try\(\) may not be followed by multiple catch\(\) blocks/; | ||
exit 2; | ||
}; | ||
exit 0; | ||
} | ||
waitpid $pid, 0; | ||
is $?, 0, 'nested try in cleanup after fork does not maintain outer catch block'; | ||
} | ||
catch {}; | ||
|
||
try { | ||
my $pid = fork; | ||
unless ($pid) { | ||
my $o = bless {}, 'WithFinally'; | ||
exit 0; | ||
} | ||
waitpid $pid, 0; | ||
is $?, 0, 'nested try in cleanup after fork does not maintain outer finally block'; | ||
} | ||
finally { exit 1 if $parent != $$ }; | ||
|
||
pass("Didn't just exit"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Try::Catch; | ||
|
||
############################################################# | ||
# this test pass javascript but not this module since we don't | ||
# throw an error if there is no catch block, I'll keep it here | ||
# in order to see if it's a better approach to throw by default | ||
############################################################## | ||
# { | ||
# try { | ||
# try { | ||
# die "inner oops"; | ||
# } | ||
# finally { | ||
# pass("finally called"); | ||
# }; | ||
# } | ||
# catch { | ||
# ok ($_ =~ /^inner oops/); | ||
# }; | ||
# } | ||
|
||
|
||
{ | ||
try { | ||
try { | ||
die "inner oops"; | ||
} | ||
catch { | ||
ok ($_ =~ /^inner oops/); | ||
} | ||
finally { | ||
pass("finally called"); | ||
}; | ||
} | ||
catch { | ||
fail("should not be called"); | ||
}; | ||
} | ||
|
||
{ | ||
try { | ||
try { | ||
die "inner2 oops"; | ||
} | ||
catch { | ||
ok($_ =~ /^inner2 oops/); | ||
die $_; | ||
} | ||
finally { | ||
pass("finally called"); | ||
}; | ||
} | ||
catch { | ||
ok($_ =~ /^inner2 oops/); | ||
}; | ||
} | ||
|
||
{ | ||
my $val = 0; | ||
my @expected; | ||
try { | ||
try { | ||
try { | ||
try { | ||
die "9"; | ||
} catch { | ||
$val = 9; | ||
die $_; | ||
} finally { | ||
try { | ||
push @expected, 1; | ||
is($val, 9, "first finally called"); | ||
die "new Error"; | ||
} catch {}; | ||
}; | ||
} catch { | ||
pass("cach called"); | ||
push @expected, 2; | ||
} finally { | ||
die "second finally called $val\n"; | ||
}; | ||
fail("should not reach here"); | ||
} catch { | ||
$val = 10; | ||
die $_; | ||
} finally { | ||
push @expected, 3; | ||
is ($val, 10, "final finally called"); | ||
}; | ||
fail("should not reach here"); | ||
} catch { | ||
ok ($_ =~ /^second finally called 9/); | ||
}; | ||
is_deeply \@expected, [1,2,3]; | ||
} | ||
|
||
done_testing(10); | ||
1; |