Commit | Line | Data |
a6ea7cf3 |
1 | #!perl -w |
2 | BEGIN { |
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 | |
16 | use strict; |
17 | use warnings; |
18 | use 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 |
22 | BEGIN { |
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 | |
36 | CHECK { |
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 | |
50 | INIT { |
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 | |
64 | END { |
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 | |
78 | print "# First body\n"; |
79 | is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); |
80 | is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); |
81 | is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); |
82 | is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not called"); |
83 | is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); |
84 | is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); |
85 | is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); |
86 | is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); |
87 | is($XS::APItest::END_called, undef, "END not yet called"); |
88 | is($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 | |
101 | print "# Second body\n"; |
102 | is($XS::APItest::BEGIN_called, 1, "BEGIN called"); |
103 | is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called"); |
104 | is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called"); |
105 | is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called"); |
106 | is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); |
107 | is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); |
108 | is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); |
109 | is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); |
110 | is($XS::APItest::END_called, undef, "END not yet called"); |
111 | is($XS::APItest::END_called_PP, undef, "END not yet called"); |
112 | |
113 | BEGIN { |
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 | |
127 | CHECK { |
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 | |
141 | INIT { |
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 | |
155 | END { |
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 | } |