Make extensions in ext run their tests from the extension's own directory.
[p5sagit/p5-mst-13.2.git] / ext / XS-APItest / t / exception.t
1 BEGIN {
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
10 use Test::More tests => 12;
11
12 BEGIN { use_ok('XS::APItest') };
13
14 #########################
15
16 my $rv;
17
18 $XS::APItest::exception_caught = undef;
19
20 $rv = eval { apitest_exception(0) };
21 is($@, '');
22 ok(defined $rv);
23 is($rv, 42);
24 is($XS::APItest::exception_caught, 0);
25
26 $XS::APItest::exception_caught = undef;
27
28 $rv = eval { apitest_exception(1) };
29 is($@, "boo\n");
30 ok(not defined $rv);
31 is($XS::APItest::exception_caught, 1);
32
33 $rv = eval { mycroak("foobar\n"); 1 };
34 is($@, "foobar\n", 'croak');
35 ok(not defined $rv);
36
37 $rv = eval { $@ = bless{}, "foo"; mycroak(undef); 1 };
38 is(ref($@), "foo", 'croak(NULL)');
39 ok(not defined $rv);