File: line_number_test.rb

package info (click to toggle)
ruby-prof 0.16.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,680 kB
  • ctags: 972
  • sloc: ruby: 4,552; ansic: 1,888; makefile: 6
file content (71 lines) | stat: -rwxr-xr-x 1,545 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
# encoding: UTF-8

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

class LineNumbers
  def method1
  end

  def method2
    method1
  end

  def method3
    sleep(1)
  end
end

# --  Tests ----
class LineNumbersTest < TestCase
  def test_function_line_no
    numbers = LineNumbers.new

    result = RubyProf.profile do
      numbers.method2
    end

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

    method = methods[0]
    assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
    assert_equal(25, method.line)

    method = methods[1]
    assert_equal('LineNumbers#method2', method.full_name)
    assert_equal(10, 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.first.methods.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(14, method.line)

    method = methods[2]
    assert_equal('LineNumbersTest#test_c_function', method.full_name)
    assert_equal(48, method.line)
  end
end