зеркало из https://github.com/github/ruby.git
* NEWS: add Thread#add_trace_func and Thread#set_trace_func.
* test/ruby/test_settracefunc.rb (test_thread_trace): add test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2b0156b6de
Коммит
c31129ffb8
|
@ -1,3 +1,7 @@
|
|||
Fri Mar 26 23:52:07 2010 wanabe <s.wanabe@gmail.com>
|
||||
|
||||
* NEWS: add Thread#add_trace_func and Thread#set_trace_func.
|
||||
|
||||
Fri Mar 26 22:58:10 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* ext/openssl/ossl_x509store.c (ossl_x509store_initialize): initialize
|
||||
|
|
5
NEWS
5
NEWS
|
@ -122,6 +122,11 @@ with all sufficient information, see the ChangeLog file.
|
|||
* extended methods:
|
||||
* string[regexp, name] is supported for named capture.
|
||||
|
||||
* Thread
|
||||
* new methods:
|
||||
* Thread#add_trace_func
|
||||
* Thread#set_trace_func
|
||||
|
||||
* Time
|
||||
* extended feature:
|
||||
* time_t restriction is removed to represent before 1901 and after 2038.
|
||||
|
|
|
@ -294,4 +294,64 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
set_trace_func proc {raise rescue nil}
|
||||
assert_equal(42, (raise rescue 42), '[ruby-core:24118]')
|
||||
end
|
||||
|
||||
def test_thread_trace
|
||||
events = {:set => [], :add => []}
|
||||
prc = Proc.new { |event, file, lineno, mid, binding, klass|
|
||||
events[:set] << [event, lineno, mid, klass, :set]
|
||||
}
|
||||
prc2 = Proc.new { |event, file, lineno, mid, binding, klass|
|
||||
events[:add] << [event, lineno, mid, klass, :add]
|
||||
}
|
||||
|
||||
th = Thread.new do
|
||||
th = Thread.current
|
||||
eval <<-EOF.gsub(/^.*?: /, "")
|
||||
1: th.set_trace_func(prc)
|
||||
2: th.add_trace_func(prc2)
|
||||
3: class ThreadTraceInnerClass
|
||||
4: def foo
|
||||
5: x = 1 + 1
|
||||
6: end
|
||||
7: end
|
||||
8: ThreadTraceInnerClass.new.foo
|
||||
9: th.set_trace_func(nil)
|
||||
EOF
|
||||
end
|
||||
th.join
|
||||
|
||||
[["c-return", 1, :set_trace_func, Thread, :set],
|
||||
["line", 2, __method__, self.class, :set],
|
||||
["c-call", 2, :add_trace_func, Thread, :set]].each do |e|
|
||||
assert_equal(e, events[:set].shift)
|
||||
end
|
||||
|
||||
[["c-return", 2, :add_trace_func, Thread],
|
||||
["line", 3, __method__, self.class],
|
||||
["c-call", 3, :inherited, Class],
|
||||
["c-return", 3, :inherited, Class],
|
||||
["class", 3, nil, nil],
|
||||
["line", 4, nil, nil],
|
||||
["c-call", 4, :method_added, Module],
|
||||
["c-return", 4, :method_added, Module],
|
||||
["end", 7, nil, nil],
|
||||
["line", 8, __method__, self.class],
|
||||
["c-call", 8, :new, Class],
|
||||
["c-call", 8, :initialize, BasicObject],
|
||||
["c-return", 8, :initialize, BasicObject],
|
||||
["c-return", 8, :new, Class],
|
||||
["call", 4, :foo, ThreadTraceInnerClass],
|
||||
["line", 5, :foo, ThreadTraceInnerClass],
|
||||
["c-call", 5, :+, Fixnum],
|
||||
["c-return", 5, :+, Fixnum],
|
||||
["return", 6, :foo, ThreadTraceInnerClass],
|
||||
["line", 9, __method__, self.class],
|
||||
["c-call", 9, :set_trace_func, Thread]].each do |e|
|
||||
[:set, :add].each do |type|
|
||||
assert_equal(e + [type], events[type].shift)
|
||||
end
|
||||
end
|
||||
assert_equal([], events[:set])
|
||||
assert_equal([], events[:add])
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче