rubyx/test/test_runner.rb

45 lines
1.3 KiB
Ruby
Raw Normal View History

require_relative 'helper'
2014-05-03 14:13:44 +02:00
require "yaml"
2014-05-08 18:31:36 +02: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-07-29 17:33:11 +02:00
parser = Parser::Salama.new
object_space = Vm::Program.new "Arm"
syntax = parser.parse_with_debug(string)
assert syntax
parts = Parser::Transform.new.apply(syntax)
2014-05-14 11:02:54 +02:00
# file is a list of expressions, all but the last must be a function
# and the last is wrapped as a main
parts.each_with_index do |part,index|
2014-05-14 11:02:54 +02:00
if index == (parts.length - 1)
expr = part.compile( program.context )
2014-05-14 11:02:54 +02:00
else
expr = part.compile( program.context )
2014-05-14 11:02:54 +02:00
raise "should be function definition for now" unless expr.is_a? Vm::Function
end
end
2014-05-19 16:32:41 +02:00
writer = Elf::ObjectWriter.new(program , Elf::Constants::TARGET_ARM)
2014-05-05 14:59:29 +02:00
writer.save(file.gsub(".rb" , ".o"))
2014-05-05 14:59:29 +02:00
# puts program.to_yaml
end
end