Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

Location:
EcnlProtoTool/trunk/mruby-2.1.1
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-bin-debugger/bintest/print.rb

    r331 r439  
    11require 'open3'
    22require 'tempfile'
     3require 'strscan'
    34
    45class BinTest_MrubyBinDebugger
    5   @debug1=false
    6   @debug2=true
     6#  @debug1=false
     7#  @debug2=true
    78  def self.test(rubysource, testcase)
    89    script, bin = Tempfile.new(['test', '.rb']), Tempfile.new(['test', '.mrb'])
     
    2021    stdin_data = testcase.map{|t| t[:cmd]}.join("\n") << "\n"
    2122
     23    prompt = /^\(#{Regexp.escape(script.path)}:\d+\) /
    2224    ["bin/mrdb #{script.path}","bin/mrdb -b #{bin.path}"].each do |cmd|
    2325      o, s = Open3.capture2(cmd, :stdin_data => stdin_data)
    24 
    25       exp_vals = testcase.map{|t| t.fetch(:exp, nil)}
     26      scanner = StringScanner.new(o)
     27      scanner.skip_until(prompt)
     28      testcase.each do |tc|
     29        exp = tc[:exp]
     30        if exp
     31          act = scanner.scan_until(/\n/)
     32          break unless assert_operator act, :start_with?, exp
     33        end
     34        scanner.skip_until(prompt)
     35      end
     36
    2637=begin
    2738if @debug1
     
    4253      end
    4354=end
    44       idx = 0
    45       exp_vals.each do |exp|
    46         next if exp.nil?
    47         idx = o.index(exp, idx)
    48         assert_false idx.nil?
    49         break unless idx
    50         idx += 1
    51       end
    5255    end
    5356  end
     
    9194  # test case
    9295  tc = []
    93   tc << {:cmd=>"p (1+2",  :exp=>'$1 = SyntaxError'}
    94   tc << {:cmd=>"p bar",   :exp=>'$2 = NoMethodError'}
     96  tc << {:cmd=>"p (1+2",  :exp=>'$1 = line 1: syntax error'}
     97  tc << {:cmd=>"p bar",   :exp=>'$2 = undefined method'}
    9598
    9699  BinTest_MrubyBinDebugger.test(src, tc)
     
    318321SRC
    319322
    320   # todo: wait for 'break' to be implimented
     323  # todo: wait for 'break' to be implemented
    321324  tc = []
    322325  9.times { tc << {:cmd=>"s"} }
     
    342345  tc << {:cmd=>"p 0x100",   :exp=>'$4 = 256'}
    343346  tc << {:cmd=>"p 1_234",   :exp=>'$5 = 1234'}
    344   tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000.to_s}"}
    345   tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000.to_s}"}
     347  tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000}"}
     348  tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000}"}
    346349
    347350  tc << {:cmd=>"p 3.14",    :exp=>'$8 = 3.14'}
    348351  tc << {:cmd=>"p -12.3",   :exp=>'$9 = -12.3'}
    349   tc << {:cmd=>"p +12.000", :exp=>'$10 = 12.0'}
    350   tc << {:cmd=>"p 1e4",     :exp=>'$11 = 10000.0'}
     352  tc << {:cmd=>"p +12.000", :exp=>'$10 = 12'}
     353  tc << {:cmd=>"p 1e4",     :exp=>'$11 = 10000'}
    351354  tc << {:cmd=>"p -0.1e-2", :exp=>'$12 = -0.001'}
    352355
     
    369372  tc << {:cmd=>'p "str"',        :exp=>'$1 = "str"'}
    370373  tc << {:cmd=>'p "s\tt\rr\n"',  :exp=>'$2 = "s\\tt\\rr\\n"'}
    371   tc << {:cmd=>'p "\C-a\C-z"',   :exp=>'$3 = "\\001\\032"'}
     374  tc << {:cmd=>'p "\C-a\C-z"',   :exp=>'$3 = "\\x01\\x1a"'}
    372375  tc << {:cmd=>'p "#{foo+bar}"', :exp=>'$4 = "foobar"'}
    373376
     
    375378  tc << {:cmd=>'p \'s\\tt\\rr\\n\'', :exp=>'$6 = "s\\\\tt\\\\rr\\\\n"'}
    376379  tc << {:cmd=>'p \'\\C-a\\C-z\'',   :exp=>'$7 = "\\\\C-a\\\\C-z"'}
    377   tc << {:cmd=>'p \'#{foo+bar}\'',   :exp=>'$8 = "#{foo+bar}"'}
     380  tc << {:cmd=>'p \'#{foo+bar}\'',   :exp=>'$8 = "\\#{foo+bar}"'}
    378381
    379382  tc << {:cmd=>'p %!str!',        :exp=>'$9 = "str"'}
    380383  tc << {:cmd=>'p %!s\tt\rr\n!',  :exp=>'$10 = "s\\tt\\rr\\n"'}
    381   tc << {:cmd=>'p %!\C-a\C-z!',   :exp=>'$11 = "\\001\\032"'}
     384  tc << {:cmd=>'p %!\C-a\C-z!',   :exp=>'$11 = "\\x01\\x1a"'}
    382385  tc << {:cmd=>'p %!#{foo+bar}!', :exp=>'$12 = "foobar"'}
    383386
    384387  tc << {:cmd=>'p %Q!str!',        :exp=>'$13 = "str"'}
    385388  tc << {:cmd=>'p %Q!s\tt\rr\n!',  :exp=>'$14 = "s\\tt\\rr\\n"'}
    386   tc << {:cmd=>'p %Q!\C-a\C-z!',   :exp=>'$15 = "\\001\\032"'}
     389  tc << {:cmd=>'p %Q!\C-a\C-z!',   :exp=>'$15 = "\\x01\\x1a"'}
    387390  tc << {:cmd=>'p %Q!#{foo+bar}!', :exp=>'$16 = "foobar"'}
    388391
     
    390393  tc << {:cmd=>'p %q!s\\tt\\rr\\n!', :exp=>'$18 = "s\\\\tt\\\\rr\\\\n"'}
    391394  tc << {:cmd=>'p %q!\\C-a\\C-z!',   :exp=>'$19 = "\\\\C-a\\\\C-z"'}
    392   tc << {:cmd=>'p %q!#{foo+bar}!',   :exp=>'$20 = "#{foo+bar}"'}
     395  tc << {:cmd=>'p %q!#{foo+bar}!',   :exp=>'$20 = "\\#{foo+bar}"'}
    393396
    394397  BinTest_MrubyBinDebugger.test(src, tc)
     
    411414  tc << {:cmd=>'p [ 5,  12,   8,    10, ]', :exp=>'$2 = [5, 12, 8, 10]'}
    412415  tc << {:cmd=>'p [1,2.5,"#{foo+bar}"]',    :exp=>'$3 = [1, 2.5, "foobar"]'}
    413   tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "#{foo}"]'}
     416  tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "\#{foo}"]'}
    414417  tc << {:cmd=>'p %W[3.14 A\ &\ B #{foo}]', :exp=>'$5 = ["3.14", "A & B", "foo"]'}
    415418
     
    589592
    590593  tc << {:cmd=>'p undefined=-1',      :exp=>'$3 = -1'}
    591   tc << {:cmd=>'p "#{undefined}"',    :exp=>'$4 = NoMethodError'}
     594  tc << {:cmd=>'p "#{undefined}"',    :exp=>'$4 = undefined method'}
    592595
    593596  BinTest_MrubyBinDebugger.test(src, tc)
     
    627630
    628631  tc << {:cmd=>'p undefined=-1',    :exp=>'$14 = -1'}
    629   tc << {:cmd=>'p "#{undefined}"',  :exp=>'$15 = NoMethodError'}
     632  tc << {:cmd=>'p "#{undefined}"',  :exp=>'$15 = undefined method'}
    630633
    631634  BinTest_MrubyBinDebugger.test(src, tc)
     
    695698
    696699  tc << {:cmd=>'p undefined=-1',    :exp=>'$14 = -1'}
    697   tc << {:cmd=>'p "#{undefined}"',  :exp=>'$15 = NoMethodError'}
    698 
    699   BinTest_MrubyBinDebugger.test(src, tc)
    700 end
    701 
     700  tc << {:cmd=>'p "#{undefined}"',  :exp=>'$15 = undefined method'}
     701
     702  BinTest_MrubyBinDebugger.test(src, tc)
     703end
Note: See TracChangeset for help on using the changeset viewer.