rb-threadframe 0.39 → 0.40

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
1
  require 'test/unit'
2
- require_relative '../../ext/thread_frame'
2
+ require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
3
3
 
4
4
  class TestISeq < Test::Unit::TestCase
5
5
 
6
6
  class C
7
7
  def initialize(test_obj, optional=true)
8
- iseq = RubyVM::ThreadFrame::current.iseq
8
+ iseq = RubyVM::Frame::current.iseq
9
9
  test_obj.assert_equal('test_obj', iseq.local_name(0))
10
10
  test_obj.assert_equal(1, iseq.arity)
11
11
  test_obj.assert_equal(-1, iseq.arg_block)
@@ -15,7 +15,7 @@ class TestISeq < Test::Unit::TestCase
15
15
 
16
16
  def test_fields
17
17
  start_lineno = __LINE__ - 1;
18
- iseq = RubyVM::ThreadFrame::current.iseq
18
+ iseq = RubyVM::Frame::current.iseq
19
19
  assert iseq
20
20
  assert_equal('test_fields', iseq.name)
21
21
  ## FIXME: Why does this fail?
@@ -26,7 +26,7 @@ class TestISeq < Test::Unit::TestCase
26
26
  assert_equal(0, iseq.arg_opts)
27
27
  assert_equal(4, iseq.local_table_size)
28
28
  x = lambda do |x,y|
29
- iseq = RubyVM::ThreadFrame::current.iseq
29
+ iseq = RubyVM::Frame::current.iseq
30
30
  assert iseq
31
31
  assert_equal(2, iseq.arity)
32
32
  assert_equal(-1, iseq.arg_block)
@@ -45,7 +45,7 @@ class TestISeq < Test::Unit::TestCase
45
45
  x.call(1,2)
46
46
 
47
47
  x = Proc.new do |a|
48
- iseq = RubyVM::ThreadFrame::current.iseq
48
+ iseq = RubyVM::Frame::current.iseq
49
49
  assert iseq
50
50
  assert_equal(1, iseq.arity)
51
51
  assert_equal(-1, iseq.arg_block)
@@ -70,8 +70,8 @@ class TestISeq < Test::Unit::TestCase
70
70
  end
71
71
 
72
72
  def test_iseq_equal
73
- tf = RubyVM::ThreadFrame.current
74
- tf2 = RubyVM::ThreadFrame.current
73
+ tf = RubyVM::Frame.current
74
+ tf2 = RubyVM::Frame.current
75
75
  while !tf.iseq do
76
76
  tf = tf.prev
77
77
  tf2 = tf2.prev
@@ -90,7 +90,8 @@ class TestISeq < Test::Unit::TestCase
90
90
  # FIXME: killcache interface will probably change. Try make less sensitive
91
91
  # to compile sequence
92
92
  def test_iseq_killcache
93
- iseq = RubyVM::ThreadFrame.current.iseq
93
+ skip "killcache doesn't work on 1.9.3" if '1.9.3' == RUBY_VERSION
94
+ iseq = RubyVM::Frame.current.iseq
94
95
  count = iseq.killcache
95
96
  if 0 != count
96
97
  assert_equal(0, iseq.killcache,
@@ -100,7 +101,7 @@ class TestISeq < Test::Unit::TestCase
100
101
 
101
102
  def test_offsetlines
102
103
  start = __LINE__ - 1
103
- tf = RubyVM::ThreadFrame::current
104
+ tf = RubyVM::Frame::current
104
105
  iseq = tf.iseq
105
106
  offlines = iseq.offsetlines
106
107
  pc = tf.pc_offset
@@ -4,7 +4,7 @@ require_relative '../../lib/iseq_extra'
4
4
  class TestLibISeqExtra < Test::Unit::TestCase
5
5
 
6
6
  def test_basic
7
- tf = RubyVM::ThreadFrame.current
7
+ tf = RubyVM::Frame.current
8
8
  iseq = tf.iseq
9
9
  # See that we get the same line numbers
10
10
  assert_equal(iseq.offsetlines.values.flatten.uniq.sort,
@@ -17,8 +17,6 @@ class TestLibISeqExtra < Test::Unit::TestCase
17
17
  iseq.line2offsets(__LINE__-1).sort)
18
18
 
19
19
  assert_equal([], iseq.line2offsets(__LINE__+100))
20
- top_iseq = tf.prev(-1).iseq
21
- assert_equal('method', RubyVM::InstructionSequence::TYPE2STR[top_iseq.type])
22
20
 
23
21
  iseq2 = tf.iseq
24
22
  # Different object ids...
@@ -37,6 +35,17 @@ class TestLibISeqExtra < Test::Unit::TestCase
37
35
  end
38
36
  end
39
37
 
38
+ def test_iseq_type
39
+ tf = RubyVM::Frame.current
40
+ top_iseq = tf.prev(-1).iseq
41
+ if '1.9.3' == RUBY_VERSION
42
+ assert_equal('METHOD', tf.prev.type)
43
+ else
44
+ assert_equal('method',
45
+ RubyVM::InstructionSequence::TYPE2STR[top_iseq.type])
46
+ end
47
+ end
48
+
40
49
  def test_format_args
41
50
  # These prototypes are from IRB
42
51
  def evaluate(context, statements, file = __FILE__, line = __LINE__); end
@@ -55,9 +64,9 @@ class TestLibISeqExtra < Test::Unit::TestCase
55
64
  end
56
65
 
57
66
  def test_iseq_parent
58
- parent_iseq = RubyVM::ThreadFrame::current.iseq
67
+ parent_iseq = RubyVM::Frame::current.iseq
59
68
  1.times do
60
- tf = RubyVM::ThreadFrame::current
69
+ tf = RubyVM::Frame::current
61
70
  assert_equal(true, tf.iseq.parent.equal?(parent_iseq))
62
71
  end
63
72
  end
@@ -1,6 +1,7 @@
1
1
  require 'test/unit'
2
- require_relative '../../ext/thread_frame'
3
- require_relative '../../lib/thread_frame'
2
+ require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
3
+ require_relative '../../lib/thread_frame' if '1.9.2' == RUBY_VERSION
4
+ require_relative '../../lib/iseq_extra'
4
5
 
5
6
  $global_test_line = __LINE__
6
7
 
@@ -9,22 +10,22 @@ class TestLibISeq < Test::Unit::TestCase
9
10
  TEST_LINE = __LINE__
10
11
 
11
12
  def test_sha1
12
- iseq1 = RubyVM::ThreadFrame::current.iseq
13
- iseq2 = RubyVM::ThreadFrame::current.iseq
13
+ iseq1 = RubyVM::Frame::current.iseq
14
+ iseq2 = RubyVM::Frame::current.iseq
14
15
  assert_equal(iseq1.sha1, iseq2.sha1,
15
16
  "SHA1 for same threadframe should match")
16
17
  end
17
18
 
18
19
  def test_lines
19
20
  line = __LINE__
20
- iseq = RubyVM::ThreadFrame::current.iseq
21
+ iseq = RubyVM::Frame::current.iseq
21
22
  assert_equal((line-1..__LINE__+2).to_a, iseq.lines,
22
23
  "lines of test_lines() don't match")
23
24
  end
24
25
 
25
26
  def test_locate_line
26
27
  line = __LINE__
27
- iseq = RubyVM::ThreadFrame::current.iseq
28
+ iseq = RubyVM::Frame::current.iseq
28
29
  assert iseq.locate_line(line)
29
30
  assert_nil iseq.locate_line(line - 2)
30
31
  end
@@ -34,11 +35,11 @@ class TestLibISeq < Test::Unit::TestCase
34
35
  # It is lame how little we can do here.
35
36
  line = __LINE__
36
37
  def find_line(line) # :nodoc
37
- tf = RubyVM::ThreadFrame.current
38
+ tf = RubyVM::Frame.current
38
39
  assert(tf.iseq.find_iseq_with_line(line),
39
40
  "should have found line #{line}")
40
41
  end
41
- tf = RubyVM::ThreadFrame.current
42
+ tf = RubyVM::Frame.current
42
43
  find_line(line+2)
43
44
  # line2 = nil
44
45
  # 1.times do
@@ -1,9 +1,9 @@
1
1
  require 'test/unit'
2
- require_relative '../../ext/thread_frame'
2
+ require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
3
3
 
4
4
  class TestThread < Test::Unit::TestCase
5
5
  def test_stack_size_with_prev
6
- tf = RubyVM::ThreadFrame.new(Thread::current)
6
+ tf = RubyVM::Frame.new(Thread::current)
7
7
 
8
8
  # valid prev counts are -stack_size .. stack_size-1
9
9
  n = tf.stack_size
@@ -21,26 +21,26 @@ class TestThread < Test::Unit::TestCase
21
21
 
22
22
  def test_prev
23
23
 
24
- assert RubyVM::ThreadFrame::prev(Thread::current, 1),
24
+ assert RubyVM::Frame::prev(Thread::current, 1),
25
25
  'should allow 2-arg prev'
26
- assert RubyVM::ThreadFrame::prev(Thread::current),
26
+ assert RubyVM::Frame::prev(Thread::current),
27
27
  'should allow 1-arg thread prev'
28
- assert(RubyVM::ThreadFrame::prev(2),
28
+ assert(RubyVM::Frame::prev(2),
29
29
  'There should be at least two prior frames in single Fixnum prev')
30
30
 
31
- top_frame = RubyVM::ThreadFrame::prev(Thread::current, -1)
31
+ top_frame = RubyVM::Frame::prev(Thread::current, -1)
32
32
  assert(top_frame, 'Should give back the top frame for two arg and -1')
33
33
  assert_equal('TOP', top_frame.type,
34
34
  'The type of the top frame should be "TOP"')
35
35
 
36
- top_frame = RubyVM::ThreadFrame::prev(-1)
36
+ top_frame = RubyVM::Frame::prev(-1)
37
37
  assert(top_frame, 'Should give back the top frame for one arg and -1')
38
38
  assert_equal('TOP', top_frame.type,
39
39
  'The type of the top frame should be "TOP"')
40
40
 
41
- assert_equal(nil, RubyVM::ThreadFrame::prev(Thread::current, 1000))
41
+ assert_equal(nil, RubyVM::Frame::prev(Thread::current, 1000))
42
42
 
43
- tf = RubyVM::ThreadFrame.prev
43
+ tf = RubyVM::Frame.prev
44
44
 
45
45
  assert tf.prev(2)
46
46
  assert_equal(tf, tf.prev(0),
@@ -52,13 +52,13 @@ class TestThread < Test::Unit::TestCase
52
52
  tf.prev('a')
53
53
  end
54
54
  assert_raises ArgumentError do
55
- tf.prev(RubyVM::ThreadFrame::current, 1, 'bad_arg')
55
+ tf.prev(RubyVM::Frame::current, 1, 'bad_arg')
56
56
  end
57
57
  assert_raises TypeError do
58
- RubyVM::ThreadFrame::prev([1])
58
+ RubyVM::Frame::prev([1])
59
59
  end
60
60
  assert_raises TypeError do
61
- RubyVM::ThreadFrame::prev(RubyVM::ThreadFrame::current, [1])
61
+ RubyVM::Frame::prev(RubyVM::Frame::current, [1])
62
62
  end
63
63
 
64
64
  end
@@ -1,6 +1,7 @@
1
1
  # Test of additional proc and method
2
2
  require 'test/unit'
3
- require_relative '../../ext/thread_frame'
3
+
4
+ require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
4
5
 
5
6
  class TestProcAndMethod < Test::Unit::TestCase
6
7
  def test_proc_iseq
@@ -8,6 +9,8 @@ class TestProcAndMethod < Test::Unit::TestCase
8
9
  Proc.new{|x,y| x+y}.iseq.is_a?(RubyVM::InstructionSequence))
9
10
  end
10
11
  def test_method_extra
12
+ # skip "Figure out what's up with on 1.9.3" if
13
+ # '1.9.3' == RUBY_VERSION
11
14
  m = self.method :test_method_extra
12
15
  assert_equal(1, m.alias_count)
13
16
  assert_equal(:test_method_extra, m.original_id)
@@ -1,7 +1,6 @@
1
1
  require 'test/unit'
2
2
 
3
- # require 'thread_frame' # To compare with previous version
4
- require_relative '../../ext/thread_frame'
3
+ require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
5
4
 
6
5
  # Test source_location and source_container.
7
6
  class TestReturnStop < Test::Unit::TestCase
@@ -9,7 +8,7 @@ class TestReturnStop < Test::Unit::TestCase
9
8
  def setup
10
9
  @tuples = []
11
10
  @p = Proc.new { |event, file, lineno, mid, binding, klass|
12
- # RubyVM::ThreadFrame.current.trace_off = true
11
+ # RubyVM::Frame.current.trace_off = true
13
12
  @tuples << [event, lineno, mid, klass]
14
13
  # p [event, lineno, mid, klass]
15
14
  }
@@ -20,7 +19,7 @@ class TestReturnStop < Test::Unit::TestCase
20
19
  def five; 5 end
21
20
 
22
21
  def recurse(a, trace_off)
23
- tf = RubyVM::ThreadFrame::current
22
+ tf = RubyVM::Frame::current
24
23
  if a==1
25
24
  assert_equal false, tf.return_stop?
26
25
  tf.return_stop=trace_off
@@ -45,14 +45,18 @@ class TestSetTraceFunc < Test::Unit::TestCase
45
45
  5: set_trace_func(nil)
46
46
  EOF
47
47
 
48
- expected = [
49
- [4, 'line', __method__, self.class],
50
- [4, 'send', __method__, self.class],
51
- [4, "c-call", :+, Fixnum],
52
- [4, "c-return", :+, Fixnum],
53
- [5, "line", __method__, self.class],
54
- [5, "send", __method__, self.class],
55
- [5, "c-call", :set_trace_func, Kernel]]
48
+ expected =
49
+ [
50
+ [4, 'line', __method__, self.class],
51
+ [4, 'send', __method__, self.class],
52
+ [4, "c-call", :+, Fixnum],
53
+ [4, "c-return", :+, Fixnum],
54
+ [5, "line", __method__, self.class],
55
+ [5, "send", __method__, self.class],
56
+ [5, "c-call", :set_trace_func, Kernel]
57
+ ]
58
+ expected.unshift [5, 'c-return', :set_trace_func, Kernel] if
59
+ '1.9.3' == RUBY_VERSION
56
60
  checkit(@events, expected)
57
61
  end
58
62
 
@@ -87,6 +91,9 @@ class TestSetTraceFunc < Test::Unit::TestCase
87
91
  [8, 'send', __method__, self.class],
88
92
  [8, 'c-call', :set_trace_func, Kernel]
89
93
  ]
94
+ expected.unshift [3, 'c-return', :set_trace_func, Kernel] if
95
+ '1.9.3' == RUBY_VERSION
96
+
90
97
  checkit(@events, expected)
91
98
  end
92
99
 
@@ -102,29 +109,34 @@ class TestSetTraceFunc < Test::Unit::TestCase
102
109
  8: x = Foo.new.bar
103
110
  9: clear_trace_func()
104
111
  EOF
105
- expected = [[4, 'line', __method__, self.class],
106
- [4, 'c-call', :inherited, Class],
107
- [4, 'c-return', :inherited, Class],
108
- [4, 'class', nil, nil],
109
- [5, 'line', nil, nil],
110
- [5, 'send', nil, nil],
111
- [5, 'c-call', :method_added, Module],
112
- [5, 'c-return', :method_added, Module],
113
- [7, 'end', nil, nil],
114
- [7, 'leave', nil, nil],
115
- [8, 'line', __method__, self.class],
116
- [8, 'send', __method__, self.class],
117
- [8, 'c-call', :new, Class],
118
- [8, 'c-call', :initialize, BasicObject],
119
- [8, 'c-return', :initialize, BasicObject],
120
- [8, 'c-return', :new, Class],
121
- [8, 'send', __method__, Class],
122
- [5, 'call', :bar, Foo],
123
- [6, 'return', :bar, Foo],
124
- [6, 'leave', :bar, Foo],
125
- [9, 'line', __method__, self.class],
126
- [9, 'send', __method__, self.class],
127
- [9, 'c-call', :clear_trace_func, Kernel]]
112
+ expected =
113
+ [
114
+ [4, 'line', __method__, self.class],
115
+ [4, 'c-call', :inherited, Class],
116
+ [4, 'c-return', :inherited, Class],
117
+ [4, 'class', nil, nil],
118
+ [5, 'line', nil, nil],
119
+ [5, 'send', nil, nil],
120
+ [5, 'c-call', :method_added, Module],
121
+ [5, 'c-return', :method_added, Module],
122
+ [7, 'end', nil, nil],
123
+ [7, 'leave', nil, nil],
124
+ [8, 'line', __method__, self.class],
125
+ [8, 'send', __method__, self.class],
126
+ [8, 'c-call', :new, Class],
127
+ [8, 'c-call', :initialize, BasicObject],
128
+ [8, 'c-return', :initialize, BasicObject],
129
+ [8, 'c-return', :new, Class],
130
+ [8, 'send', __method__, Class],
131
+ [5, 'call', :bar, Foo],
132
+ [6, 'return', :bar, Foo],
133
+ [6, 'leave', :bar, Foo],
134
+ [9, 'line', __method__, self.class],
135
+ [9, 'send', __method__, self.class],
136
+ [9, 'c-call', :clear_trace_func, Kernel]
137
+ ]
138
+ expected.unshift [3, 'c-return', :set_trace_func, Kernel] if
139
+ '1.9.3' == RUBY_VERSION
128
140
  checkit(@events, expected)
129
141
  end
130
142
 
@@ -194,6 +206,9 @@ class TestSetTraceFunc < Test::Unit::TestCase
194
206
  [9, 'line', :test_return2, self.class],
195
207
  [9, 'send', :test_return2, self.class],
196
208
  [9, 'c-call', :set_trace_func, Kernel]]
209
+ expected.unshift [3, 'c-return', :set_trace_func, Kernel] if
210
+ '1.9.3' == RUBY_VERSION
211
+
197
212
  @events.each_with_index{|e, i|
198
213
  assert_equal(e, @events[i], showit(@events, expected))}
199
214
  assert_equal(expected.size, @events.size, showit(@events, expected))
@@ -236,6 +251,9 @@ class TestSetTraceFunc < Test::Unit::TestCase
236
251
  [8, 'send', __method__, self.class],
237
252
  [8, 'c-call', :set_trace_func, Kernel]
238
253
  ]
254
+ expected.unshift [3, 'c-return', :set_trace_func, Kernel] if
255
+ '1.9.3' == RUBY_VERSION
256
+
239
257
  checkit(events, expected)
240
258
  end
241
259
 
@@ -249,18 +267,24 @@ class TestSetTraceFunc < Test::Unit::TestCase
249
267
  8: set_trace_func(nil)
250
268
  EOF
251
269
 
252
- expected = [
253
- [4, 'line', __method__, self.class],
254
- [4, 'send', __method__, self.class],
255
- [4, 'c-call', :any?, Enumerable],
256
- [4, 'c-call', :each, Array],
257
- [4, 'line', __method__, self.class],
258
- [4, 'leave', __method__, self.class],
259
- [4, 'c-return', :each, Array],
260
- [4, 'c-return', :any?, Enumerable],
261
- [5, 'line', __method__, self.class],
262
- [5, 'send', __method__, self.class],
263
- [5, 'c-call', :set_trace_func, Kernel]]
270
+ expected =
271
+ [
272
+ [4, 'line', __method__, self.class],
273
+ [4, 'send', __method__, self.class],
274
+ [4, 'c-call', :any?, Enumerable],
275
+ [4, 'c-call', :each, Array],
276
+ [4, 'line', __method__, self.class],
277
+ [4, 'leave', __method__, self.class],
278
+ [4, 'c-return', :each, Array],
279
+ [4, 'c-return', :any?, Enumerable],
280
+ [5, 'line', __method__, self.class],
281
+ [5, 'send', __method__, self.class],
282
+ [5, 'c-call', :set_trace_func, Kernel]
283
+ ]
284
+ expected.unshift [3, 'c-return', :set_trace_func, Kernel] if
285
+ '1.9.3' == RUBY_VERSION
286
+
287
+
264
288
  checkit(events, expected)
265
289
  end
266
290
 
@@ -1,7 +1,6 @@
1
1
  require 'test/unit'
2
2
 
3
- # require 'thread_frame' # To compare with previous version
4
- require_relative '../../ext/thread_frame'
3
+ require_relative '../../ext/thread_frame' if '1.9.2' == RUBY_VERSION
5
4
 
6
5
  # Test source_location and source_container.
7
6
  class TestSource < Test::Unit::TestCase
@@ -21,7 +20,7 @@ class TestSource < Test::Unit::TestCase
21
20
  assert_equal('string', iseq.source_container[0])
22
21
  # puts iseq.source_container[1]
23
22
 
24
- eval_str = ' RubyVM::ThreadFrame.current.source_container # test'
23
+ eval_str = ' RubyVM::Frame.current.source_container # test'
25
24
  tuple = eval(eval_str)
26
25
  assert_equal('string', tuple[0])
27
26
  assert_equal(eval_str, tuple[1])
@@ -29,7 +28,7 @@ class TestSource < Test::Unit::TestCase
29
28
  end
30
29
 
31
30
  def test_basic
32
- tf = RubyVM::ThreadFrame::current
31
+ tf = RubyVM::Frame::current
33
32
  # Is this too specific to test/unit.rb implementation details?
34
33
  tup = tf.source_container
35
34
  tup[1] = File.basename(tup[1])
@@ -39,7 +38,7 @@ class TestSource < Test::Unit::TestCase
39
38
  # 1.times creates a C frame.
40
39
  1.times do
41
40
  expect_line = __LINE__ - 1
42
- tf = RubyVM::ThreadFrame::current
41
+ tf = RubyVM::Frame::current
43
42
  tup = tf.source_container
44
43
  tup[1] = File.basename(tup[1])
45
44
  assert_equal(['file', File.basename(__FILE__)], tup)
@@ -54,7 +53,7 @@ class TestSource < Test::Unit::TestCase
54
53
  # 1.upto also creates a C frame.
55
54
  1.upto(1) do
56
55
  expect_line = __LINE__ - 1
57
- tf = RubyVM::ThreadFrame::current
56
+ tf = RubyVM::Frame::current
58
57
  assert_equal('BLOCK', tf.type)
59
58
  tup = tf.source_container
60
59
  tup[1] = File.basename(tup[1])
@@ -68,7 +67,7 @@ class TestSource < Test::Unit::TestCase
68
67
  end
69
68
 
70
69
  x = lambda do |expect_line|
71
- tf = RubyVM::ThreadFrame::current
70
+ tf = RubyVM::Frame::current
72
71
  assert_equal('LAMBDA', tf.type)
73
72
  tup = tf.source_container
74
73
  tup[1] = File.basename(tup[1])
@@ -83,7 +82,7 @@ class TestSource < Test::Unit::TestCase
83
82
  x.call(__LINE__)
84
83
 
85
84
  x = Proc.new do |expect_line|
86
- tf = RubyVM::ThreadFrame::current
85
+ tf = RubyVM::Frame::current
87
86
  tup = tf.source_container
88
87
  tup[1] = File.basename(tup[1])
89
88
  assert_equal(['file', File.basename(__FILE__)], tup)