Make extensions in ext run their tests from the extension's own directory.
[p5sagit/p5-mst-13.2.git] / ext / XS-APItest / t / xs_special_subs.t
1 #!perl -w
2
3 BEGIN {
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     # Hush the used only once warning.
11     $XS::APItest::WARNINGS_ON_BOOTSTRAP = $MacPerl::Architecture;
12     $XS::APItest::WARNINGS_ON_BOOTSTRAP = 1;
13 }
14
15 use strict;
16 use warnings;
17 my $uc;
18 BEGIN {
19     $uc = $] > 5.009;
20 }
21 use Test::More tests => $uc ? 100 : 80;
22
23 # Doing this longhand cut&paste makes it clear
24 # BEGIN and INIT are FIFO, CHECK and END are LIFO
25 BEGIN {
26     print "# First BEGIN\n";
27     is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called");
28     is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called");
29     is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called")
30        if $uc;
31     is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not yet called")
32        if $uc;
33     is($XS::APItest::CHECK_called, undef, "CHECK not yet called");
34     is($XS::APItest::CHECK_called_PP, undef, "CHECK not yet called");
35     is($XS::APItest::INIT_called, undef, "INIT not yet called");
36     is($XS::APItest::INIT_called_PP, undef, "INIT not yet called");
37     is($XS::APItest::END_called, undef, "END not yet called");
38     is($XS::APItest::END_called_PP, undef, "END not yet called");
39 }
40
41 CHECK {
42     print "# First CHECK\n";
43     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
44     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
45     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
46     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
47     is($XS::APItest::CHECK_called, 1, "CHECK called");
48     is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
49     is($XS::APItest::INIT_called, undef, "INIT not yet called");
50     is($XS::APItest::INIT_called_PP, undef, "INIT not yet called");
51     is($XS::APItest::END_called, undef, "END not yet called");
52     is($XS::APItest::END_called_PP, undef, "END not yet called");
53 }
54
55 INIT {
56     print "# First INIT\n";
57     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
58     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
59     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
60     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
61     is($XS::APItest::CHECK_called, 1, "CHECK called");
62     is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
63     is($XS::APItest::INIT_called, undef, "INIT not yet called");
64     is($XS::APItest::INIT_called_PP, undef, "INIT not yet called");
65     is($XS::APItest::END_called, undef, "END not yet called");
66     is($XS::APItest::END_called_PP, undef, "END not yet called");
67 }
68
69 END {
70     print "# First END\n";
71     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
72     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
73     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
74     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
75     is($XS::APItest::CHECK_called, 1, "CHECK called");
76     is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
77     is($XS::APItest::INIT_called, 1, "INIT called");
78     is($XS::APItest::INIT_called_PP, 1, "INIT called");
79     is($XS::APItest::END_called, 1, "END called");
80     is($XS::APItest::END_called_PP, 1, "END called");
81 }
82
83 print "# First body\n";
84 is($XS::APItest::BEGIN_called, 1, "BEGIN called");
85 is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
86 is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
87 is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
88 is($XS::APItest::CHECK_called, 1, "CHECK called");
89 is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
90 is($XS::APItest::INIT_called, 1, "INIT called");
91 is($XS::APItest::INIT_called_PP, 1, "INIT called");
92 is($XS::APItest::END_called, undef, "END not yet called");
93 is($XS::APItest::END_called_PP, undef, "END not yet called");
94
95 use XS::APItest;
96
97 print "# Second body\n";
98 is($XS::APItest::BEGIN_called, 1, "BEGIN called");
99 is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
100 is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
101 is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
102 is($XS::APItest::CHECK_called, 1, "CHECK called");
103 is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
104 is($XS::APItest::INIT_called, 1, "INIT called");
105 is($XS::APItest::INIT_called_PP, 1, "INIT called");
106 is($XS::APItest::END_called, undef, "END not yet called");
107 is($XS::APItest::END_called_PP, undef, "END not yet called");
108
109 BEGIN {
110     print "# Second BEGIN\n";
111     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
112     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
113     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
114     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
115     is($XS::APItest::CHECK_called, undef, "CHECK not yet called");
116     is($XS::APItest::CHECK_called_PP, undef, "CHECK not yet called");
117     is($XS::APItest::INIT_called, undef, "INIT not yet called");
118     is($XS::APItest::INIT_called_PP, undef, "INIT not yet called");
119     is($XS::APItest::END_called, undef, "END not yet called");
120     is($XS::APItest::END_called_PP, undef, "END not yet called");
121 }
122
123 CHECK {
124     print "# Second CHECK\n";
125     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
126     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
127     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK yet called") if $uc;
128     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK yet called") if $uc;
129     is($XS::APItest::CHECK_called, undef, "CHECK not yet called");
130     is($XS::APItest::CHECK_called_PP, undef, "CHECK not yet called");
131     is($XS::APItest::INIT_called, undef, "INIT not yet called");
132     is($XS::APItest::INIT_called_PP, undef, "INIT not yet called");
133     is($XS::APItest::END_called, undef, "END not yet called");
134     is($XS::APItest::END_called_PP, undef, "END not yet called");
135 }
136
137 INIT {
138     print "# Second INIT\n";
139     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
140     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
141     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
142     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
143     is($XS::APItest::CHECK_called, 1, "CHECK called");
144     is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
145     is($XS::APItest::INIT_called, 1, "INIT called");
146     is($XS::APItest::INIT_called_PP, 1, "INIT called");
147     is($XS::APItest::END_called, undef, "END not yet called");
148     is($XS::APItest::END_called_PP, undef, "END not yet called");
149 }
150
151 END {
152     print "# Second END\n";
153     is($XS::APItest::BEGIN_called, 1, "BEGIN called");
154     is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
155     is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
156     is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
157     is($XS::APItest::CHECK_called, 1, "CHECK called");
158     is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
159     is($XS::APItest::INIT_called, 1, "INIT called");
160     is($XS::APItest::INIT_called_PP, 1, "INIT called");
161     is($XS::APItest::END_called, undef, "END not yet called");
162     is($XS::APItest::END_called_PP, undef, "END not yet called");
163 }