xs_special_subs.t revision 1.1.1.2
1#!perl -w
2
3BEGIN {
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
15use strict;
16use warnings;
17my $uc;
18BEGIN {
19    $uc = $] > 5.009;
20}
21use 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
25BEGIN {
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
41CHECK {
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
55INIT {
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
69END {
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
83print "# First body\n";
84is($XS::APItest::BEGIN_called, 1, "BEGIN called");
85is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
86is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
87is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
88is($XS::APItest::CHECK_called, 1, "CHECK called");
89is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
90is($XS::APItest::INIT_called, 1, "INIT called");
91is($XS::APItest::INIT_called_PP, 1, "INIT called");
92is($XS::APItest::END_called, undef, "END not yet called");
93is($XS::APItest::END_called_PP, undef, "END not yet called");
94
95use XS::APItest;
96
97print "# Second body\n";
98is($XS::APItest::BEGIN_called, 1, "BEGIN called");
99is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called");
100is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called") if $uc;
101is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called") if $uc;
102is($XS::APItest::CHECK_called, 1, "CHECK called");
103is($XS::APItest::CHECK_called_PP, 1, "CHECK called");
104is($XS::APItest::INIT_called, 1, "INIT called");
105is($XS::APItest::INIT_called_PP, 1, "INIT called");
106is($XS::APItest::END_called, undef, "END not yet called");
107is($XS::APItest::END_called_PP, undef, "END not yet called");
108
109BEGIN {
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
123CHECK {
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
137INIT {
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
151END {
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}
164