Sha256: 60c880ae524608b1c3f92f0c89c12188ed30e0a7a514c4f1dcf8a7573e056767

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

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

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

class LineNumbers
  def method1
    3
  end

  def method2
    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

2 entries across 2 versions & 1 rubygems

Version Path
ruby-prof-0.11.0.rc1-x86-mingw32 test/line_number_test.rb
ruby-prof-0.11.0.rc1 test/line_number_test.rb