From 1da641a16b6fdccad639ac46cec658436029af16 Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 20 Nov 2012 11:05:20 +0000 Subject: * vm_trace.c: rename and add TracePoint APIs. (1) TracePoint.new(...){...} creates a new trace point but does not make it enable. (2) TracePoint.trace(...){...} creats a new trace point and enable it (same as old behavior). (3) TracePoint#enable make it enable (renamed from TracePoint#retrace). If block given, when enable only in block. (4) TracePoint#disable make it disable (renamed from TracePoint#untrace). If block given, when disable only in block. (5) TracePoint#enabled? returns this trace is enable or not. * test/ruby/test_settracefunc.rb: addd tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_settracefunc.rb | 54 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 0be81f024f..b5ee0eb93c 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -437,7 +437,7 @@ class TestSetTraceFunc < Test::Unit::TestCase 18: xyzzy = XYZZY.new 19: xyzzy.foo 20: begin; raise RuntimeError; rescue RuntimeError => raised_exc; end - 21: trace.untrace + 21: trace.disable EOF self.class.class_eval{remove_const(:XYZZY)} @@ -493,7 +493,7 @@ class TestSetTraceFunc < Test::Unit::TestCase [:c_call, 20, "xyzzy", Module, :===, RuntimeError,:outer, :nothing], [:c_return,20, "xyzzy", Module, :===, RuntimeError,:outer, true], [:line, 21, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing], - [:c_call, 21, "xyzzy", TracePoint, :untrace, trace, :outer, :nothing], + [:c_call, 21, "xyzzy", TracePoint, :disable, trace, :outer, :nothing], ] return events, answer_events @@ -533,6 +533,7 @@ class TestSetTraceFunc < Test::Unit::TestCase def test_tracepoint events1, answer_events = *trace_by_tracepoint() + mesg = events1.map{|e| "#{e[0]} - #{e[2]}:#{e[1]} id: #{e[4]}" }.join("\n") @@ -567,7 +568,7 @@ class TestSetTraceFunc < Test::Unit::TestCase tap{} tap{} tap{} - trace.untrace + trace.disable # passed tp is unique, `trace' object which is genereted by TracePoint.trace tps.each{|tp| @@ -581,7 +582,7 @@ class TestSetTraceFunc < Test::Unit::TestCase tp_store = tp } tap{} - trace.untrace + trace.disable assert_raise(RuntimeError){tp_store.line} assert_raise(RuntimeError){tp_store.event} @@ -593,4 +594,49 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_raise(RuntimeError){tp_store.return_value} assert_raise(RuntimeError){tp_store.raised_exception} end + + def foo + end + + def test_tracepoint_enable + ary = [] + trace = TracePoint.new(:call){|tp| + ary << tp.id + } + foo + trace.enable{ + foo + } + foo + assert_equal([:foo], ary) + end + + def test_tracepoint_disable + ary = [] + trace = TracePoint.trace(:call){|tp| + ary << tp.id + } + foo + trace.disable{ + foo + } + foo + trace.disable + assert_equal([:foo, :foo], ary) + end + + def test_tracepoint_enabled + trace = TracePoint.trace(:call){|tp| + # + } + assert_equal(true, trace.enabled?) + trace.disable{ + assert_equal(false, trace.enabled?) + trace.enable{ + assert_equal(true, trace.enabled?) + } + } + trace.disable + assert_equal(false, trace.enabled?) + end end -- cgit v1.2.3