-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathdebug_spec.cr
279 lines (220 loc) · 4.59 KB
/
debug_spec.cr
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
require "../../spec_helper"
describe "Code gen: debug" do
it "codegens abstract struct (#3578)" do
codegen(%(
abstract struct Base
end
struct Foo < Base
end
struct Bar < Base
end
x = Foo.new || Bar.new
), debug: Crystal::Debug::All)
end
it "inlines instance var access through getter in debug mode" do
run(%(
struct Bar
@x = 1
def set
@x = 2
end
def x
@x
end
end
class Foo
@bar = Bar.new
def set
bar.set
end
def bar
@bar
end
end
foo = Foo.new
foo.set
foo.bar.x
), debug: Crystal::Debug::All, filename: "foo.cr").to_i.should eq(2)
end
it "codegens correct debug info for untyped expression (#4007 and #4008)" do
codegen(%(
require "prelude"
int = 3
case int
when 0
puts 0
when 1, 2, Int32
puts "1 | 2 | Int32"
else
puts int
end
), debug: Crystal::Debug::All)
end
it "codegens correct debug info for new with custom allocate (#3945)" do
codegen(%(
class Foo
def initialize
end
def self.allocate
Pointer(UInt8).malloc(1_u64).as(self)
end
end
Foo.new
), debug: Crystal::Debug::All)
end
it "correctly restores debug location after fun change (#4254)" do
codegen(%(
require "prelude"
class Foo
def self.one
TWO.two { three }
self
end
def self.three
1 + 2
end
def two(&block)
block
end
end
ONE = Foo.one
TWO = Foo.new
ONE.three
), debug: Crystal::Debug::All)
end
it "has correct debug location after constant initialization in call with block (#4719)" do
codegen(%(
require "prelude"
fun __crystal_malloc_atomic(size : UInt32) : Void*
x = uninitialized Void*
x
end
class Foo
end
class Bar
def initialize
yield
end
end
A = Foo.new
Bar.new { }
A
), debug: Crystal::Debug::All)
end
it "has debug info in closure inside if (#5593)" do
codegen(%(
require "prelude"
def foo
if true && true
yield 1
end
end
def bar(&block)
block
end
foo do |i|
bar do
i
end
end
), debug: Crystal::Debug::All)
end
it "doesn't emit incorrect debug info for closured self" do
codegen(%(
def foo(&block : Int32 ->)
block.call(1)
end
class Foo
def bar
foo do
self
end
end
end
Foo.new.bar
), debug: Crystal::Debug::All)
end
it "doesn't emit debug info for unused variable declarations (#9882)" do
codegen(%(
x : Int32
), debug: Crystal::Debug::All)
end
it "stores and restores debug location after jumping to main (#6920)" do
codegen(%(
require "prelude"
Module.method
module Module
def self.value
1 &+ 2
end
@@x : Int32 = value
def self.method
@@x
end
end
), debug: Crystal::Debug::All)
end
it "stores and restores debug location after jumping to main (2)" do
codegen(%(
module Foo
@@x : Int32 = begin
y = 1
end
def self.x
@@x
end
end
Foo.x
), debug: Crystal::Debug::All)
end
it "stores and restores debug location after jumping to main (3)" do
codegen(%(
def raise(exception)
x = uninitialized NoReturn
x
end
lib LibFoo
$foo : ->
end
LibFoo.foo = ->{ }
), debug: Crystal::Debug::All)
end
it "doesn't fail on constant read calls (#11416)" do
codegen(%(
require "prelude"
class Foo
def foo
end
end
def a_foo
Foo.new
end
THE_FOO.foo
THE_FOO = a_foo
), debug: Crystal::Debug::All)
end
it "doesn't fail on splat expansions inside array-like literals" do
run(%(
require "prelude"
class Foo
def each
yield 1
yield 2
yield 3
end
end
class Bar
@bar = 0
def <<(value)
@bar = @bar &* 10 &+ value
end
def bar
@bar
end
end
x = Foo.new
y = Bar{*x}
y.bar
), debug: Crystal::Debug::All).to_i.should eq(123)
end
end