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