Last active
July 22, 2020 15:22
-
-
Save happy-barney/233ff3287dc5083d774172f55e36f513 to your computer and use it in GitHub Desktop.
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
use feature 'cleanup_block'; | |
no warnings 'experimental::cleanup_block'; | |
use lib 't'; | |
require 'test.pl'; | |
sub it { | |
my ($title, %params) = @_; | |
exists $params{expect} | |
? is ($params{got}, $params{expect}, $title) | |
: ok ($params{got}, $title) | |
} | |
it ("goto into coderef is treated as a leaving block" => ( | |
expect => "in/bar-out/bar-in/foo-out/foo", | |
got => do { | |
my @seen; | |
my sub foo { | |
FINALLY { push @seen, "out/foo" }; | |
push @seen, "in/foo"; | |
} | |
my sub bar { | |
FINALLY { push @seen, "out/bar" }; | |
push @seen, "in/bar"; | |
goto \&foo; | |
} | |
bar(); | |
join '-', @seen; | |
}, | |
)); | |
it ("should execute each reached finally block only once" => ( | |
expect => 'bar-foo', | |
got => do { | |
my @seen; | |
{ | |
goto FOO; | |
my $counter = 0; | |
BAR: FINALLY { push @seen, "bar" } | |
FOO: FINALLY { push @seen, "foo" } | |
goto BAR unless $counter++; | |
} | |
join '-', @seen; | |
}, | |
)); | |
# not ok 1 - should execute each reached finally block only once | |
# Failed test 1 - should execute each reached finally block only once at leave-block.t line 15 | |
# got "foo-bar-foo" | |
# expected "bar-foo" | |
# treating FINALLY and END | |
it ("should behave inconsistently with END in do" => ( | |
expect => 'undef/end', | |
got => do { | |
my $finally = do { | |
"finally"; | |
FINALLY { } | |
}; | |
my $end = do { | |
"end"; | |
END { } | |
}; | |
join '/', map { $_ // 'undef' } $finally, $end; | |
}, | |
)); | |
it ("should behave inconsistently with END in map" => ( | |
expect => ':end-1/end-2', | |
got => do { | |
my @finally = map { $_; FINALLY { } } 'finally-1', 'finally-2'; | |
my @end = map { $_; END { } } 'end-1', 'end-2'; | |
my $finally = join '/', map { $_ // 'undef' } @finally; | |
my $end = join '/', map { $_ // 'undef' } @end; | |
join ':', map { $_ // 'undef' } $finally, $end; | |
}, | |
)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment