File: call_tree_visitor_test.rb

package info (click to toggle)
ruby-prof 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 844 kB
  • sloc: ruby: 6,448; ansic: 2,707; makefile: 6
file content (32 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby
# encoding: UTF-8

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

class CallTreeVisitorTest < TestCase
  def setup
    # Need to use wall time for this test due to the sleep calls
    RubyProf::measure_mode = RubyProf::WALL_TIME
  end

  def test_visit
    result = RubyProf.profile do
      RubyProf::C1.sleep_wait
    end

    visitor = RubyProf::CallTreeVisitor.new(result.threads.first.call_tree)

    method_names = Array.new

    visitor.visit do |call_tree, event|
      method_names << call_tree.target.full_name if event == :enter
    end

    assert_equal(3, method_names.length)
    assert_equal("CallTreeVisitorTest#test_visit", method_names[0])
    assert_equal("<Class::RubyProf::C1>#sleep_wait", method_names[1])
    assert_equal("Kernel#sleep", method_names[2])
  end
end