Make extensions in ext run their tests from the extension's own directory.
[p5sagit/p5-mst-13.2.git] / ext / XS-APItest / t / my_cxt.t
CommitLineData
85ce96a1 1#!perl -w
2
3# test per-interpeter static data API (MY_CXT)
4# DAPM Dec 2005
5
6my $threads;
7BEGIN {
85ce96a1 8 push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
9 require Config; import Config;
10 if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
11 # Look, I'm using this fully-qualified variable more than once!
12 my $arch = $MacPerl::Architecture;
13 print "1..0 # Skip: XS::APItest was not built\n";
14 exit 0;
15 }
16 $threads = $Config{'useithreads'};
17 # must 'use threads' before 'use Test::More'
18 eval 'use threads' if $threads;
19}
20
21use warnings;
22use strict;
23
9568a123 24use Test::More tests => 16;
85ce96a1 25
26BEGIN {
27 use_ok('XS::APItest');
28};
29
30is(my_cxt_getint(), 99, "initial int value");
9568a123 31is(my_cxt_getsv($_), "initial", "initial SV value$_")
32 foreach '', ' (context arg)';
85ce96a1 33
34my_cxt_setint(1234);
35is(my_cxt_getint(), 1234, "new int value");
36
37my_cxt_setsv("abcd");
9568a123 38is(my_cxt_getsv($_), "abcd", "new SV value$_")
39 foreach '', ' (context arg)';
85ce96a1 40
41sub do_thread {
42 is(my_cxt_getint(), 1234, "initial int value (child)");
43 my_cxt_setint(4321);
44 is(my_cxt_getint(), 4321, "new int value (child)");
45
9568a123 46 is(my_cxt_getsv($_), "initial_clone", "initial sv value (child)$_")
47 foreach '', ' (context arg)';
85ce96a1 48 my_cxt_setsv("dcba");
9568a123 49 is(my_cxt_getsv($_), "dcba", "new SV value (child)$_")
50 foreach '', ' (context arg)';
85ce96a1 51}
52
53SKIP: {
9568a123 54 skip "No threads", 6 unless $threads;
878090d5 55 threads->create(\&do_thread)->join;
85ce96a1 56}
57
58is(my_cxt_getint(), 1234, "int value preserved after join");
9568a123 59is(my_cxt_getsv($_), "abcd", "SV value preserved after join$_")
60 foreach '', ' (context arg)';