summaryrefslogtreecommitdiff
path: root/test/ruby/test_settracefunc.rb
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-03 05:10:41 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-03 05:10:41 +0000
commitcd0fec37281a72d402981894b764d27ab7d1fb39 (patch)
tree7798f0f28cbf31b54fd44887585c878c35277a76 /test/ruby/test_settracefunc.rb
parent25d1891899be492dc64bb6852741d4f112feba64 (diff)
Add TracePoint#parameters
It can be used to get the parameters' information of method and block. There was no way to get block parameters. It was possible but ineffective to get method parameters via Method object: `tp.defined_class.method(tp.method_id).parameters` TracePoint#parameters allows us to get the information easily. [Feature #14694] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_settracefunc.rb')
-rw-r--r--test/ruby/test_settracefunc.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 7157d8c482..fe2201a30e 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -703,6 +703,45 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_equal(false, trace.enabled?)
end
+ def parameter_test(a, b, c)
+ yield
+ end
+
+ def test_tracepoint_parameters
+ trace = TracePoint.new(:line, :class, :end, :call, :return, :b_call, :b_return, :c_call, :c_return, :raise){|tp|
+ next if !target_thread?
+ next if tp.path != __FILE__
+ case tp.event
+ when :call, :return
+ assert_equal([[:req, :a], [:req, :b], [:req, :c]], tp.parameters)
+ when :b_call, :b_return
+ next if tp.parameters == []
+ if tp.parameters.first == [:opt, :x]
+ assert_equal([[:opt, :x], [:opt, :y], [:opt, :z]], tp.parameters)
+ else
+ assert_equal([[:req, :p], [:req, :q], [:req, :r]], tp.parameters)
+ end
+ when :c_call, :c_return
+ assert_equal([[:req]], tp.parameters) if tp.method_id == :getbyte
+ when :line, :class, :end, :raise
+ assert_raise(RuntimeError) { tp.parameters }
+ end
+ }
+ obj = Object.new
+ trace.enable{
+ parameter_test(1, 2, 3) {|x, y, z|
+ }
+ lambda {|p, q, r| }.call(4, 5, 6)
+ "".getbyte(0)
+ class << obj
+ end
+ begin
+ raise
+ rescue
+ end
+ }
+ end
+
def method_test_tracepoint_return_value obj
obj
end