xref: /openbsd-src/gnu/usr.bin/perl/ext/XS-APItest/t/exception.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1BEGIN {
2    push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
3    require Config; import Config;
4    if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
5        print "1..0 # Skip: XS::APItest was not built\n";
6        exit 0;
7    }
8}
9
10use Test::More tests => 12;
11
12BEGIN { use_ok('XS::APItest') };
13
14#########################
15
16my $rv;
17
18$XS::APItest::exception_caught = undef;
19
20$rv = eval { apitest_exception(0) };
21is($@, '');
22ok(defined $rv);
23is($rv, 42);
24is($XS::APItest::exception_caught, 0);
25
26$XS::APItest::exception_caught = undef;
27
28$rv = eval { apitest_exception(1) };
29is($@, "boo\n");
30ok(not defined $rv);
31is($XS::APItest::exception_caught, 1);
32
33$rv = eval { mycroak("foobar\n"); 1 };
34is($@, "foobar\n", 'croak');
35ok(not defined $rv);
36
37$rv = eval { $@ = bless{}, "foo"; mycroak(undef); 1 };
38is(ref($@), "foo", 'croak(NULL)');
39ok(not defined $rv);
40