1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
require 'test/unit'
require 'rbconfig'
require 'optparse'
if /mswin32/ !~ RUBY_PLATFORM
$ruby = './miniruby'
else
$ruby = 'miniruby'
end
$matzruby = Config::CONFIG['ruby_install_name']
ARGV.each{|opt|
if /\Aruby=(.+)/ =~ opt
$ruby = $1
elsif /\Amatzruby=(.+)/ =~ opt
$matzruby = $1
end
}
a = "matzruby: #{`#{$matzruby} -v`}"
b = "ruby : #{`#{$ruby} -v`}"
puts a, b
raise "Using same command" if a == b
class YarvTestBase < Test::Unit::TestCase
def initialize *args
super
end
def remove_const sym
Object.module_eval{
remove_const sym
}
end
def remove_method sym
Object.module_eval{
undef sym
}
end
require 'tempfile'
def exec exec_file, program
dir = []
dir << ENV['RAMDISK'] if ENV['RAMDISK']
tmpf = Tempfile.new("yarvtest_#{Process.pid}_#{Time.now.to_i}", *dir)
tmpf.write program
tmpf.close
result = `#{exec_file} #{tmpf.path}`
tmpf.open
tmpf.close(true)
result
end
def dump_and_exec exec_file, str
asmstr = <<-EOASMSTR
iseq = YARVCore::InstructionSequence.compile(<<-'EOS__')
#{str}
EOS__
p YARVCore::InstructionSequence.load(iseq.to_a).eval
EOASMSTR
exec(exec_file, asmstr)
end
def exec_ exec_file, program
exec_file.tr!('\\', '/')
r = ''
IO.popen("#{exec_file}", 'r+'){|io|
#
io.write program
io.close_write
begin
while line = io.gets
r << line
# p line
end
rescue => e
# p e
end
}
r
end
def ae str
evalstr = %{
p eval(%q{
#{str}
})
}
matzruby = exec($matzruby, evalstr)
ruby = exec($ruby, evalstr)
if $DEBUG #|| true
puts "matzruby (#$matzruby): #{matzruby}"
puts "ruby (#$ruby): #{ruby}"
end
assert_equal(matzruby.gsub(/\r/, ''), ruby.gsub(/\r/, ''), str)
# store/load test
if false # || true
yarvasm = dump_and_exec($ruby, str)
assert_equal(ruby.gsub(/\r/, ''), yarvasm.gsub(/\r/, ''))
end
end
def test_
end
end
|