diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 81b93740..9f33f4cb 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -67,10 +67,20 @@ module Elf @symbol_table.add_func_symbol name, offset, @text, linkage end - def save(filename) - to = File.open(filename, 'wb') - @object.write to - to.close + # save to either file or io + # Pass Filename as string + # or any io object + def save(file) + case file + when String + io = File.open(file, 'wb') + when IO , StringIO + io = file + else + raise "must pass io or filename, not #{file}" + end + @object.write io + io.close end end diff --git a/test/elf/helper.rb b/test/elf/helper.rb index 490d2d04..f9ed6d47 100644 --- a/test/elf/helper.rb +++ b/test/elf/helper.rb @@ -10,10 +10,10 @@ module Elf def as_main(input) in_space("def main(arg);#{input};end") end - def check(input, file) + def check(input) linker = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_binary( input , :arm ) writer = Elf::ObjectWriter.new(linker) - writer.save "test/#{file}.o" + writer.save StringIO.new end end end diff --git a/test/elf/test_something.rb b/test/elf/test_something.rb index 24452ec4..cdf14b4d 100644 --- a/test/elf/test_something.rb +++ b/test/elf/test_something.rb @@ -23,7 +23,7 @@ module Elf end HERE @exit_code = 4 - check get_preload("Integer.lt;Integer.plus") + in_space(input) , "fibo" + check get_preload("Integer.lt;Integer.plus") + in_space(input) end end end diff --git a/test/elf/test_somethingelse.rb b/test/elf/test_somethingelse.rb index f1c116de..dc0ac246 100644 --- a/test/elf/test_somethingelse.rb +++ b/test/elf/test_somethingelse.rb @@ -9,7 +9,7 @@ module Elf preload = "class Word < Data8;def putstring;X.putstring;end;end;" @stdout = hello @exit_code = hello.length - check preload + as_main(input), "hello" + check preload + as_main(input) end end end diff --git a/test/elf/test_zero.rb b/test/elf/test_zero.rb index bb5aa800..6c7af5cb 100644 --- a/test/elf/test_zero.rb +++ b/test/elf/test_zero.rb @@ -11,8 +11,12 @@ module Elf def test_empty_translate writer = Elf::ObjectWriter.new(@linker ) - writer.save "test/zero.o" + writer.save StringIO.new end + def test_empty_translate_with_debug + writer = Elf::ObjectWriter.new(@linker , debug: true ) + writer.save StringIO.new + end end end diff --git a/test/rubyx/macro/test_object_set.rb b/test/rubyx/macro/test_object_set.rb index 4bf71be2..3f9eadbb 100644 --- a/test/rubyx/macro/test_object_set.rb +++ b/test/rubyx/macro/test_object_set.rb @@ -2,7 +2,7 @@ require_relative "helper" module RubyX module Macro - class TestObjectGet < MiniTest::Test + class TestObjectSet < MiniTest::Test include MacroHelper def source <