Sha256: 35d0e20d4f5a3a500383681e3f22392de5bfb7e58987878a1f9fc9251d8d4ab4

Contents?: true

Size: 1.93 KB

Versions: 12

Compression:

Stored size: 1.93 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

require File.expand_path('../test_helper', __FILE__)

# --  Tests ----
class CallTreesTest < TestCase
  def some_method_1
    some_method_2
  end

  def some_method_2
  end

  def test_call_infos
    result = RubyProf::Profile.profile do
      some_method_1
    end

    thread = result.threads.first
    assert_equal(3, thread.methods.length)

    method = thread.methods[0]
    assert_equal('CallTreesTest#test_call_infos', method.full_name)

    call_trees = method.call_trees
    assert_empty(call_trees.callers)
    assert_equal(1, call_trees.callees.length)
    assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
    assert_equal('CallTreesTest#some_method_1', call_trees.callees[0].target.full_name)

    method = thread.methods[1]
    assert_equal('CallTreesTest#some_method_1', method.full_name)

    call_trees = method.call_trees
    assert_equal(1, call_trees.callers.length)
    assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
    assert_equal('CallTreesTest#test_call_infos', call_trees.callers[0].parent.target.full_name)
    assert_equal(1, call_trees.callees.length)
    assert_kind_of(RubyProf::CallTree, call_trees.callees[0])
    assert_equal('CallTreesTest#some_method_2', call_trees.callees[0].target.full_name)

    method = thread.methods[2]
    assert_equal('CallTreesTest#some_method_2', method.full_name)

    call_trees = method.call_trees
    assert_equal(1, call_trees.callers.length)
    assert_kind_of(RubyProf::CallTree, call_trees.callers[0])
    assert_equal('CallTreesTest#some_method_1', call_trees.callers[0].parent.target.full_name)
    assert_empty(call_trees.callees)
  end

  def test_gc
    result = RubyProf::Profile.profile do
      some_method_1
    end

    method = result.threads.first.methods[1]

    100.times do |i|
      method.call_trees.callers
      GC.start
    end
    assert(true)
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
ruby-prof-1.7.1-x64-mingw-ucrt test/call_trees_test.rb
ruby-prof-1.7.1 test/call_trees_test.rb
ruby-prof-1.7.0-x64-mingw-ucrt test/call_trees_test.rb
ruby-prof-1.7.0 test/call_trees_test.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/test/call_trees_test.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/test/call_trees_test.rb
ruby-prof-1.6.3-x64-mingw-ucrt test/call_trees_test.rb
ruby-prof-1.6.3 test/call_trees_test.rb
ruby-prof-1.6.2-x64-mingw-ucrt test/call_trees_test.rb
ruby-prof-1.6.2 test/call_trees_test.rb
ruby-prof-1.6.1 test/call_trees_test.rb
ruby-prof-1.6.1-x64-mingw-ucrt test/call_trees_test.rb