rubyx/test/test_runner.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

require_relative 'helper'
2014-05-03 15:13:44 +03:00
require "yaml"
2014-05-08 19:31:36 +03:00
require "parslet/convenience"
class TestRunner < MiniTest::Test
# this creates test methods dynamically , one for each file in runners directory
def self.runnable_methods
methods = []
Dir[File.join(File.dirname(__FILE__) , "runners" , "*.rb")].each do |file|
meth = File.basename(file).split(".").first
name = "test_#{meth}"
methods << name
self.send(:define_method, name ) {
execute file
}
end
methods
end
def execute file
string = File.read(file)
2014-05-08 19:31:36 +03:00
parser = Parser::Composed.new
syntax = parser.function_definition.parse_with_debug(string)
2014-05-03 18:51:47 +03:00
program = Vm::Program.new "Arm"
2014-05-08 19:31:36 +03:00
main = Parser::Transform.new.apply(syntax)
program.main = main.compile( program.context )
program.link_at( 0 , program.context )
binary = program.assemble(StringIO.new )
2014-05-05 15:59:29 +03:00
writer = Elf::ObjectWriter.new(Elf::Constants::TARGET_ARM)
assembly = program.assemble(StringIO.new)
writer.set_text assembly.string
writer.save(file.gsub(".rb" , ".o"))
2014-05-05 15:59:29 +03:00
2014-05-05 09:35:40 +03:00
puts program.to_yaml
end
end