Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.28 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. use Test::More;
  6.  
  7. sub escape {
  8.     no warnings 'exiting';
  9.     eval { last ESCAPE };
  10. }
  11.  
  12. my $escaped = 1;
  13. my $safe = eval {
  14.     ESCAPE: {
  15.         eval "escape(); 1" || diag "Exception: $@";
  16.         ok(0, "Should not see this");
  17.         $escaped = 0;
  18.     }
  19.    
  20.     1;
  21. };
  22.  
  23. ok($safe, "outer eval 1 completed");
  24. ok($escaped, "We can escape");
  25.  
  26. $escaped = 1;
  27. $safe = eval {
  28.     ESCAPE: {
  29.         eval "BEGIN { escape() }; 1" || diag "Exception: $@";
  30.         $escaped = 0;
  31.     }
  32.    
  33.     1;
  34. };
  35.  
  36. ok($safe, "outer eval 2 completed");
  37. ok($escaped, "We can escape when there is a BEGIN between us and the escape point");
  38.  
  39. done_testing;
  40.  
  41. =head1 5.20.1
  42.  
  43.     ok 1 - outer eval 1 completed
  44.     ok 2 - We can escape
  45.     ok 3 - outer eval 2 completed
  46.     not ok 4 - We can escape when there is a BEGIN between us and the escape point
  47.     #   Failed test 'We can escape when there is a BEGIN between us and the escape point'
  48.     #   at test.pl line 37.
  49.     1..4
  50.     # Looks like you failed 1 test of 4.
  51.  
  52. =head1 5.10.1
  53.  
  54.     ok 1 - outer eval 1 completed
  55.     ok 2 - We can escape
  56.     ok 3 - outer eval 2 completed
  57.     ok 4 - We can escape when there is a BEGIN between us and the escape point
  58.     1..4
  59.     segmentation fault
  60.  
  61. =cut
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement