diff options
Diffstat (limited to 'mrbgems/mruby-bin-debugger/bintest')
| -rw-r--r--[-rwxr-xr-x] | mrbgems/mruby-bin-debugger/bintest/mrdb.rb | 11 | ||||
| -rw-r--r--[-rwxr-xr-x] | mrbgems/mruby-bin-debugger/bintest/print.rb | 84 |
2 files changed, 47 insertions, 48 deletions
diff --git a/mrbgems/mruby-bin-debugger/bintest/mrdb.rb b/mrbgems/mruby-bin-debugger/bintest/mrdb.rb index ae40f0a46..bc5dc4552 100755..100644 --- a/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +++ b/mrbgems/mruby-bin-debugger/bintest/mrdb.rb @@ -13,14 +13,14 @@ class BinTest_MrubyBinDebugger script.flush # compile - `./bin/mrbc -g -o "#{bin.path}" "#{script.path}"` - + `#{cmd("mrbc")} -g -o "#{bin.path}" "#{script.path}"` + # add mrdb quit testcase << {:cmd=>"quit"} stdin_data = testcase.map{|t| t[:cmd]}.join("\n") << "\n" - ["bin/mrdb #{script.path}","bin/mrdb -b #{bin.path}"].each do |cmd| + ["#{cmd('mrdb')} #{script.path}", "#{cmd('mrdb')} -b #{bin.path}"].each do |cmd| o, s = Open3.capture2(cmd, :stdin_data => stdin_data) exp_vals = testcase.map{|t| t.fetch(:exp, nil)} @@ -63,10 +63,7 @@ assert('mruby-bin-debugger(mrdb) command line') do # ruby source src = "foo = 'foo'\n" - str = "" - 103.times { - str += "1234567890" - } + str = ":#{'abcdefghij' * 103}" cmd = "p a=#{str}" # test case diff --git a/mrbgems/mruby-bin-debugger/bintest/print.rb b/mrbgems/mruby-bin-debugger/bintest/print.rb index e9d85f333..63ebded3e 100755..100644 --- a/mrbgems/mruby-bin-debugger/bintest/print.rb +++ b/mrbgems/mruby-bin-debugger/bintest/print.rb @@ -1,9 +1,10 @@ require 'open3' require 'tempfile' +require 'strscan' class BinTest_MrubyBinDebugger - @debug1=false - @debug2=true +# @debug1=false +# @debug2=true def self.test(rubysource, testcase) script, bin = Tempfile.new(['test', '.rb']), Tempfile.new(['test', '.mrb']) @@ -12,17 +13,27 @@ class BinTest_MrubyBinDebugger script.flush # compile - `./bin/mrbc -g -o "#{bin.path}" "#{script.path}"` - + `#{cmd("mrbc")} -g -o "#{bin.path}" "#{script.path}"` + # add mrdb quit testcase << {:cmd=>"quit"} stdin_data = testcase.map{|t| t[:cmd]}.join("\n") << "\n" - ["bin/mrdb #{script.path}","bin/mrdb -b #{bin.path}"].each do |cmd| + prompt = /^\(#{Regexp.escape(script.path)}:\d+\) / + ["#{cmd('mrdb')} #{script.path}", "#{cmd('mrdb')} -b #{bin.path}"].each do |cmd| o, s = Open3.capture2(cmd, :stdin_data => stdin_data) + scanner = StringScanner.new(o) + scanner.skip_until(prompt) + testcase.each do |tc| + exp = tc[:exp] + if exp + act = scanner.scan_until(/\n/) + break unless assert_operator act, :start_with?, exp + end + scanner.skip_until(prompt) + end - exp_vals = testcase.map{|t| t.fetch(:exp, nil)} =begin if @debug1 o.split("\n").each_with_index do |i,actual| @@ -41,14 +52,6 @@ end assert_true actual.include?(exp) unless exp.nil? end =end - idx = 0 - exp_vals.each do |exp| - next if exp.nil? - idx = o.index(exp, idx) - assert_false idx.nil? - break unless idx - idx += 1 - end end end end @@ -64,7 +67,7 @@ assert('mruby-bin-debugger(print) invalid arguments') do BinTest_MrubyBinDebugger.test(src, tc) end -assert('mruby-bin-debugger(print) nomal') do +assert('mruby-bin-debugger(print) normal') do # ruby source src = <<"SRC" foo = 'foo' @@ -90,13 +93,13 @@ assert('mruby-bin-debugger(print) error') do # test case tc = [] - tc << {:cmd=>"p (1+2", :exp=>'$1 = SyntaxError'} - tc << {:cmd=>"p bar", :exp=>'$2 = NoMethodError'} + tc << {:cmd=>"p (1+2", :exp=>'$1 = line 1: syntax error'} + tc << {:cmd=>"p bar", :exp=>'$2 = undefined method'} BinTest_MrubyBinDebugger.test(src, tc) end -# Kernel#instance_eval(string) does't work multiple statements. +# Kernel#instance_eval(string) doesn't work multiple statements. =begin assert('mruby-bin-debugger(print) multiple statements') do # ruby source @@ -231,7 +234,7 @@ SRC BinTest_MrubyBinDebugger.test(src, tc) end -assert('mruby-bin-debugger(print) same name:local variabe') do +assert('mruby-bin-debugger(print) same name:local variable') do # ruby source (bp is break point) src = <<"SRC" lv = 'top' @@ -261,7 +264,7 @@ SRC BinTest_MrubyBinDebugger.test(src, tc) end -assert('mruby-bin-debugger(print) same name:instance variabe') do +assert('mruby-bin-debugger(print) same name:instance variable') do # ruby source (bp is break point) src = <<"SRC" @iv = 'top' @@ -293,7 +296,7 @@ SRC BinTest_MrubyBinDebugger.test(src, tc) end -# Kernel#instance_eval(string) does't work const. +# Kernel#instance_eval(string) doesn't work const. =begin assert('mruby-bin-debugger(print) same name:const') do # ruby source (bp is break point) @@ -317,7 +320,7 @@ TestConstNameSubClass.new.m() bp = nil SRC - # todo: wait for 'break' to be implimented + # todo: wait for 'break' to be implemented tc = [] 9.times { tc << {:cmd=>"s"} } tc << {:cmd=>"p CONST", :exp=>"super class"} @@ -341,13 +344,13 @@ assert('mruby-bin-debugger(print) Literal:Numeric') do tc << {:cmd=>"p +0100", :exp=>'$3 = 64'} tc << {:cmd=>"p 0x100", :exp=>'$4 = 256'} tc << {:cmd=>"p 1_234", :exp=>'$5 = 1234'} - tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000.to_s}"} - tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000.to_s}"} + tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000}"} + tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000}"} tc << {:cmd=>"p 3.14", :exp=>'$8 = 3.14'} tc << {:cmd=>"p -12.3", :exp=>'$9 = -12.3'} - tc << {:cmd=>"p +12.000", :exp=>'$10 = 12.0'} - tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000.0'} + tc << {:cmd=>"p +12.000", :exp=>'$10 = 12'} + tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000'} tc << {:cmd=>"p -0.1e-2", :exp=>'$12 = -0.001'} BinTest_MrubyBinDebugger.test(src, tc) @@ -368,28 +371,28 @@ SRC tc << {:cmd=>'p "str"', :exp=>'$1 = "str"'} tc << {:cmd=>'p "s\tt\rr\n"', :exp=>'$2 = "s\\tt\\rr\\n"'} - tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\001\\032"'} + tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\x01\\x1a"'} tc << {:cmd=>'p "#{foo+bar}"', :exp=>'$4 = "foobar"'} tc << {:cmd=>'p \'str\'', :exp=>'$5 = "str"'} tc << {:cmd=>'p \'s\\tt\\rr\\n\'', :exp=>'$6 = "s\\\\tt\\\\rr\\\\n"'} tc << {:cmd=>'p \'\\C-a\\C-z\'', :exp=>'$7 = "\\\\C-a\\\\C-z"'} - tc << {:cmd=>'p \'#{foo+bar}\'', :exp=>'$8 = "#{foo+bar}"'} + tc << {:cmd=>'p \'#{foo+bar}\'', :exp=>'$8 = "\\#{foo+bar}"'} tc << {:cmd=>'p %!str!', :exp=>'$9 = "str"'} tc << {:cmd=>'p %!s\tt\rr\n!', :exp=>'$10 = "s\\tt\\rr\\n"'} - tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\001\\032"'} + tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\x01\\x1a"'} tc << {:cmd=>'p %!#{foo+bar}!', :exp=>'$12 = "foobar"'} tc << {:cmd=>'p %Q!str!', :exp=>'$13 = "str"'} tc << {:cmd=>'p %Q!s\tt\rr\n!', :exp=>'$14 = "s\\tt\\rr\\n"'} - tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\001\\032"'} + tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\x01\\x1a"'} tc << {:cmd=>'p %Q!#{foo+bar}!', :exp=>'$16 = "foobar"'} tc << {:cmd=>'p %q!str!', :exp=>'$17 = "str"'} tc << {:cmd=>'p %q!s\\tt\\rr\\n!', :exp=>'$18 = "s\\\\tt\\\\rr\\\\n"'} tc << {:cmd=>'p %q!\\C-a\\C-z!', :exp=>'$19 = "\\\\C-a\\\\C-z"'} - tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = "#{foo+bar}"'} + tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = "\\#{foo+bar}"'} BinTest_MrubyBinDebugger.test(src, tc) end @@ -410,7 +413,7 @@ SRC tc << {:cmd=>'p []', :exp=>'$1 = []'} tc << {:cmd=>'p [ 5, 12, 8, 10, ]', :exp=>'$2 = [5, 12, 8, 10]'} tc << {:cmd=>'p [1,2.5,"#{foo+bar}"]', :exp=>'$3 = [1, 2.5, "foobar"]'} - tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "#{foo}"]'} + tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "\#{foo}"]'} tc << {:cmd=>'p %W[3.14 A\ &\ B #{foo}]', :exp=>'$5 = ["3.14", "A & B", "foo"]'} BinTest_MrubyBinDebugger.test(src, tc) @@ -513,7 +516,7 @@ SRC tc << {:cmd=>'p a+1', :exp=>'$1 = 2'} tc << {:cmd=>'p 2-b', :exp=>'$2 = -3'} tc << {:cmd=>'p c * 3', :exp=>'$3 = 24'} - tc << {:cmd=>'p a/b', :exp=>'$4 = 0.2'} + tc << {:cmd=>'p a/b', :exp=>'$4 = 0'} tc << {:cmd=>'p c%b', :exp=>'$5 = 3'} tc << {:cmd=>'p 2**10', :exp=>'$6 = 1024'} tc << {:cmd=>'p ~3', :exp=>'$7 = -4'} @@ -588,7 +591,7 @@ SRC tc << {:cmd=>'p foo=[foo,bar,baz]', :exp=>'$2 = ["foo", "bar", "baz"]'} tc << {:cmd=>'p undefined=-1', :exp=>'$3 = -1'} - tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = NoMethodError'} + tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = undefined method'} BinTest_MrubyBinDebugger.test(src, tc) end @@ -611,13 +614,13 @@ SRC tc << {:cmd=>'p a+=9', :exp=>'$1 = 10'} tc << {:cmd=>'p b-=c', :exp=>'$2 = 15'} tc << {:cmd=>'p bar*=2', :exp=>'$3 = "barbar"'} - tc << {:cmd=>'p a/=4', :exp=>'$4 = 2.5'} + tc << {:cmd=>'p a/=4', :exp=>'$4 = 2'} tc << {:cmd=>'p c%=4', :exp=>'$5 = 2'} tc << {:cmd=>'p b&=0b0101', :exp=>'$6 = 5'} tc << {:cmd=>'p c|=0x10', :exp=>'$7 = 18'} - tc << {:cmd=>'p "#{a} #{b} #{c}"', :exp=>'$8 = "2.5 5 18"'} + tc << {:cmd=>'p "#{a} #{b} #{c}"', :exp=>'$8 = "2 5 18"'} tc << {:cmd=>'p "#{foo}#{bar}#{baz}"', :exp=>'$9 = "foobarbarbaz"'} tc << {:cmd=>'p a,b,c=[10,20,30]',:exp=>'$10 = [10, 20, 30]'} @@ -626,7 +629,7 @@ SRC tc << {:cmd=>'p [a,b]', :exp=>'$13 = [20, 10]'} tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'} - tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = NoMethodError'} + tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'} BinTest_MrubyBinDebugger.test(src, tc) end @@ -679,13 +682,13 @@ SRC tc << {:cmd=>'p a+=9', :exp=>'$1 = 10'} tc << {:cmd=>'p b-=c', :exp=>'$2 = 15'} tc << {:cmd=>'p bar*=2', :exp=>'$3 = "barbar"'} - tc << {:cmd=>'p a/=4', :exp=>'$4 = 2.5'} + tc << {:cmd=>'p a/=4', :exp=>'$4 = 2'} tc << {:cmd=>'p c%=4', :exp=>'$5 = 2'} tc << {:cmd=>'p b&=0b0101', :exp=>'$6 = 5'} tc << {:cmd=>'p c|=0x10', :exp=>'$7 = 18'} - tc << {:cmd=>'p "#{a} #{b} #{c}"', :exp=>'$8 = "2.5 5 18"'} + tc << {:cmd=>'p "#{a} #{b} #{c}"', :exp=>'$8 = "2 5 18"'} tc << {:cmd=>'p "#{foo}#{bar}#{baz}"', :exp=>'$9 = "foobarbarbaz"'} tc << {:cmd=>'p a,b,c=[10,20,30]',:exp=>'$10 = [10, 20, 30]'} @@ -694,8 +697,7 @@ SRC tc << {:cmd=>'p [a,b]', :exp=>'$13 = [20, 10]'} tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'} - tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = NoMethodError'} + tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'} BinTest_MrubyBinDebugger.test(src, tc) end - |
