In Files

  • mrbgems/mruby-bin-debugger/bintest/mrdb.rb
  • mrbgems/mruby-bin-debugger/bintest/print.rb

Parent

Methods

BinTest_MrubyBinDebugger

Public Class Methods

test(rubysource, testcase) click to toggle source
 
               # File mrbgems/mruby-bin-debugger/bintest/mrdb.rb, line 8
  def self.test(rubysource, testcase)
    script, bin = Tempfile.new(['test', '.rb']), Tempfile.new(['test', '.mrb'])

    # .rb
    script.write rubysource
    script.flush

    # compile
    `./bin/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|
      o, s = Open3.capture2(cmd, :stdin_data => stdin_data)

      exp_vals = testcase.map{|t| t.fetch(:exp, nil)}
      unexp_vals = testcase.map{|t| t.fetch(:unexp, nil)}

if @debug1
  o.split("\n").each_with_index do |i,actual|
    p [i,actual]
  end
end
      # compare actual / expected
      o.split("\n").each do |actual|
        next if actual.empty?
        exp = exp_vals.shift
if @debug2
  a = true
  a = actual.include?(exp) unless exp.nil?
  p [actual, exp] unless a
end
        assert_true actual.include?(exp) unless exp.nil?
      end
      # compare actual / unexpected
      o.split("\n").each do |actual|
        next if actual.empty?
        unexp = unexp_vals.shift
if @debug3
  a = false
  a = actual.include?(unexp) unless unexp.nil?
  p [actual, unexp] if a
end
        assert_false actual.include?(unexp) unless unexp.nil?
      end
    end
  end