Debian Codegraph @

ext/XS-APItest/t/xs_special_subs_require.t

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