Commit 0aa5aa1d authored by dearblue's avatar dearblue

Add test for top level local variables are in file scope; ref #4931

parent 25d9370f
...@@ -32,3 +32,20 @@ EOS ...@@ -32,3 +32,20 @@ EOS
o, _ = Open3.capture2("bin/mirb -r #{lib.path}", :stdin_data => "Hoge.new.hoge\n") o, _ = Open3.capture2("bin/mirb -r #{lib.path}", :stdin_data => "Hoge.new.hoge\n")
assert_true o.include?('=> :hoge') assert_true o.include?('=> :hoge')
end end
assert('top level local variables are in file scope') do
lib = Tempfile.new('lib.rb')
lib.write <<-TESTLIB
a = 1
A = -> { a }
TESTLIB
lib.flush
o, _ = Open3.capture2("bin/mirb -r #{lib.path}", :stdin_data => <<-TESTCODE)
a
a = 5
A.call
TESTCODE
assert_kind_of Integer, o =~ /\bundefined method 'a' \(NoMethodError\).*=> 5\b.*=> 1\b/m
end
...@@ -162,3 +162,24 @@ assert('codegen error') do ...@@ -162,3 +162,24 @@ assert('codegen error') do
code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end" code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end"
assert_mruby("", /\Acodegen error:.*\n\z/, false, ["-e", code]) assert_mruby("", /\Acodegen error:.*\n\z/, false, ["-e", code])
end end
assert('top level local variables are in file scope') do
arb, amrb = Tempfile.new('a.rb'), Tempfile.new('a.mrb')
brb, bmrb = Tempfile.new('b.rb'), Tempfile.new('b.mrb')
crb, cmrb = Tempfile.new('c.rb'), Tempfile.new('c.mrb')
drb, dmrb = Tempfile.new('d.rb'), Tempfile.new('d.mrb')
File.write arb.path, 'a = 1'
system "#{cmd('mrbc')} -g -o #{amrb.path} #{arb.path}"
File.write brb.path, 'p a'
system "#{cmd('mrbc')} -g -o #{bmrb.path} #{brb.path}"
assert_mruby("", /:1: undefined method 'a' \(NoMethodError\)\n\z/, false, ["-r", arb.path, brb.path])
assert_mruby("", /:1: undefined method 'a' \(NoMethodError\)\n\z/, false, ["-b", "-r", amrb.path, bmrb.path])
File.write crb.path, 'a, b, c = 1, 2, 3; A = -> { b = -2; [a, b, c] }'
system "#{cmd('mrbc')} -g -o #{cmrb.path} #{crb.path}"
File.write drb.path, 'a, b = 5, 6; p A.call; p a, b'
system "#{cmd('mrbc')} -g -o #{dmrb.path} #{drb.path}"
assert_mruby("[1, -2, 3]\n5\n6\n", "", true, ["-r", crb.path, drb.path])
assert_mruby("[1, -2, 3]\n5\n6\n", "", true, ["-b", "-r", cmrb.path, dmrb.path])
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment