aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-31 09:33:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-31 09:33:22 +0000
commit84d931415ee8d8839c7fcc65047a8b1112ab851d (patch)
tree800eb0692719076327caf7843c2ea4ac1d32a888 /test
parent6806c16fefa62e420da73ed37ba94690dab18afc (diff)
downloadruby-84d931415ee8d8839c7fcc65047a8b1112ab851d.tar.gz
compile.c: ensure after return in library toplevel
* compile.c (compile_return): execute ensure clause after toplevel return even in library toplevel other than the main script. [ruby-core:83589] [Bug #14061] test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_syntax.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index beb85272ff..0a0ef83f8b 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -990,7 +990,8 @@ eom
def test_return_toplevel
feature4840 = '[ruby-core:36785] [Feature #4840]'
- code = "#{<<~"begin;"}\n#{<<~'end;'}"
+ line = __LINE__+2
+ code = "#{<<~"begin;"}#{<<~'end;'}"
begin;
return; raise
begin return; rescue SystemExit; exit false; end
@@ -1006,10 +1007,20 @@ eom
begin raise; ensure return; end and self
nil&defined?0--begin e=no_method_error(); return; 0;end
end;
- all_assertions_foreach(feature4840, *code.split(/\n/)) do |s|
- assert_in_out_err(%[-W0], s, [*s[/#=> (.*)/, 1]], [],
- proc {RubyVM::InstructionSequence.compile(s).disasm},
- success: true)
+ .split(/\n/).map {|s|[(line+=1), *s.split(/#=> /, 2)]}
+ failed = proc do |n, s|
+ RubyVM::InstructionSequence.compile(s, __FILE__, nil, n).disasm
+ end
+ all_assertions_foreach(feature4840, *code) do |n, s, *ex|
+ assert_in_out_err(%[-W0], src = s, ex, [], proc {failed[n, s]}, success: true)
+ end
+ Tempfile.create(%w"test_return_ .rb") do |lib|
+ lib.close
+ args = %W[-W0 -r#{lib.path}]
+ all_assertions_foreach(feature4840, *code) do |n, s, *ex|
+ File.write(lib, s)
+ assert_in_out_err(args, "", ex, [], proc {failed[n, s]}, success: true)
+ end
end
end