rubyx/test/fragments/helper.rb

48 lines
1.5 KiB
Ruby
Raw Normal View History

require_relative '../helper'
# simple tests to check parsing pworks and the first classes come out right.
#
# build up from small to check larger expressions are correct
2014-05-21 20:37:04 +02:00
module Fragments
def check
expressions = Virtual.machine.boot.compile_main @string_input
@expect.each_with_index do | should , i |
2015-07-19 11:33:33 +02:00
assert expressions[i].is_a?(Virtual::Slot) , "compiles should return slots, not #{should.class}"
assert_equal should , expressions[i].class
end
2015-07-19 10:15:38 +02:00
# Virtual.machine.run_passes
end
# helper to write the file
def write name
writer = Elf::ObjectWriter.new(@object_machine , Elf::Constants::TARGET_ARM)
assembly = writer.text
writer.save("#{name}.o")
function = @object_machine.classes[@target[0]]
2014-06-05 15:27:25 +02:00
assert function , "no class #{@target[0]}"
function = function.get_function(@target[1])
2014-06-05 15:27:25 +02:00
assert function , "no function #{@target[1]} for class #{@target[0]}"
io = StringIO.new
function.assemble io
assembly = io.string
# use this for getting the bytes to compare to :
2014-06-12 08:07:03 +02:00
puts bytes(assembly)
assembly.bytes.each_with_index do |byte , index|
is = @should[index]
assert_equal Fixnum , is.class , "@#{index.to_s(16)} = #{is}"
assert_equal byte , is , "@#{index.to_s(16)} #{byte.to_s(16)} != #{is.to_s(16)}"
end
if( RbConfig::CONFIG["build_cpu"] == "arm")
system "ld -N #{name}.o"
result = %x[./a.out]
assert_equal @output , result
end
end
def bytes string
"[" + string.bytes.collect{|b| "0x"+ b.to_s(16)}.join(",") + "]"
end
end