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