Skip to content

Commit e4e2f81

Browse files
committed
Test that CONTROL catches labeled control exceptions
1 parent 41d6e41 commit e4e2f81

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

t/nqp/044-try-catch.t

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Tests for try and catch
44

5-
plan(55);
5+
plan(57);
66

77
sub oops($msg = "oops!") { # throw an exception
88
nqp::die($msg);
@@ -464,3 +464,52 @@ sub scope2() {
464464
}
465465

466466
scope2();
467+
468+
sub catch_with_control($throws) {
469+
my $caught;
470+
my sub caught($arg) {
471+
$caught := $arg;
472+
}
473+
nqp::handle(
474+
$throws(),
475+
'CONTROL', caught('control')
476+
);
477+
$caught;
478+
};
479+
480+
sub catch_labeled($throws) {
481+
my $caught;
482+
my sub caught($arg) {
483+
$caught := $arg;
484+
}
485+
my $ret := nqp::handle(
486+
$caught := $throws(),
487+
'LABELED', Label2,
488+
'TAKE', caught('labeled')
489+
);
490+
$caught;
491+
};
492+
493+
sub catch_unlabeled($throws) {
494+
my $caught;
495+
my sub caught($arg) {
496+
$caught := $arg;
497+
}
498+
nqp::handle(
499+
$caught := $throws(),
500+
'TAKE', caught('unlabeled')
501+
);
502+
$caught;
503+
};
504+
505+
is(catch_unlabeled({
506+
catch_with_control({
507+
THROW(nqp::const::CONTROL_TAKE, nqp::null())
508+
});
509+
}), 'control', 'an unlabeled exception is caught by CONTROL');
510+
511+
is(catch_labeled({
512+
catch_with_control({
513+
THROW(nqp::add_i(nqp::const::CONTROL_TAKE, nqp::const::CONTROL_LABELED), Label2)
514+
});
515+
}), 'control', 'a labeled exception is caught by CONTROL');

0 commit comments

Comments
 (0)