The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

use lib "t/testlib";
use strict;
use SPVM 'TestCase::Exception';
use File::Basename 'basename';
my $file = basename $0;
# Exception
{
eval { SPVM::TestCase::Exception->exception_zero_divide_int() }; my $line = __LINE__;
my $error = $@;
my $die_line = SPVM::TestCase::Exception->ZERO_DIVIDE_INT_LINE;
ok($die_line > 0);
like($error, qr|\Qdivided by 0|);
like($error, qr/\Q$file/);
like($error, qr/$line/);
like($error, qr/$die_line/);
like($error, qr|Exception\.spvm|);
}
# Exception
{
{
ok(SPVM::TestCase::Exception->exception_eval_call_method());
}
{
eval { SPVM::TestCase::Exception->exception_call_stack() };
like($@, qr/Error/);
like($@, qr/exception_die_return_int/);
like($@, qr/exception_call_stack/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_byte() };
like($@, qr/Error/);
like($@, qr/exception_die_return_byte/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_short() };
like($@, qr/Error/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_int() };
like($@, qr/Error/);
like($@, qr/exception_die_return_int/);
like($@, qr/Exception\.spvm/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_long() };
like($@, qr/Error/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_float() };
like($@, qr/Error/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_double() };
like($@, qr/Error/);
}
{
eval { SPVM::TestCase::Exception->exception_die_return_void() };
like($@, qr/Error/);
}
{
ok(SPVM::TestCase::Exception->exception_die_return_int_eval_catch());
}
{
eval { SPVM::TestCase::Exception->exception_die_return_object() };
like($@, qr/Error/);
}
}
eval { SPVM::TestCase->eval_block_stack_check() };
ok($@);
# Set field exception
{
ok(SPVM::TestCase::Exception->exception_set_field_object_undef());
}
# Get field exception
{
ok(SPVM::TestCase::Exception->exception_get_field_object_undef());
}
# Exception - callback
{
eval { SPVM::TestCase::Exception->exception_callback() };
my $error = $@;
my $callback_die_line = SPVM::TestCase::Exception->CALLBACK_DIE_LINE;
ok($callback_die_line > 0);
like($error, qr/Comparator Error/);
like($error, qr|TestCase/Exception\.spvm line $callback_die_line|);
}
# die statement
{
ok(SPVM::TestCase::Exception->die);
}
done_testing;