forked from oracle/truffleruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_trace_func.rb
255 lines (204 loc) · 8.15 KB
/
test_trace_func.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
require 'test/unit'
class TestTraceFunc < Test::Unit::TestCase
def setup
super
@test_dir = File.dirname(__FILE__)
end
# FIXME: https://github.com/jruby/jruby/issues/1767
# def test_class
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# output << sprintf("%s %s:%d %s %s", event, file, line, id ? id : 'nil', classname)
# }
# class << self
# end
# set_trace_func nil
# line = __LINE__ - 5
# expected = ["line #{__FILE__}:#{line} test_class TestTraceFunc",
# "class #{__FILE__}:#{line} nil TestTraceFunc",
# "end #{__FILE__}:#{line} nil TestTraceFunc",
# "line #{__FILE__}:#{line + 3} test_class TestTraceFunc",
# "c-call #{__FILE__}:#{line + 3} set_trace_func Kernel"]
# assert_equal(expected, output);
# end
# def test_block_and_vars
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# output << sprintf("%s %s:%d %s %s", event, file, line, id, classname)
# }
# 1.times {
# a = 1
# b = 2
# }
# set_trace_func nil
# line = __LINE__ - 7
# expected = ["line #{__FILE__}:#{line} test_block_and_vars TestTraceFunc",
# "c-call #{__FILE__}:#{line} times Fixnum",
# "b-call #{__FILE__}:#{line} test_block_and_vars TestTraceFunc",
# "line #{__FILE__}:#{line + 1} test_block_and_vars TestTraceFunc",
# "line #{__FILE__}:#{line + 2} test_block_and_vars TestTraceFunc",
# "b-return #{__FILE__}:#{line + 2} test_block_and_vars TestTraceFunc",
# "c-return #{__FILE__}:#{line} times Fixnum",
# "line #{__FILE__}:#{line + 5} test_block_and_vars TestTraceFunc",
# "c-call #{__FILE__}:#{line + 5} set_trace_func Kernel"]
# assert_equal(expected, output)
# end
# def sample_method(a, b)
# a + b
# end
# def test_method_trace
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# output << sprintf("%10s %s:%-2d %18s %14s", event, file, line, id, classname)
# }
# sample_method(1, 1)
# set_trace_func nil
# line = __LINE__ - 4
# expected = [" line #{__FILE__}:#{line} test_method_trace TestTraceFunc",
# " call #{__FILE__}:#{line - 11} sample_method TestTraceFunc",
# " line #{__FILE__}:#{line - 10} sample_method TestTraceFunc",
# " c-call #{__FILE__}:#{line - 10} + Fixnum",
# " c-return #{__FILE__}:#{line - 10} + Fixnum",
# " return #{__FILE__}:#{line - 10} sample_method TestTraceFunc",
# " line #{__FILE__}:#{line + 2} test_method_trace TestTraceFunc",
# " c-call #{__FILE__}:#{line + 2} set_trace_func Kernel"];
# assert_equal(expected, output)
# end
# def bogus_method
# end
# def test_trace_binding
# a = true
# expected = [[:a, :expected, :results],
# [:a, :expected, :results],
# [:a, :expected, :results],
# [:a, :expected, :results],
# [],
# [],
# [:a, :expected, :results],
# [:a, :expected, :results]]
# results = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# results << eval('local_variables', binding)
# }
# 1.to_i # c-call, two traces
# # newline, one trace
# bogus_method # call, two traces
# # newline, one trace
# set_trace_func nil # c-call, two traces
# assert_equal(expected, results)
# end
# def test_load_trace
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# output << sprintf("%s %d %s %s", event, line, id ? id : 'nil', classname)
# }
# require("#@test_dir/dummy.rb")
# set_trace_func nil
# line = __LINE__ - 4
# expected = ["line #{line} test_load_trace TestTraceFunc",
# "c-call #{line} require Kernel",
# "line 1 nil false",
# "c-call 1 inherited Class",
# "c-return 1 inherited Class",
# "class 1 nil false",
# "end 1 nil false",
# "c-return #{line} require Kernel",
# "line #{line + 2} test_load_trace TestTraceFunc",
# "c-call #{line + 2} set_trace_func Kernel"]
# assert_equal(expected, output);
# end
# def test_require_trace_full_paths # JRUBY-2722
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# unless event =~ /c-.*/
# output << sprintf("%s %s %d %s %s", file, event, line, id ? id : 'nil', classname)
# end
# }
# require("./test/tracing/dummy1.rb")
# set_trace_func nil
# line = __LINE__ - 4
# expected = ["#{__FILE__} line #{line} test_require_trace_full_paths TestTraceFunc",
# "#{File.join(@test_dir, 'dummy1.rb')} line 1 nil false",
# "#{File.join(@test_dir, 'dummy1.rb')} class 1 nil false",
# "#{File.join(@test_dir, 'dummy1.rb')} end 1 nil false",
# "#{__FILE__} line #{line + 2} test_require_trace_full_paths TestTraceFunc"]
# assert_equal(expected, output);
# end
# def test_require_trace # JRUBY-2722
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# unless event =~ /c-.*/
# output << sprintf("%s %s %d %s %s", File.basename(file), event, line, id ? id : 'nil', classname)
# end
# }
# require("#@test_dir/dummy2.rb")
# set_trace_func nil
# line = __LINE__ - 4
# expected = ["test_trace_func.rb line #{line} test_require_trace TestTraceFunc",
# "dummy2.rb line 1 nil false",
# "dummy2.rb class 1 nil false",
# "dummy2.rb end 1 nil false",
# "test_trace_func.rb line #{line + 2} test_require_trace TestTraceFunc"]
# assert_equal(expected, output);
# end
# def test_return # JRUBY-2723
# output = []
# set_trace_func proc { |event, file, line, id, binding, classname|
# output << sprintf("%s %s %d %s %s", File.basename(file), event, line, id ? id : 'nil', classname)
# }
# require "#@test_dir/other.rb"
# in_other
# set_trace_func nil
# line = __LINE__ - 5
# expected = ["test_trace_func.rb line #{line} test_return TestTraceFunc",
# "test_trace_func.rb c-call #{line} require Kernel",
# "other.rb line 1 nil false",
# "other.rb c-call 1 method_added Module",
# "other.rb c-return 1 method_added Module",
# "test_trace_func.rb c-return #{line} require Kernel",
# "test_trace_func.rb line #{line + 1} test_return TestTraceFunc",
# "other.rb call 1 in_other Object",
# "other.rb line 2 in_other Object",
# "other.rb c-call 2 sleep Kernel",
# "other.rb c-return 2 sleep Kernel",
# "other.rb return 2 in_other Object",
# "test_trace_func.rb line #{line + 3} test_return TestTraceFunc",
# "test_trace_func.rb c-call #{line + 3} set_trace_func Kernel"]
# assert_equal(expected, output);
# end
# # JRUBY-2815
# def test_trace_over_system_call
# output = []
# set_trace_func(proc do |event, file, line, id, binding, classname|
# unless file =~ /path_helper\.rb/
# output << sprintf("%s %s %d %s %s", File.basename(file), event, line, id ? id : 'nil', classname)
# end
# end)
# system('echo .')
# set_trace_func nil
# line = __LINE__ - 3
# expected = ["test_trace_func.rb line #{line} test_trace_over_system_call TestTraceFunc",
# "test_trace_func.rb c-call #{line} system Kernel",
# "test_trace_func.rb c-return #{line} system Kernel",
# "test_trace_func.rb line #{line + 1} test_trace_over_system_call TestTraceFunc",
# "test_trace_func.rb c-call #{line + 1} set_trace_func Kernel"]
# assert_equal expected, output
# end
# # JRUBY-6832
# def test_trace_over_nameerror
# output = nil
# set_trace_func(proc{ |event, file, line, method, binding, klass|
# output = binding.eval("[self, s]") if event == "raise"
# })
# def hello
# s = "snorkle"
# s.desnrok
# end
# begin
# hello
# rescue NameError
# end
# set_trace_func nil
# assert_equal output, [self, "snorkle"]
# end
end