Sha256: 9aa2c8f980a443980a4077646fb6cbff44dbc7b564a7320ae762f3cfe427ce88

Contents?: true

Size: 1.55 KB

Versions: 23

Compression:

Stored size: 1.55 KB

Contents

#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
require 'prime'

class LineNumbers
  def method1
    a = 3
  end
  
  def method2
    a = 3
    method1
  end
  
  def method3
    sleep(1)
  end
end

# --  Tests ----
class LineNumbersTest < Test::Unit::TestCase
  def test_function_line_no
    numbers = LineNumbers.new
    
    result = RubyProf.profile do
      numbers.method2
    end

    methods = result.threads.values.first.sort.reverse
    assert_equal(3, methods.length)
    
    method = methods[0]
    assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
    assert_equal(27, method.line)
    
    method = methods[1]
    assert_equal('LineNumbers#method2', method.full_name)
    assert_equal(11, method.line)
    
    method = methods[2]
    assert_equal('LineNumbers#method1', method.full_name)
    assert_equal(7, method.line)
  end
  
  def test_c_function
    numbers = LineNumbers.new
    
    result = RubyProf.profile do
      numbers.method3
    end

    methods = result.threads.values.first.sort_by {|method| method.full_name}
    assert_equal(3, methods.length)

    # Methods:
    #   LineNumbers#method3
    #   LineNumbersTest#test_c_function
    #   Kernel#sleep

    method = methods[0]
    assert_equal('Kernel#sleep', method.full_name)
    assert_equal(0, method.line)
    
    method = methods[1]
    assert_equal('LineNumbers#method3', method.full_name)
    assert_equal(16, method.line)
    
    method = methods[2]
    assert_equal('LineNumbersTest#test_c_function', method.full_name)
    assert_equal(50, method.line)
  end
end

Version data entries

23 entries across 23 versions & 5 rubygems

Version Path
adamh-ruby-prof-0.7.3 test/line_number_test.rb
skaes-ruby-prof-0.7.3 test/line_number_test.rb
ruby-prof-danielhoey-0.8.1 test/line_number_test.rb
ruby-prof-0.8.2 test/line_number_test.rb
ruby-prof-0.8.1-x86-mingw32 test/line_number_test.rb
ruby-prof-0.8.1-x86-mswin32 test/line_number_test.rb
ruby-prof-0.8.1 test/line_number_test.rb
ruby-prof-0.7.10 test/line_number_test.rb
ruby-prof-0.7.9 test/line_number_test.rb
ruby-prof-0.7.8 test/line_number_test.rb
ruby-prof-0.7.7 test/line_number_test.rb
ruby-prof-0.7.6 test/line_number_test.rb
ruby-prof-0.7.5 test/line_number_test.rb
ruby-prof-0.7.4 test/line_number_test.rb
rdp-ruby-prof-0.7.4 test/line_number_test.rb
ruby-prof-0.7.0-x86-mswin32-60 test/line_number_test.rb
ruby-prof-0.7.3 test/line_number_test.rb
ruby-prof-0.7.2-x86-mswin32-60 test/line_number_test.rb
ruby-prof-0.7.3-x86-mswin32-60 test/line_number_test.rb
ruby-prof-0.7.1 test/line_number_test.rb