5 use Test::More tests => 17;
8 use t::BHK (); # make sure it gets compiled early
10 BEGIN { package XS::APItest; *main::bhkav = \@XS::APItest::bhkav }
12 # 'use t::BHK' switches on recording hooks, and clears @bhkav.
13 # 'no t::BHK' switches recording off again.
14 # 'use t::BHK push => "foo"' pushes onto @bhkav
16 BEGIN { diag "## COMPILE TIME ##" }
17 diag "## RUN TIME ##";
23 BEGIN { is_deeply \@bhkav, [], "no blocks" }
31 BEGIN { is_deeply \@bhkav,
32 [[start => 1], qw/pre_end post_end/],
40 BEGIN { is_deeply \@bhkav,
54 BEGIN { is_deeply \@bhkav,
70 BEGIN { is_deeply \@bhkav,
81 use t::BHK push => "before";
83 use t::BHK push => "inside";
85 use t::BHK push => "after";
88 BEGIN { is_deeply \@bhkav,
96 "hooks called in the correct places";
103 BEGIN { is_deeply \@bhkav,
106 qw/pre_end post_end/,
111 use t::BHK; t::BHK->import;
113 no t::BHK; t::BHK->unimport;
115 BEGIN { is_deeply \@bhkav, [], "string eval (compile)" }
118 [eval => "entereval"],
120 qw/pre_end post_end/,
124 delete @INC{qw{t/Null.pm t/Block.pm}};
134 qw/pre_end post_end/,
147 qw/pre_end post_end/,
148 qw/pre_end post_end/,
150 "do file (single block)";
152 delete @INC{qw{t/Null.pm t/Block.pm}};
162 qw/pre_end post_end/,
175 qw/pre_end post_end/,
176 qw/pre_end post_end/,
178 "require (single block)";
180 BEGIN { delete $INC{"t/Block.pm"} }
186 BEGIN { is_deeply \@bhkav,
191 qw/pre_end post_end/,
192 qw/pre_end post_end/,
194 "use (single block)";
197 BEGIN { delete $INC{"t/Markers.pm"} }
200 use t::BHK push => "compile/main/before";
202 use t::BHK push => "compile/main/after";
205 BEGIN { is_deeply \@bhkav,
207 "compile/main/before",
213 qw/pre_end post_end/,
215 qw/pre_end post_end/,
218 "compile/main/after",
223 # OK, now some *really* evil stuff...
228 sub DESTROY { $_[0]->() }
234 # grumbleSCOPECHECKgrumble
235 push @XS::APItest::COMPILE_SCOPE_CONTAINER,
237 push @bhkav, "DESTROY";
244 BEGIN { is_deeply \@bhkav,
246 [start => 1], # block
247 [start => 1], # BEGIN
249 qw/pre_end post_end/,
250 qw/pre_end post_end/,
255 "compile-time DESTROY comes between pre_ and post_end";
261 push @XS::APItest::COMPILE_SCOPE_CONTAINER,
270 BEGIN { is_deeply \@bhkav,
272 [start => 1], # block
273 [start => 1], # BEGIN
275 qw/pre_end post_end/,
276 qw/pre_end post_end/,
278 [eval => "entereval"],
280 [start => 1], # block inside eval
281 qw/pre_end post_end/,
282 qw/pre_end post_end/,
285 "evil eval-in-DESTROY tricks";