Revision | 1a458faeb6265b283f347072fba9b8e39e4898e8 (tree) |
---|---|
Time | 2023-03-17 22:26:59 |
Author | miyakawataku |
Commiter | miyakawataku |
replace CONTROL.try in tests of CORE mod
@@ -61,11 +61,11 @@ | ||
61 | 61 | |
62 | 62 | TEST.group('CORE.reraise'){ # {{{1 |
63 | 63 | TEST.test('alternative message for non-str argument'){ |
64 | - CONTROL.try( | |
64 | + CONTROL.xtry( | |
65 | 65 | { reraise(42 []) } |
66 | 66 | {(:Result) raise('expected an exception, but got {}'.format(Result.repr)) } |
67 | - {(:Msg :Traces) | |
68 | - Msg == 'exception message is not str' || raise('got Msg {}'.format(Msg.repr)) | |
67 | + {(:Exc) | |
68 | + Exc.message == 'exception message is not str' || Exc.raise | |
69 | 69 | } |
70 | 70 | ) |
71 | 71 | } |
@@ -145,11 +145,12 @@ | ||
145 | 145 | TEST.test('raises an exception if not found'){ |
146 | 146 | save_mod_paths{ |
147 | 147 | MOD.append_path('src/test/kink/mod_base/path_y') |
148 | - CONTROL.try( | |
148 | + CONTROL.xtry( | |
149 | 149 | { require('dir/NO_SUCH_MOD') } |
150 | 150 | {(:R) raise('got {}'.format(R.repr)) } |
151 | - {(:Msg :Traces) | |
152 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('NO_SUCH_MOD') || reraise(Msg Traces) | |
151 | + {(:Exc) | |
152 | + :Msg = Exc.message | |
153 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('NO_SUCH_MOD') || Exc.raise | |
153 | 154 | } |
154 | 155 | ) |
155 | 156 | } |
@@ -158,11 +159,12 @@ | ||
158 | 159 | TEST.test('raises an exception if not found, with empty config'){ |
159 | 160 | save_mod_paths{ |
160 | 161 | MOD.append_path('src/test/kink/mod_base/path_y') |
161 | - CONTROL.try( | |
162 | + CONTROL.xtry( | |
162 | 163 | { require('dir/NO_SUCH_MOD'){} } |
163 | 164 | {(:R) raise('got {}'.format(R.repr)) } |
164 | - {(:Msg :Traces) | |
165 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('NO_SUCH_MOD') || reraise(Msg Traces) | |
165 | + {(:Exc) | |
166 | + :Msg = Exc.message | |
167 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('NO_SUCH_MOD') || Exc.raise | |
166 | 168 | } |
167 | 169 | ) |
168 | 170 | } |
@@ -182,11 +184,12 @@ | ||
182 | 184 | TEST.test('raises an exception on a compile error'){ |
183 | 185 | save_mod_paths{ |
184 | 186 | MOD.append_path('src/test/kink/mod_base/path_x') |
185 | - CONTROL.try( | |
187 | + CONTROL.xtry( | |
186 | 188 | { require('dir/COMPILE_ERROR') } |
187 | 189 | {(:R) raise('got {}'.format(R.repr)) } |
188 | - {(:Msg :Traces) | |
189 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('COMPILE_ERROR') || reraise(Msg Traces) | |
190 | + {(:Exc) | |
191 | + :Msg = Exc.message | |
192 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('COMPILE_ERROR') || Exc.raise | |
190 | 193 | } |
191 | 194 | ) |
192 | 195 | } |
@@ -195,11 +198,12 @@ | ||
195 | 198 | TEST.test('raises an exception on a compile error, with empty config'){ |
196 | 199 | save_mod_paths{ |
197 | 200 | MOD.append_path('src/test/kink/mod_base/path_x') |
198 | - CONTROL.try( | |
201 | + CONTROL.xtry( | |
199 | 202 | { require('dir/COMPILE_ERROR'){} } |
200 | 203 | {(:R) raise('got {}'.format(R.repr)) } |
201 | - {(:Msg :Traces) | |
202 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('COMPILE_ERROR') || reraise(Msg Traces) | |
204 | + {(:Exc) | |
205 | + :Msg = Exc.message | |
206 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('COMPILE_ERROR') || Exc.raise | |
203 | 207 | } |
204 | 208 | ) |
205 | 209 | } |
@@ -219,11 +223,12 @@ | ||
219 | 223 | } |
220 | 224 | |
221 | 225 | TEST.test('raises an exception on a bad name'){ |
222 | - CONTROL.try( | |
226 | + CONTROL.xtry( | |
223 | 227 | { require('bad Name') } |
224 | 228 | {(:R) raise('got {}'.format(R.repr)) } |
225 | - {(:Msg :Traces) | |
226 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('bad Name') || reraise(Msg Traces) | |
229 | + {(:Exc) | |
230 | + :Msg = Exc.message | |
231 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('bad Name') || Exc.raise | |
227 | 232 | } |
228 | 233 | ) |
229 | 234 | } |
@@ -252,11 +257,12 @@ | ||
252 | 257 | # }}}2 |
253 | 258 | TEST.group('checks the mod name'){ # {{{2 |
254 | 259 | TEST.test('is a str'){ |
255 | - CONTROL.try( | |
260 | + CONTROL.xtry( | |
256 | 261 | { require(nada) } |
257 | 262 | {(:R) raise('got {}'.format(R.repr)) } |
258 | - {(:Msg :Traces) | |
259 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('nada') || reraise(Msg Traces) | |
263 | + {(:Exc) | |
264 | + :Msg = Exc.message | |
265 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('nada') || Exc.raise | |
260 | 266 | } |
261 | 267 | ) |
262 | 268 | } |
@@ -265,11 +271,12 @@ | ||
265 | 271 | # }}}2 |
266 | 272 | TEST.group('checks $config'){ # {{{2 |
267 | 273 | TEST.test('is a fun'){ |
268 | - CONTROL.try( | |
274 | + CONTROL.xtry( | |
269 | 275 | { require('kink/CORE' nada) } |
270 | 276 | {(:R) raise('got {}'.format(R.repr)) } |
271 | - {(:Msg :Traces) | |
272 | - Msg.have_slice?('CORE.require') && Msg.have_slice?('nada') || reraise(Msg Traces) | |
277 | + {(:Exc) | |
278 | + :Msg = Exc.message | |
279 | + Msg.have_slice?('CORE.require') && Msg.have_slice?('nada') || Exc.raise | |
273 | 280 | } |
274 | 281 | ) |
275 | 282 | } |
@@ -293,11 +300,12 @@ | ||
293 | 300 | } |
294 | 301 | |
295 | 302 | TEST.test('op_lognot non-bool result in exception'){ |
296 | - CONTROL.try( | |
303 | + CONTROL.xtry( | |
297 | 304 | { op_lognot(nada) } |
298 | 305 | {(:Result) raise('got {}'.format(Result.repr)) } |
299 | - {(:Msg :Traces) | |
300 | - Msg.have_slice?('nada') && Msg.have_slice?('op_lognot') || reraise(Msg Traces) | |
306 | + {(:Exc) | |
307 | + :Msg = Exc.message | |
308 | + Msg.have_slice?('nada') && Msg.have_slice?('op_lognot') || Exc.raise | |
301 | 309 | } |
302 | 310 | ) |
303 | 311 | } |
@@ -330,21 +338,23 @@ | ||
330 | 338 | } |
331 | 339 | |
332 | 340 | TEST.test('expect bool for the first arg'){ |
333 | - CONTROL.try( | |
341 | + CONTROL.xtry( | |
334 | 342 | { op_logor(nada { true }) } |
335 | 343 | {(:R) raise('got {}'.format(R.repr)) } |
336 | - {(:Msg :Traces) | |
337 | - Msg.have_slice?('nada') && Msg.have_slice?('op_logor') || reraise(Msg Traces) | |
344 | + {(:Exc) | |
345 | + :Msg = Exc.message | |
346 | + Msg.have_slice?('nada') && Msg.have_slice?('op_logor') || Exc.raise | |
338 | 347 | } |
339 | 348 | ) |
340 | 349 | } |
341 | 350 | |
342 | 351 | TEST.test('expect fun for the second arg'){ |
343 | - CONTROL.try( | |
352 | + CONTROL.xtry( | |
344 | 353 | { op_logor(true nada) } |
345 | 354 | {(:R) raise('got {}'.format(R.repr)) } |
346 | - {(:Msg :Traces) | |
347 | - Msg.have_slice?('nada') && Msg.have_slice?('op_logor') || reraise(Msg Traces) | |
355 | + {(:Exc) | |
356 | + :Msg = Exc.message | |
357 | + Msg.have_slice?('nada') && Msg.have_slice?('op_logor') || Exc.raise | |
348 | 358 | } |
349 | 359 | ) |
350 | 360 | } |
@@ -377,21 +387,23 @@ | ||
377 | 387 | } |
378 | 388 | |
379 | 389 | TEST.test('expect bool for the first arg'){ |
380 | - CONTROL.try( | |
390 | + CONTROL.xtry( | |
381 | 391 | { op_logand(nada { true }) } |
382 | 392 | {(:R) raise('got {}'.format(R.repr)) } |
383 | - {(:Msg :Traces) | |
384 | - Msg.have_slice?('nada') && Msg.have_slice?('op_logand') || reraise(Msg Traces) | |
393 | + {(:Exc) | |
394 | + :Msg = Exc.message | |
395 | + Msg.have_slice?('nada') && Msg.have_slice?('op_logand') || Exc.raise | |
385 | 396 | } |
386 | 397 | ) |
387 | 398 | } |
388 | 399 | |
389 | 400 | TEST.test('expect fun for the second arg'){ |
390 | - CONTROL.try( | |
401 | + CONTROL.xtry( | |
391 | 402 | { op_logand(true nada) } |
392 | 403 | {(:R) raise('got {}'.format(R.repr)) } |
393 | - {(:Msg :Traces) | |
394 | - Msg.have_slice?('nada') && Msg.have_slice?('op_logand') || reraise(Msg Traces) | |
404 | + {(:Exc) | |
405 | + :Msg = Exc.message | |
406 | + Msg.have_slice?('nada') && Msg.have_slice?('op_logand') || Exc.raise | |
395 | 407 | } |
396 | 408 | ) |
397 | 409 | } |
@@ -416,21 +428,23 @@ | ||
416 | 428 | } |
417 | 429 | |
418 | 430 | TEST.test('bool must be a bool'){ |
419 | - CONTROL.try( | |
431 | + CONTROL.xtry( | |
420 | 432 | { CORE.if(nada {}) } |
421 | 433 | {(:R) raise('got {}'.format(R.repr)) } |
422 | - {(:Msg :Traces) | |
423 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
434 | + {(:Exc) | |
435 | + :Msg = Exc.message | |
436 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
424 | 437 | } |
425 | 438 | ) |
426 | 439 | } |
427 | 440 | |
428 | 441 | TEST.test('$true_cont must be a fun'){ |
429 | - CONTROL.try( | |
442 | + CONTROL.xtry( | |
430 | 443 | { CORE.if(true nada) } |
431 | 444 | {(:R) raise('got {}'.format(R.repr)) } |
432 | - {(:Msg :Traces) | |
433 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
445 | + {(:Exc) | |
446 | + :Msg = Exc.message | |
447 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
434 | 448 | } |
435 | 449 | ) |
436 | 450 | } |
@@ -450,31 +464,34 @@ | ||
450 | 464 | } |
451 | 465 | |
452 | 466 | TEST.test('bool must be a bool'){ |
453 | - CONTROL.try( | |
467 | + CONTROL.xtry( | |
454 | 468 | { CORE.if(nada {} {}) } |
455 | 469 | {(:R) raise('got {}'.format(R.repr)) } |
456 | - {(:Msg :Traces) | |
457 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
470 | + {(:Exc) | |
471 | + :Msg = Exc.message | |
472 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
458 | 473 | } |
459 | 474 | ) |
460 | 475 | } |
461 | 476 | |
462 | 477 | TEST.test('$true_cont must be a fun'){ |
463 | - CONTROL.try( | |
478 | + CONTROL.xtry( | |
464 | 479 | { CORE.if(true nada {}) } |
465 | 480 | {(:R) raise('got {}'.format(R.repr)) } |
466 | - {(:Msg :Traces) | |
467 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
481 | + {(:Exc) | |
482 | + :Msg = Exc.message | |
483 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
468 | 484 | } |
469 | 485 | ) |
470 | 486 | } |
471 | 487 | |
472 | 488 | TEST.test('$false_cont must be a fun'){ |
473 | - CONTROL.try( | |
489 | + CONTROL.xtry( | |
474 | 490 | { CORE.if(false {} nada) } |
475 | 491 | {(:R) raise('got {}'.format(R.repr)) } |
476 | - {(:Msg :Traces) | |
477 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
492 | + {(:Exc) | |
493 | + :Msg = Exc.message | |
494 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
478 | 495 | } |
479 | 496 | ) |
480 | 497 | } |
@@ -497,11 +514,12 @@ | ||
497 | 514 | |
498 | 515 | TEST.test('bool must be a bool'){ |
499 | 516 | :Nada = nada |
500 | - CONTROL.try( | |
517 | + CONTROL.xtry( | |
501 | 518 | { if(Nada {}) } |
502 | 519 | {(:R) raise('got {}'.format(R.repr)) } |
503 | - {(:Msg :Traces) | |
504 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
520 | + {(:Exc) | |
521 | + :Msg = Exc.message | |
522 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
505 | 523 | } |
506 | 524 | ) |
507 | 525 | } |
@@ -522,11 +540,12 @@ | ||
522 | 540 | |
523 | 541 | TEST.test('bool must be a bool'){ |
524 | 542 | :Nada = nada |
525 | - CONTROL.try( | |
543 | + CONTROL.xtry( | |
526 | 544 | { if(Nada {} {}) } |
527 | 545 | {(:R) raise('got {}'.format(R.repr)) } |
528 | - {(:Msg :Traces) | |
529 | - Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || reraise(Msg Traces) | |
546 | + {(:Exc) | |
547 | + :Msg = Exc.message | |
548 | + Msg.have_slice?('nada') && Msg.have_slice?('CORE.if') || Exc.raise | |
530 | 549 | } |
531 | 550 | ) |
532 | 551 | } |
@@ -542,21 +561,21 @@ | ||
542 | 561 | Result == 'OK' || raise('got {}'.format(Result.repr)) |
543 | 562 | } |
544 | 563 | TEST.test('not matched'){ |
545 | - CONTROL.try( | |
564 | + CONTROL.xtry( | |
546 | 565 | { branch({ false } { raise('not reach here') }) } |
547 | 566 | {(:Result) raise('expected an exception, but got {}'.format(Result.repr)) } |
548 | - {(:Msg :Traces) | |
549 | - Msg.have_slice?('no matching cond') || reraise(Msg Traces) | |
567 | + {(:Exc) | |
568 | + Exc.message.have_slice?('no matching cond') || Exc.raise | |
550 | 569 | } |
551 | 570 | ) |
552 | 571 | } |
553 | 572 | TEST.ignore_test('not bool cond'){ |
554 | - CONTROL.try( | |
573 | + CONTROL.xtry( | |
555 | 574 | { branch({ false } { raise('not reach here') } { 42 } { raise('not reach here') }) } |
556 | 575 | {(:Result) raise('expected an exception, but got {}'.format(Result.repr)) } |
557 | - {(:Msg :Traces) | |
558 | - Msg == 'CORE.branch(...[$cond1 $then1 $cond2 $then2 ,,,]): result of $cond2 must be bool, but got 42' | |
559 | - || reraise(Msg Traces) | |
576 | + {(:Exc) | |
577 | + Exc.message == 'CORE.branch(...[$cond1 $then1 $cond2 $then2 ,,,]): result of $cond2 must be bool, but got 42' | |
578 | + || Exc.raise | |
560 | 579 | } |
561 | 580 | ) |
562 | 581 | } |
@@ -579,12 +598,12 @@ | ||
579 | 598 | Result == 'Else' || raise('got {}'.format(Result.repr)) |
580 | 599 | } |
581 | 600 | TEST.ignore_test('not bool cond'){ |
582 | - CONTROL.try( | |
601 | + CONTROL.xtry( | |
583 | 602 | { branch({ false } { 'F' } { 42 } { 'T' } $true { 'Else' }) } |
584 | 603 | {(:Result) raise('expected an exception, but got {}'.format(Result.repr)) } |
585 | - {(:Msg :Traces) | |
586 | - Msg == 'CORE.branch(...[$cond1 $then1 $cond2 $then2 ,,,]): result of $cond2 must be bool, but got 42' | |
587 | - || reraise(Msg Traces) | |
604 | + {(:Exc) | |
605 | + Exc.message == 'CORE.branch(...[$cond1 $then1 $cond2 $then2 ,,,]): result of $cond2 must be bool, but got 42' | |
606 | + || Exc.raise | |
588 | 607 | } |
589 | 608 | ) |
590 | 609 | } |
@@ -597,11 +616,11 @@ | ||
597 | 616 | } |
598 | 617 | TEST.test('slowpath because $true is modified'){ |
599 | 618 | :true = { false } |
600 | - CONTROL.try( | |
619 | + CONTROL.xtry( | |
601 | 620 | { branch({ false } { 'F' } $true { 'F' }) } |
602 | 621 | {(:Result) raise('expected an exception, but got {}'.format(Result.repr)) } |
603 | - {(:Msg :Traces) | |
604 | - Msg == 'CORE.branch(...[$cond1 $then1 $cond2 $then2 ,,,]): no matching cond' || reraise(Msg Traces) | |
622 | + {(:Exc) | |
623 | + Exc.message == 'CORE.branch(...[$cond1 $then1 $cond2 $then2 ,,,]): no matching cond' || Exc.raise | |
605 | 624 | } |
606 | 625 | ) |
607 | 626 | } |