ruby-changes:34391
From: ko1 <ko1@a...>
Date: Fri, 20 Jun 2014 07:28:00 +0900 (JST)
Subject: [ruby-changes:34391] ko1:r46472 (trunk): * test/ruby/test_settracefunc.rb: rewrite tests with
ko1 2014-06-20 07:27:53 +0900 (Fri, 20 Jun 2014) New Revision: 46472 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46472 Log: * test/ruby/test_settracefunc.rb: rewrite tests with assert_consistent_call_return(). assert_consistent_call_return() is also modified to check consistency. Modified files: trunk/ChangeLog trunk/test/ruby/test_settracefunc.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46471) +++ ChangeLog (revision 46472) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jun 20 07:26:44 2014 Koichi Sasada <ko1@a...> + + * test/ruby/test_settracefunc.rb: rewrite tests with + assert_consistent_call_return(). + + assert_consistent_call_return() is also modified to check + consistency. + Fri Jun 20 07:07:28 2014 Koichi Sasada <ko1@a...> * compile.c (rb_iseq_compile_node): put start label of block after Index: test/ruby/test_settracefunc.rb =================================================================== --- test/ruby/test_settracefunc.rb (revision 46471) +++ test/ruby/test_settracefunc.rb (revision 46472) @@ -1203,6 +1203,42 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L1203 }, '[Bug #9940]' end + def method_prefix event + case event + when :call, :return + :n + when :c_call, :c_return + :c + when :b_call, :b_return + :b + end + end + + def method_label tp + "#{method_prefix(tp.event)}##{tp.method_id}" + end + + def assert_consistent_call_return message='', check_events: nil + check_events ||= %i(a_call a_return) + call_stack = [] + + TracePoint.new(*check_events){|tp| + next unless target_thread? + + case tp.event.to_s + when /call/ + call_stack << method_label(tp) + when /return/ + frame = call_stack.pop + assert_equal(frame, method_label(tp)) + end + }.enable do + yield + end + + assert_equal true, call_stack.empty? + end + def method_test_rescue_should_not_cause_b_return begin raise @@ -1220,135 +1256,40 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L1256 end def test_rescue_and_ensure_should_not_cause_b_return - curr_thread = Thread.current - trace = TracePoint.new(:b_call, :b_return){ - next if curr_thread != Thread.current - flunk("Should not reach here because there is no block.") - } - - begin - trace.enable + assert_consistent_call_return '[Bug #9957]' do method_test_rescue_should_not_cause_b_return begin method_test_ensure_should_not_cause_b_return rescue # ignore end - ensure - trace.disable end end define_method(:method_test_argument_error_on_bmethod){|correct_key: 1|} def test_argument_error_on_bmethod - events = [] - curr_thread = Thread.current - TracePoint.new(:call, :return){|tp| - next if curr_thread != Thread.current - events << [tp.event, tp.method_id] - }.enable do + assert_consistent_call_return '[Bug #9959]' do begin method_test_argument_error_on_bmethod(wrong_key: 2) rescue => e # ignore end end - - assert_equal [], events # should be empty. end def test_rb_rescue - events = [] - curr_thread = Thread.current - TracePoint.new(:a_call, :a_return){|tp| - next if curr_thread != Thread.current - events << [tp.event, tp.method_id] - }.enable do + assert_consistent_call_return '[Bug #9961]' do begin -Numeric.new rescue => e # ignore end end - - assert_equal [ - [:b_call, :test_rb_rescue], - [:c_call, :new], - [:c_call, :initialize], - [:c_return, :initialize], - [:c_return, :new], - [:c_call, :-@], - [:c_call, :coerce], - [:c_call, :to_s], - [:c_return, :to_s], - [:c_call, :new], - [:c_call, :initialize], - [:c_return, :initialize], - [:c_return, :new], - [:c_call, :exception], - [:c_return, :exception], - [:c_call, :backtrace], - [:c_return, :backtrace], - [:c_return, :coerce], # don't miss it! - [:c_call, :to_s], - [:c_return, :to_s], - [:c_call, :to_s], - [:c_return, :to_s], - [:c_call, :new], - [:c_call, :initialize], - [:c_return, :initialize], - [:c_return, :new], - [:c_call, :exception], - [:c_return, :exception], - [:c_call, :backtrace], - [:c_return, :backtrace], - [:c_return, :-@], - [:c_call, :===], - [:c_return, :===], - [:b_return, :test_rb_rescue]], events - end - - def method_prefix event - case event - when :call, :return - :n - when :c_call, :c_return - :c - when :b_call, :b_return - :b - end - end - - def method_label tp - "#{method_prefix(tp.event)}##{tp.method_id}" - end - - def assert_consistent_call_return message='', check_events: nil - check_events ||= %i(a_call a_return) - call_events = [] - return_events = [] - - TracePoint.new(*check_events){|tp| - next unless target_thread? - - case tp.event.to_s - when /call/ - call_events << method_label(tp) - when /return/ - return_events << method_label(tp) - end - }.enable do - yield - end - - assert_equal false, call_events.empty? - assert_equal false, return_events.empty? - assert_equal call_events, return_events.reverse, message end def test_b_call_with_redo - assert_consistent_call_return do + assert_consistent_call_return '[Bug #9964]' do i = 0 1.times{ break if (i+=1) > 10 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/