test/line_number_test.rb in ruby-prof-0.18.0 vs test/line_number_test.rb in ruby-prof-1.0.0
- old
+ new
@@ -2,79 +2,160 @@
# encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
class LineNumbers
- def method1
+ def method_1
+ method_2
+ filler = 1
+ method_3
end
- def method2
- method1
+ def method_2
+ filler = 1
+ 2.times do |i|
+ filler = 2
+ method_3
+ end
end
- def method3
+ def method_3
+ sleep(0.4)
+ method_4
+ end
+
+ def method_4
sleep(1)
end
end
# -- Tests ----
class LineNumbersTest < TestCase
def test_function_line_no
numbers = LineNumbers.new
result = RubyProf.profile do
- numbers.method2
+ numbers.method_1
end
methods = result.threads.first.methods.sort.reverse
- assert_equal(3, methods.length)
+ assert_equal(7, methods.length)
+ # Method 0
method = methods[0]
assert_equal('LineNumbersTest#test_function_line_no', method.full_name)
- assert_equal(25, method.line)
+ assert_equal(37, method.line)
+ assert_equal(1, method.callers.count)
+ call_info = method.callers[0]
+ assert_nil(call_info.parent)
+ assert_equal(37, call_info.line)
+
+ assert_equal(1, method.callees.count)
+ call_info = method.callees[0]
+ assert_equal('LineNumbers#method_1', call_info.target.full_name)
+ assert_equal(37, call_info.line)
+
+ # Method 1
method = methods[1]
- assert_equal('LineNumbers#method2', method.full_name)
- if RUBY_VERSION < "2.5"
- assert_equal(10, method.line)
- else
- assert_equal(11, method.line)
- end
+ assert_equal('LineNumbers#method_1', method.full_name)
+ assert_equal(7, method.line)
+ assert_equal(1, method.callers.count)
+ call_info = method.callers[0]
+ assert_equal('LineNumbersTest#test_function_line_no', call_info.parent.full_name)
+ assert_equal(37, call_info.line)
+
+ assert_equal(2, method.callees.count)
+ call_info = method.callees[0]
+ assert_equal('LineNumbers#method_2', call_info.target.full_name)
+ assert_equal(8, call_info.line)
+
+ call_info = method.callees[1]
+ assert_equal('LineNumbers#method_3', call_info.target.full_name)
+ assert_equal(10, call_info.line)
+
+ # Method 2
method = methods[2]
- assert_equal('LineNumbers#method1', method.full_name)
- assert_equal(7, method.line)
- end
+ assert_equal('LineNumbers#method_3', method.full_name)
+ assert_equal(21, method.line)
- def test_c_function
- numbers = LineNumbers.new
+ assert_equal(2, method.callers.count)
+ call_info = method.callers[0]
+ assert_equal('Integer#times', call_info.parent.full_name)
+ assert_equal(17, call_info.line)
- result = RubyProf.profile do
- numbers.method3
- end
+ call_info = method.callers[1]
+ assert_equal('LineNumbers#method_1', call_info.parent.full_name)
+ assert_equal(10, call_info.line)
- methods = result.threads.first.methods.sort_by {|method| method.full_name}
- assert_equal(3, methods.length)
+ assert_equal(2, method.callees.count)
+ call_info = method.callees[0]
+ assert_equal('Kernel#sleep', call_info.target.full_name)
+ assert_equal(22, call_info.line)
- # Methods:
- # LineNumbers#method3
- # LineNumbersTest#test_c_function
- # Kernel#sleep
+ call_info = method.callees[1]
+ assert_equal('LineNumbers#method_4', call_info.target.full_name)
+ assert_equal(23, call_info.line)
- method = methods[0]
+ # Method 3
+ method = methods[3]
assert_equal('Kernel#sleep', method.full_name)
assert_equal(0, method.line)
- method = methods[1]
- assert_equal('LineNumbers#method3', method.full_name)
- if RUBY_VERSION < "2.5"
- assert_equal(14, method.line)
- else
- assert_equal(15, method.line)
- end
+ assert_equal(2, method.callers.count)
+ call_info = method.callers[0]
+ assert_equal('LineNumbers#method_3', call_info.parent.full_name)
+ assert_equal(22, call_info.line)
- method = methods[2]
- assert_equal('LineNumbersTest#test_c_function', method.full_name)
- assert_equal(52, method.line)
- end
+ call_info = method.callers[1]
+ assert_equal('LineNumbers#method_4', call_info.parent.full_name)
+ assert_equal(27, call_info.line)
+ assert_equal(0, method.callees.count)
+
+ # Method 4
+ method = methods[4]
+ assert_equal('LineNumbers#method_4', method.full_name)
+ assert_equal(26, method.line)
+
+ assert_equal(1, method.callers.count)
+ call_info = method.callers[0]
+ assert_equal('LineNumbers#method_3', call_info.parent.full_name)
+ assert_equal(23, call_info.line)
+
+ assert_equal(1, method.callees.count)
+ call_info = method.callees[0]
+ assert_equal('Kernel#sleep', call_info.target.full_name)
+ assert_equal(27, call_info.line)
+
+ # Method 5
+ method = methods[5]
+ assert_equal('LineNumbers#method_2', method.full_name)
+ assert_equal(13, method.line)
+
+ assert_equal(1, method.callers.count)
+ call_info = method.callers[0]
+ assert_equal('LineNumbers#method_1', call_info.parent.full_name)
+ assert_equal(8, call_info.line)
+
+ assert_equal(1, method.callees.count)
+ call_info = method.callees[0]
+ assert_equal('Integer#times', call_info.target.full_name)
+ assert_equal(15, call_info.line)
+
+ # Method 6
+ method = methods[6]
+ assert_equal('Integer#times', method.full_name)
+ assert_equal(0, method.line)
+
+ assert_equal(1, method.callers.count)
+ call_info = method.callers[0]
+ assert_equal('LineNumbers#method_2', call_info.parent.full_name)
+ assert_equal(15, call_info.line)
+
+ assert_equal(1, method.callees.count)
+ call_info = method.callees[0]
+ assert_equal('LineNumbers#method_3', call_info.target.full_name)
+ assert_equal(17, call_info.line)
+ end
end