* test/ruby/test_settracefunc.rb: fixed tests for set_trace_func.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fef818ec82
commit
862cd3cd3c
@ -1,3 +1,7 @@
|
|||||||
|
Tue Nov 13 00:36:16 2007 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* test/ruby/test_settracefunc.rb: fixed tests for set_trace_func.
|
||||||
|
|
||||||
Mon Nov 12 19:47:29 2007 NAKAMURA Usaku <usa@ruby-lang.org>
|
Mon Nov 12 19:47:29 2007 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* thread.c (call_trace_proc): should return value.
|
* thread.c (call_trace_proc): should return value.
|
||||||
|
@ -1,139 +1,174 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
class TestSetTraceFunc < Test::Unit::TestCase
|
class TestSetTraceFunc < Test::Unit::TestCase
|
||||||
def foo; end;
|
def setup
|
||||||
|
@original_compile_option = VM::InstructionSequence.compile_option
|
||||||
def bar
|
VM::InstructionSequence.compile_option = {
|
||||||
events = []
|
:trace_instruction => true,
|
||||||
set_trace_func(Proc.new { |event, file, lineno, mid, bidning, klass|
|
:specialized_instruction => false
|
||||||
events << [event, lineno, mid, klass]
|
}
|
||||||
})
|
|
||||||
return events
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_event
|
def teardown
|
||||||
|
VM::InstructionSequence.compile_option = @original_compile_option
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_c_call
|
||||||
events = []
|
events = []
|
||||||
set_trace_func(Proc.new { |event, file, lineno, mid, bidning, klass|
|
eval <<-EOF.gsub(/^.*?: /, "")
|
||||||
events << [event, lineno, mid, klass]
|
1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass|
|
||||||
})
|
2: events << [event, lineno, mid, klass]
|
||||||
a = 1
|
3: })
|
||||||
foo
|
4: x = 1 + 1
|
||||||
a
|
5: set_trace_func(nil)
|
||||||
b = 1 + 2
|
EOF
|
||||||
if b == 3
|
assert_equal(["c-return", 3, :set_trace_func, Kernel],
|
||||||
case b
|
events.shift)
|
||||||
when 2
|
assert_equal(["line", 4, __method__, self.class],
|
||||||
c = "b == 2"
|
events.shift)
|
||||||
when 3
|
assert_equal(["c-call", 4, :+, Fixnum],
|
||||||
c = "b == 3"
|
events.shift)
|
||||||
end
|
assert_equal(["c-return", 4, :+, Fixnum],
|
||||||
end
|
events.shift)
|
||||||
begin
|
assert_equal(["line", 5, __method__, self.class],
|
||||||
raise "error"
|
events.shift)
|
||||||
rescue
|
assert_equal(["c-call", 5, :set_trace_func, Kernel],
|
||||||
end
|
events.shift)
|
||||||
eval("class Foo; end")
|
|
||||||
set_trace_func nil
|
|
||||||
|
|
||||||
assert_equal(["c-return", 18, :set_trace_func, Kernel],
|
|
||||||
events.shift) # TODO
|
|
||||||
assert_equal(["line", 19, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # a = 1
|
|
||||||
assert_equal(["line", 20, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # foo
|
|
||||||
assert_equal(["call", 4, :foo, TestSetTraceFunc],
|
|
||||||
events.shift) # foo
|
|
||||||
assert_equal(["return", 4, :foo, TestSetTraceFunc],
|
|
||||||
events.shift) # foo
|
|
||||||
assert_equal(["line", 21, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # a
|
|
||||||
assert_equal(["line", 22, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # b = 1 + 2
|
|
||||||
assert_equal(["c-call", 22, :+, Fixnum],
|
|
||||||
events.shift) # 1 + 2
|
|
||||||
assert_equal(["c-return", 22, :+, Fixnum],
|
|
||||||
events.shift) # 1 + 2
|
|
||||||
assert_equal(["line", 23, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # if b == 3
|
|
||||||
assert_equal(["line", 23, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # if b == 3
|
|
||||||
assert_equal(["c-call", 23, :==, Fixnum],
|
|
||||||
events.shift) # b == 3
|
|
||||||
assert_equal(["c-return", 23, :==, Fixnum],
|
|
||||||
events.shift) # b == 3
|
|
||||||
assert_equal(["line", 24, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # case b
|
|
||||||
assert_equal(["line", 25, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # when 2
|
|
||||||
assert_equal(["c-call", 25, :===, Kernel],
|
|
||||||
events.shift) # when 2
|
|
||||||
assert_equal(["c-call", 25, :==, Fixnum],
|
|
||||||
events.shift) # when 2
|
|
||||||
assert_equal(["c-return", 25, :==, Fixnum],
|
|
||||||
events.shift) # when 2
|
|
||||||
assert_equal(["c-return", 25, :===, Kernel],
|
|
||||||
events.shift) # when 2
|
|
||||||
assert_equal(["line", 27, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # when 3
|
|
||||||
assert_equal(["c-call", 27, :===, Kernel],
|
|
||||||
events.shift) # when 3
|
|
||||||
assert_equal(["c-return", 27, :===, Kernel],
|
|
||||||
events.shift) # when 3
|
|
||||||
assert_equal(["line", 28, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # c = "b == 3"
|
|
||||||
assert_equal(["line", 31, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # begin
|
|
||||||
assert_equal(["line", 32, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-call", 32, :raise, Kernel],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-call", 32, :new, Class],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-call", 32, :initialize, Exception],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-return", 32, :initialize, Exception],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-return", 32, :new, Class],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-call", 32, :backtrace, Exception],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-return", 32, :backtrace, Exception],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-call", 32, :set_backtrace, Exception],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-return", 32, :set_backtrace, Exception],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["raise", 32, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["c-return", 32, :raise, Kernel],
|
|
||||||
events.shift) # raise "error"
|
|
||||||
assert_equal(["line", 35, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # eval(<<EOF)
|
|
||||||
assert_equal(["c-call", 35, :eval, Kernel],
|
|
||||||
events.shift) # eval(<<EOF)
|
|
||||||
assert_equal(["line", 1, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # class Foo
|
|
||||||
assert_equal(["c-call", 1, :inherited, Class],
|
|
||||||
events.shift) # class Foo
|
|
||||||
assert_equal(["c-return", 1, :inherited, Class],
|
|
||||||
events.shift) # class Foo
|
|
||||||
assert_equal(["class", 1, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # class Foo
|
|
||||||
assert_equal(["end", 1, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # class Foo
|
|
||||||
assert_equal(["c-return", 35, :eval, Kernel],
|
|
||||||
events.shift) # eval(<<EOF)
|
|
||||||
assert_equal(["line", 36, :test_event, TestSetTraceFunc],
|
|
||||||
events.shift) # set_trace_func nil
|
|
||||||
assert_equal(["c-call", 36, :set_trace_func, Kernel],
|
|
||||||
events.shift) # set_trace_func nil
|
|
||||||
assert_equal([], events)
|
assert_equal([], events)
|
||||||
|
end
|
||||||
|
|
||||||
events = bar
|
def test_call
|
||||||
set_trace_func(nil)
|
events = []
|
||||||
assert_equal(["return", 7, :bar, TestSetTraceFunc], events.shift)
|
eval <<-EOF.gsub(/^.*?: /, "")
|
||||||
assert_equal(["line", 131, :test_event, TestSetTraceFunc], events.shift)
|
1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass|
|
||||||
assert_equal(["c-call", 131, :set_trace_func, Kernel], events.shift)
|
2: events << [event, lineno, mid, klass]
|
||||||
|
3: })
|
||||||
|
4: def add(x, y)
|
||||||
|
5: x + y
|
||||||
|
6: end
|
||||||
|
7: x = add(1, 1)
|
||||||
|
8: set_trace_func(nil)
|
||||||
|
EOF
|
||||||
|
assert_equal(["c-return", 3, :set_trace_func, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 4, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :method_added, Module],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :method_added, Module],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 7, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["call", 6, :add, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 5, :add, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 5, :+, Fixnum],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 5, :+, Fixnum],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["return", 6, :add, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 8, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 8, :set_trace_func, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal([], events)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_class
|
||||||
|
events = []
|
||||||
|
eval <<-EOF.gsub(/^.*?: /, "")
|
||||||
|
1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass|
|
||||||
|
2: events << [event, lineno, mid, klass]
|
||||||
|
3: })
|
||||||
|
4: class Foo
|
||||||
|
5: def bar
|
||||||
|
6: end
|
||||||
|
7: end
|
||||||
|
8: x = Foo.new.bar
|
||||||
|
9: set_trace_func(nil)
|
||||||
|
EOF
|
||||||
|
assert_equal(["c-return", 3, :set_trace_func, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 4, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :inherited, Class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :inherited, Class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["class", 7, nil, nil],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 5, nil, nil],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 5, :method_added, Module],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 5, :method_added, Module],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["end", 7, nil, nil],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 8, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 8, :new, Class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 8, :initialize, BasicObject],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 8, :initialize, BasicObject],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 8, :new, Class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["call", 6, :bar, Foo],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["return", 6, :bar, Foo],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 9, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 9, :set_trace_func, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal([], events)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_raise
|
||||||
|
events = []
|
||||||
|
eval <<-EOF.gsub(/^.*?: /, "")
|
||||||
|
1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass|
|
||||||
|
2: events << [event, lineno, mid, klass]
|
||||||
|
3: })
|
||||||
|
4: raise "error" rescue nil
|
||||||
|
5: set_trace_func(nil)
|
||||||
|
EOF
|
||||||
|
assert_equal(["c-return", 3, :set_trace_func, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 4, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :raise, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :new, Class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :initialize, Exception],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :initialize, Exception],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :new, Class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :backtrace, Exception],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :backtrace, Exception],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :set_backtrace, Exception],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :set_backtrace, Exception],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["raise", 4, :raise, Kernel],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 4, :===, Module],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-return", 4, :===, Module],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["line", 5, __method__, self.class],
|
||||||
|
events.shift)
|
||||||
|
assert_equal(["c-call", 5, :set_trace_func, Kernel],
|
||||||
|
events.shift)
|
||||||
assert_equal([], events)
|
assert_equal([], events)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user