This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add simple exception handling macros for XS writers.
[perl5.git] / ext / XS / APItest / t / exception.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4     push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
5     require Config; import Config;
6     if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
7         print "1..0 # Skip: XS::APItest was not built\n";
8         exit 0;
9     }
10 }
11
12 use Test::More tests => 8;
13
14 BEGIN { use_ok('XS::APItest') };
15
16 #########################
17
18 my $rv;
19
20 $XS::APItest::exception_caught = undef;
21
22 $rv = eval { exception(0) };
23 is($@, '');
24 ok(defined $rv);
25 is($rv, 42);
26 is($XS::APItest::exception_caught, 0);
27
28 $XS::APItest::exception_caught = undef;
29
30 $rv = eval { exception(1) };
31 is($@, "boo\n");
32 ok(not defined $rv);
33 is($XS::APItest::exception_caught, 1);