repo.or.cz
/
ruby-svn.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git]
/
yarvtest
/
test_exception.rb
blob
9e69d02909a4f21947991ebb2229acd8b3141976
1
require 'yarvtest/yarvtest'
2
3
class TestException < YarvTestBase
4
5
def test_rescue
6
ae %q{
7
begin
8
1
9
rescue
10
2
11
end
12
}
13
14
ae %q{
15
begin
16
1
17
begin
18
2
19
rescue
20
3
21
end
22
4
23
rescue
24
5
25
end
26
}
27
28
ae %q{
29
begin
30
1
31
rescue
32
2
33
else
34
3
35
end
36
}
37
end
38
39
def test_ensure
40
ae %q{
41
begin
42
1+1
43
ensure
44
2+2
45
end
46
}
47
ae %q{
48
begin
49
1+1
50
begin
51
2+2
52
ensure
53
3+3
54
end
55
ensure
56
4+4
57
end
58
}
59
ae %q{
60
begin
61
1+1
62
begin
63
2+2
64
ensure
65
3+3
66
end
67
ensure
68
4+4
69
begin
70
5+5
71
ensure
72
6+6
73
end
74
end
75
}
76
end
77
78
def test_rescue_ensure
79
ae %q{
80
begin
81
1+1
82
rescue
83
2+2
84
ensure
85
3+3
86
end
87
}
88
ae %q{
89
begin
90
1+1
91
rescue
92
2+2
93
ensure
94
3+3
95
end
96
}
97
ae %q{
98
begin
99
1+1
100
rescue
101
2+2
102
else
103
3+3
104
ensure
105
4+4
106
end
107
}
108
ae %q{
109
begin
110
1+1
111
begin
112
2+2
113
rescue
114
3+3
115
else
116
4+4
117
end
118
rescue
119
5+5
120
else
121
6+6
122
ensure
123
7+7
124
end
125
}
126
127
end
128
129
def test_raise
130
ae %q{
131
begin
132
raise
133
rescue
134
:ok
135
end
136
}
137
ae %q{
138
begin
139
raise
140
rescue
141
:ok
142
ensure
143
:ng
144
end
145
}
146
ae %q{
147
begin
148
raise
149
rescue => e
150
e.class
151
end
152
}
153
ae %q{
154
begin
155
raise
156
rescue StandardError
157
:ng
158
rescue Exception
159
:ok
160
end
161
}
162
ae %q{
163
begin
164
begin
165
raise "a"
166
rescue
167
raise "b"
168
ensure
169
raise "c"
170
end
171
rescue => e
172
e.message
173
end
174
}
175
end
176
177
def test_error_variable
178
ae %q{
179
a = nil
180
1.times{|e|
181
begin
182
rescue => err
183
end
184
a = err.class
185
}
186
}
187
ae %q{
188
a = nil
189
1.times{|e|
190
begin
191
raise
192
rescue => err
193
end
194
a = err.class
195
}
196
a
197
}
198
end
199
200
def test_raise_in_other_scope
201
ae %q{
202
class E1 < Exception
203
end
204
205
def m
206
yield
207
end
208
209
begin
210
begin
211
begin
212
m{
213
raise
214
}
215
rescue E1
216
:ok2
217
ensure
218
end
219
rescue
220
:ok3
221
ensure
222
end
223
rescue E1
224
:ok
225
ensure
226
end
227
} do
228
remove_const :E1
229
end
230
231
ae %q{
232
$i = 0
233
def m
234
iter{
235
begin
236
$i += 1
237
begin
238
$i += 2
239
break
240
ensure
241
242
end
243
ensure
244
$i += 4
245
end
246
$i = 0
247
}
248
end
249
250
def iter
251
yield
252
end
253
m
254
$i
255
}
256
257
ae %q{
258
$i = 0
259
def m
260
begin
261
$i += 1
262
begin
263
$i += 2
264
return
265
ensure
266
$i += 3
267
end
268
ensure
269
$i += 4
270
end
271
p :end
272
end
273
m
274
$i
275
}
276
end
277
278
def test_raise_in_cont_sp
279
ae %q{
280
def m a, b
281
a + b
282
end
283
m(1, begin
284
raise
285
rescue
286
2
287
end) +
288
m(10, begin
289
raise
290
rescue
291
20
292
ensure
293
30
294
end)
295
}
296
ae %q{
297
def m a, b
298
a + b
299
end
300
m(begin
301
raise
302
rescue
303
1
304
end,
305
begin
306
raise
307
rescue
308
2
309
end)
310
}
311
end
312
313
def test_geterror
314
ae %q{
315
$!
316
}
317
ae %q{
318
begin
319
raise "FOO"
320
rescue
321
$!
322
end
323
}
324
ae %q{
325
def m
326
$!
327
end
328
begin
329
raise "FOO"
330
rescue
331
m()
332
end
333
}
334
ae %q{
335
$ans = []
336
def m
337
$!
338
end
339
begin
340
raise "FOO"
341
rescue
342
begin
343
raise "BAR"
344
rescue
345
$ans << m()
346
end
347
$ans << m()
348
end
349
$ans
350
}
351
ae %q{
352
$ans = []
353
def m
354
$!
355
end
356
357
begin
358
begin
359
raise "FOO"
360
ensure
361
$ans << m()
362
end
363
rescue
364
$ans << m()
365
end
366
}
367
ae %q{
368
$ans = []
369
def m
370
$!
371
end
372
def m2
373
1.times{
374
begin
375
return
376
ensure
377
$ans << m
378
end
379
}
380
end
381
m2
382
$ans
383
}
384
end
385
386
def test_stack_consistency
387
ae %q{ #
388
proc{
389
begin
390
raise
391
break
392
rescue
393
:ok
394
end
395
}.call
396
}
397
ae %q{
398
proc do
399
begin
400
raise StandardError
401
redo
402
rescue StandardError
403
end
404
end.call
405
}
406
end
407
end
408