diff options
Diffstat (limited to 'test/ruby/test_iseq.rb')
| -rw-r--r-- | test/ruby/test_iseq.rb | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 45223c89da..b4760dc412 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -139,8 +139,7 @@ class TestISeq < Test::Unit::TestCase def test_lambda_with_ractor_roundtrip iseq = compile(<<~EOF, __LINE__+1) x = 42 - y = nil.instance_eval{ lambda { x } } - Ractor.make_shareable(y) + y = Ractor.shareable_lambda{x} y.call EOF assert_equal(42, ISeq.load_from_binary(iseq_to_binary(iseq)).eval) @@ -158,22 +157,18 @@ class TestISeq < Test::Unit::TestCase def test_ractor_unshareable_outer_variable name = "\u{2603 26a1}" - y = nil.instance_eval do - eval("proc {#{name} = nil; proc {|x| #{name} = x}}").call + assert_raise_with_message(Ractor::IsolationError, /\(#{name}\)/) do + eval("#{name} = nil; Ractor.shareable_proc{#{name} = nil}") end - assert_raise_with_message(ArgumentError, /\(#{name}\)/) do - Ractor.make_shareable(y) - end - y = nil.instance_eval do - eval("proc {#{name} = []; proc {|x| #{name}}}").call - end - assert_raise_with_message(Ractor::IsolationError, /'#{name}'/) do - Ractor.make_shareable(y) + + assert_raise_with_message(Ractor::IsolationError, /\'#{name}\'/) do + eval("#{name} = []; Ractor.shareable_proc{#{name}}") end + obj = Object.new - def obj.foo(*) nil.instance_eval{ ->{super} } end - assert_raise_with_message(Ractor::IsolationError, /refer unshareable object \[\] from variable '\*'/) do - Ractor.make_shareable(obj.foo(*[])) + def obj.foo(*) Ractor.shareable_proc{super} end + assert_raise_with_message(Ractor::IsolationError, /cannot make a shareable Proc because it can refer unshareable object \[\]/) do + obj.foo(*[]) end end @@ -217,6 +212,26 @@ class TestISeq < Test::Unit::TestCase end end + def test_compile_file_options + Tempfile.create(%w"test_iseq .rb") do |f| + f.puts('_ = "test"') + f.close + iseq = RubyVM::InstructionSequence.compile_file(f.path, { frozen_string_literal: false }) + refute_predicate iseq.eval, :frozen? + + iseq = RubyVM::InstructionSequence.compile_file(f.path, { frozen_string_literal: true }) + assert_predicate iseq.eval, :frozen? + end + end + + def test_compile_options + iseq = RubyVM::InstructionSequence.compile("'test'", nil, nil, nil, { frozen_string_literal: false }) + refute_predicate iseq.eval, :frozen? + + iseq = RubyVM::InstructionSequence.compile("'test'", nil, nil, nil, { frozen_string_literal: true }) + assert_predicate iseq.eval, :frozen? + end + LINE_BEFORE_METHOD = __LINE__ def method_test_line_trace @@ -360,6 +375,20 @@ class TestISeq < Test::Unit::TestCase assert_not_predicate(s4, :frozen?) end + def test_frozen_string_literal_compile_option_file + Tempfile.create(%w[fsl .rb]) do |f| + f.write("['foo', 'foo', \"\#{$f}foo\", \"\#{'foo'}\"]\n") + f.flush + $f = 'f' + s1, s2, s3, s4 = RubyVM::InstructionSequence + .compile_file(f.path, frozen_string_literal: true).eval + assert_predicate(s1, :frozen?) + assert_predicate(s2, :frozen?) + assert_not_predicate(s3, :frozen?) + assert_not_predicate(s4, :frozen?) + end + end + # Safe call chain is not optimized when Coverage is running. # So we can test it only when Coverage is not running. def test_safe_call_chain @@ -687,6 +716,17 @@ class TestISeq < Test::Unit::TestCase assert_equal([[:nokey]], iseq.eval.singleton_method(:foo).parameters) end + def test_to_binary_dumps_noblock + iseq = assert_iseq_to_binary(<<-RUBY) + o = Object.new + class << o + def foo(&nil); end + end + o + RUBY + assert_equal([[:noblock]], iseq.eval.singleton_method(:foo).parameters) + end + def test_to_binary_line_info assert_iseq_to_binary("#{<<~"begin;"}\n#{<<~'end;'}", '[Bug #14660]').eval begin; @@ -866,6 +906,10 @@ class TestISeq < Test::Unit::TestCase assert_ruby_status([], "BEGIN {exit}; while true && true; end") end + def test_short_circuited_loop_condition + assert_ruby_status([], "while true || true; exit; end; abort") + end + def test_unreachable_syntax_error mesg = /Invalid break/ assert_syntax_error("false and break", mesg) |
