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