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