Sha256: b5ebcdb2a984f36d1b00af8517b3a47fc95f936273ce9ab3f1efa24d100a7fb7

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

# Test of additional tracing flag use to selectively turn on off tracing
require 'test/unit'
require_relative '../../ext/thread_frame'

class TestTracing < Test::Unit::TestCase
  def test_basic_query_set_unset
    tf = RubyVM::ThreadFrame::current
    # Test default values
    assert_equal(false, tf.trace_off?)
    assert_equal(false, tf.return_stop?)

    # Test set true
    tf.trace_off = true
    assert_equal(true, tf.trace_off?)
    tf.return_stop = true
    assert_equal(true, tf.return_stop?)

    # Test setting off when on
    tf.trace_off = nil
    assert_equal(false, tf.trace_off?)
    tf.return_stop = false
    assert_equal(false, tf.return_stop?)
  end

  def test_trace_off
    @levels = []
    def trace_hook(event, file, line, id, binding, klass)
      @levels << RubyVM::ThreadFrame::current.stack_size
    end

    def baz
      6
    end
    def bar(set_off)
      RubyVM::ThreadFrame::current.trace_off = true if set_off
      baz
      5
    end
    def foo(set_off)
      bar(set_off)
    end
    # 0x10 is the mask for tracing return events
    Thread.current.set_trace_func(method(:trace_hook).to_proc, 0x10)
    foo(false)
    assert_equal(3,  @levels.size)

    @levels = []
    Thread.current.set_trace_func(method(:trace_hook).to_proc, 0x10)
    foo(true)
    Thread.current.set_trace_func(nil)
    assert_equal(1,  @levels.size)

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rb-threadframe-0.39 test/unit/test-trace.rb
rb-threadframe-0.38 test/unit/test-trace.rb
rb-threadframe-0.37 test/unit/test-trace.rb
rb-threadframe-0.36 test/unit/test-trace.rb
rb-threadframe-0.35 test/unit/test-trace.rb
rb-threadframe-0.34 test/unit/test-trace.rb
rb-threadframe-0.33 test/unit/test-trace.rb
rb-threadframe-0.32 test/unit/test-trace.rb