public void EvalRetry2() {
// retry in block:
AssertOutput(() => CompilerTest(@"
$x = 0
1.times do |i|
puts 'in block'
module M
eval('retry') if ($x += 1) < 2
end
end
"), @"
in block
in block
");
// retry in rescue:
AssertOutput(() => CompilerTest(@"
$x = 0
1.times do
begin
raise
rescue
puts 'in rescue'
module M
eval('retry') if ($x += 1) < 2
end
end
end
"), @"
in rescue
in rescue
");
// TODO:
// retry in a define_method block:
AssertOutput(() => CompilerTest(@"
$x = 0
class C
define_method :foo do
puts 'define_method'
begin
eval('module M; retry; end') if ($x += 1) < 3
# TODO: should not catch here
# rescue
# p 'unreachable'
end
end
end
begin
C.new.foo
rescue
p $!
end"), @"
define_method
#<LocalJumpError: retry from proc-closure>
");
// retry in a method taking a block:
AssertOutput(() => CompilerTest(@"
$x = 0
def foo *a
yield
eval('module M; retry; end') if ($x += 1) < 2
end
foo(puts('in arg')) { puts 'in block' }
"), @"
in arg
in block
in arg
in block
");
}