summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-19 22:27:53 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-19 22:27:53 +0000
commit07413b1a5e535e103b3794f28a60b74e08202e0d (patch)
tree9f1634c58b659fb82fbbaf8abf90c59eae29968f /test/ruby
parent13f0b628d7520f7a1777e39fbc6ce7b075e4bd47 (diff)
downloadruby-07413b1a5e535e103b3794f28a60b74e08202e0d.tar.gz
* test/ruby/test_settracefunc.rb: rewrite tests with
assert_consistent_call_return(). assert_consistent_call_return() is also modified to check consistency. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_settracefunc.rb139
1 files changed, 40 insertions, 99 deletions
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 3bbe5b3eea..ac9f9050f9 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -1203,6 +1203,42 @@ class TestSetTraceFunc < Test::Unit::TestCase
}, '[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::TestCase
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