require 'tempfile' require 'open3' def assert_mruby(exp_out, exp_err, exp_success, args) out, err, stat = Open3.capture3( *(cmd_list("mruby") + args)) assert "assert_mruby" do assert_operator(exp_out, :===, out, "standard output") assert_operator(exp_err, :===, err, "standard error") assert_equal(exp_success, stat.success?, "exit success?") end end assert('regression for #1564') do assert_mruby("", /\A-e:1:2: syntax error, .*\n\z/, false, %w[-e <<]) assert_mruby("", /\A-e:1:3: syntax error, .*\n\z/, false, %w[-e <<-]) end assert('regression for #1572') do script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb') File.write script.path, 'p "ok"' system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}" o = `#{cmd('mruby')} #{bin.path}`.strip assert_equal '"ok"', o end assert '$0 value' do script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb') # .rb script script.write "p $0\n" script.flush assert_equal "\"#{script.path}\"", `#{cmd('mruby')} "#{script.path}"`.chomp # .mrb file `#{cmd('mrbc')} -o "#{bin.path}" "#{script.path}"` assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} "#{bin.path}"`.chomp # one liner assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp end assert 'ARGV value' do assert_mruby(%{["ab", "cde"]\n}, "", true, %w[-e p(ARGV) ab cde]) assert_mruby("[]\n", "", true, %w[-e p(ARGV)]) end assert '__END__', '8.6' do script = Tempfile.new('test.rb') script.write < { 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