Files
Yukihiro "Matz" Matsumoto b059f3df25 mruby-bin-mrbc: skip multi-input debug-info bintest when bin-mruby absent
The bintest added in 0d87198c92 runs the compiled output via the
mruby binary and uses Kernel#puts in the script body.  In builds
that omit mruby-bin-mruby, the test failed with "sh: bin/mruby:
not found" before reaching the actual assertion.

Skip the assert block when bin/mruby isn't built, and switch the
script's puts to print since Kernel#puts only exists when mruby-io
is loaded (same pattern as #6814).

close #6831

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-16 21:17:41 +09:00

53 lines
2.0 KiB
Ruby

require 'tempfile'
assert('Compiling multiple files without new line in last line. #2361') do
a, b, out = Tempfile.new('a.rb'), Tempfile.new('b.rb'), Tempfile.new('out.mrb')
a.write('module A; end')
a.flush
b.write('module B; end')
b.flush
result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} #{b.path} 2>&1`
assert_equal "#{cmd_bin('mrbc')}:#{a.path}:Syntax OK", result.chomp
assert_equal 0, $?.exitstatus
end
assert('parsing function with void argument') do
a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb')
a.write('f ()')
a.flush
result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1`
assert_equal "#{cmd_bin('mrbc')}:#{a.path}:Syntax OK", result.chomp
assert_equal 0, $?.exitstatus
end
assert('embedded document with invalid terminator') do
a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb')
a.write("=begin\n=endx\n")
a.flush
result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1`
assert_equal "#{a.path}:3:0: embedded document meets end of file", result.chomp
assert_equal 1, $?.exitstatus
end
assert('debug info preserves line/filename across multiple inputs. #1316') do
# Verifying mrbc's debug info requires running the compiled output through
# the mruby binary; skip when bin-mruby isn't built. Kernel#puts only
# exists when mruby-io is loaded, so the script uses print.
skip "mruby command not built" unless File.exist?(cmd_bin("mruby"))
a = Tempfile.new(['a', '.rb'])
b = Tempfile.new(['b', '.rb'])
out = Tempfile.new(['out', '.mrb'])
a.write("# line 1\n# line 2\nprint \"from a\"\n# line 4\nundefined_in_a\n")
a.flush
b.write("# b line 1\nprint \"from b\"\n")
b.flush
`#{cmd('mrbc')} -g -o #{out.path} #{a.path} #{b.path}`
assert_equal 0, $?.exitstatus
result = `#{cmd('mruby')} -b #{out.path} 2>&1`
# Error should point at a.rb line 5 (the `undefined_in_a` line),
# not b.rb or a different line within a.rb.
assert_include result, "#{a.path}:5:"
assert_not_include result, b.path
end