Sha256: b8f16e234eca2993b106f6fbb73831ae5199c93ee2ec867b6a32a24c42c06ee5

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

require 'test/unit'
require_relative '../../ext/thread_frame'

class TestARGC < Test::Unit::TestCase

  def setup
    @original_compile_option = RubyVM::InstructionSequence.compile_option
    RubyVM::InstructionSequence.compile_option = {
      :trace_instruction => false,
      :specialized_instruction => false
    }
  end

  def teardown
    set_trace_func(nil)
    RubyVM::InstructionSequence.compile_option = @original_compile_option
  end

  def test_C_argc
    cmd='File.basename("/tmp/foo.rb");File.basename("/tmp/foo.rb",".rb")'
    iseq = RubyVM::InstructionSequence.compile(cmd)
    events = []
    all_events = []
    eval <<-EOF.gsub(/^.*?: /, "")
     1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass|
     2:   tf = RubyVM::ThreadFrame.current.prev(1)
     3:   all_events << [tf.argc, tf.arity, tf.type, mid]
     4:   if :basename == mid 
     5:     events << [tf.argc, tf.arity, tf.type, mid]
     6:   end
     7: })
     8: iseq.eval
     9: set_trace_func(nil)
    EOF
    # p all_events
    assert_equal([[1, -1, "CFUNC", :basename],  # 1-arg c-call
                  [1, -1, "CFUNC", :basename],  # 1-arg c-return
                  [2, -1, "CFUNC", :basename],  # 2-arg c-call
                  [2, -1, "CFUNC", :basename]   # 2-arg c-return
                 ], events)
  end
end

# We want to double-check we didn't mess up any pointers somewhere.
at_exit { GC.start  }

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rb-threadframe-0.37 test/unit/test-argc.rb
rb-threadframe-0.36 test/unit/test-argc.rb
rb-threadframe-0.35 test/unit/test-argc.rb
rb-threadframe-0.34 test/unit/test-argc.rb
rb-threadframe-0.33 test/unit/test-argc.rb
rb-threadframe-0.32 test/unit/test-argc.rb