Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test nqp::newexception, nqp::throw, nqp::setpayload, nqp::getpayload,…
… nqp::setmessage, nqp::getmessage.
  • Loading branch information
pmurias committed Mar 8, 2016
1 parent 431361b commit d8953b6
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion t/nqp/44-try-catch.t
Expand Up @@ -2,7 +2,7 @@

# Tests for try and catch

plan(11);
plan(18);

sub oops($msg = "oops!") { # throw an exception
nqp::die($msg);
Expand Down Expand Up @@ -100,3 +100,33 @@ ok($ok eq "oops!", "combination of both try and CATCH");
oops_s();
}
ok($ok eq "oops_s!", "nqp::die_s");


{
my $exception := nqp::newexception();
nqp::setmessage($exception, "a cute exception");
nqp::setpayload($exception, "cute payload");
nqp::throw($exception);
CATCH {
ok(nqp::getmessage($_) eq "a cute exception", "nqp::setmessage/nqp::getmessage");
ok(nqp::getpayload($_) eq "cute payload", "nqp::setpayload/nqp::getpayload");
}
}

{
class Foo is repr('VMException') {
method custom_stuff() {"cool stuff"}
}

my $exception := Foo.new(custom_attr=>'custom');
my $msg := "a custom exception";
ok(nqp::setmessage($exception, $msg) eq $msg, "correct return value for nqp::setmessage");
my $payload := "custom payload";
ok(nqp::setpayload($exception, $payload) eq $payload, "correct return value for nqp::setpayload");
nqp::throw($exception);
CATCH {
ok($_.custom_stuff eq "cool stuff", "calling method on custom exception");
ok(nqp::getmessage($_) eq "a custom exception", "nqp::setmessage/nqp::getmessage on custom exception");
ok(nqp::getpayload($_) eq "custom payload", "nqp::setpayload/nqp::getpayload on custom exception");
}
}

0 comments on commit d8953b6

Please sign in to comment.