3 # This tests the B:: module(s) with CHECK, BEGIN, END and INIT blocks. The
4 # text excerpts below marked with "# " in front are the expected output. They
5 # are there twice, EOT for threading, and EONT for a non-threading Perl. The
6 # output is matched losely. If the match fails even though the "got" and
7 # "expected" output look exactly the same, then watch for trailing, invisible
13 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
14 print "1..0 # Skip -- Perl configured without B module\n";
19 # import checkOptree(), and %gOpts (containing test state)
20 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
23 plan tests => 13 + ($] > 5.009 ? 2 : 0);
25 require_ok("B::Concise");
28 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
29 prog => q{$a=$b && print q/foo/},
34 my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
38 @warnings_todo = (todo =>
39 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
40 . "propagated to 5.8.x")
43 checkOptree ( name => 'BEGIN',
47 strip_open_hints => 1,
48 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
50 # a <1> leavesub[1 ref] K/REFC,1 ->(end)
51 # - <@> lineseq KP ->a
52 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$ ->2
53 # 3 <1> require sK/1 ->4
54 # 2 <$> const[PV "strict.pm"] s/BARE ->3
55 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$ ->5
58 # 9 <1> entersub[t1] KS*/TARG,2 ->a
59 # 5 <0> pushmark s ->6
60 # 6 <$> const[PV "strict"] sM ->7
61 # 7 <$> const[PV "refs"] sM ->8
62 # 8 <$> method_named[PV "unimport"] ->9
64 # k <1> leavesub[1 ref] K/REFC,1 ->(end)
66 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$ ->c
67 # d <1> require sK/1 ->e
68 # c <$> const[PV "strict.pm"] s/BARE ->d
69 # e <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$ ->f
72 # j <1> entersub[t1] KS*/TARG,2 ->k
73 # f <0> pushmark s ->g
74 # g <$> const[PV "strict"] sM ->h
75 # h <$> const[PV "refs"] sM ->i
76 # i <$> method_named[PV "unimport"] ->j
78 # u <1> leavesub[1 ref] K/REFC,1 ->(end)
79 # - <@> lineseq KP ->u
80 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$ ->m
81 # n <1> require sK/1 ->o
82 # m <$> const[PV "warnings.pm"] s/BARE ->n
83 # o <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$ ->p
86 # t <1> entersub[t1] KS*/TARG,2 ->u
87 # p <0> pushmark s ->q
88 # q <$> const[PV "warnings"] sM ->r
89 # r <$> const[PV "qw"] sM ->s
90 # s <$> method_named[PV "unimport"] ->t
92 # y <1> leavesub[1 ref] K/REFC,1 ->(end)
93 # - <@> lineseq KP ->y
94 # v <;> nextstate(main 2 -e:1) v:>,<,%,{ ->w
95 # x <1> postinc[t3] sK/1 ->y
96 # - <1> ex-rv2sv sKRM/1 ->x
97 # w <#> gvsv[*beg] s ->x
100 # a <1> leavesub[1 ref] K/REFC,1 ->(end)
101 # - <@> lineseq KP ->a
102 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$ ->2
103 # 3 <1> require sK/1 ->4
104 # 2 <$> const(PV "strict.pm") s/BARE ->3
105 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$ ->5
106 # - <@> lineseq K ->-
108 # 9 <1> entersub[t1] KS*/TARG,2 ->a
109 # 5 <0> pushmark s ->6
110 # 6 <$> const(PV "strict") sM ->7
111 # 7 <$> const(PV "refs") sM ->8
112 # 8 <$> method_named(PV "unimport") ->9
114 # k <1> leavesub[1 ref] K/REFC,1 ->(end)
115 # - <@> lineseq K ->k
116 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$ ->c
117 # d <1> require sK/1 ->e
118 # c <$> const(PV "strict.pm") s/BARE ->d
119 # e <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$ ->f
120 # - <@> lineseq K ->-
122 # j <1> entersub[t1] KS*/TARG,2 ->k
123 # f <0> pushmark s ->g
124 # g <$> const(PV "strict") sM ->h
125 # h <$> const(PV "refs") sM ->i
126 # i <$> method_named(PV "unimport") ->j
128 # u <1> leavesub[1 ref] K/REFC,1 ->(end)
129 # - <@> lineseq KP ->u
130 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$ ->m
131 # n <1> require sK/1 ->o
132 # m <$> const(PV "warnings.pm") s/BARE ->n
133 # o <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$ ->p
134 # - <@> lineseq K ->-
136 # t <1> entersub[t1] KS*/TARG,2 ->u
137 # p <0> pushmark s ->q
138 # q <$> const(PV "warnings") sM ->r
139 # r <$> const(PV "qw") sM ->s
140 # s <$> method_named(PV "unimport") ->t
142 # y <1> leavesub[1 ref] K/REFC,1 ->(end)
143 # - <@> lineseq KP ->y
144 # v <;> nextstate(main 2 -e:1) v:>,<,%,{ ->w
145 # x <1> postinc[t2] sK/1 ->y
146 # - <1> ex-rv2sv sKRM/1 ->x
147 # w <$> gvsv(*beg) s ->x
151 checkOptree ( name => 'END',
154 strip_open_hints => 1,
155 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
157 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
158 # - <@> lineseq KP ->4
159 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
160 # 3 <1> postinc[t3] sK/1 ->4
161 # - <1> ex-rv2sv sKRM/1 ->3
162 # 2 <#> gvsv[*end] s ->3
165 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
166 # - <@> lineseq KP ->4
167 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
168 # 3 <1> postinc[t2] sK/1 ->4
169 # - <1> ex-rv2sv sKRM/1 ->3
170 # 2 <$> gvsv(*end) s ->3
174 checkOptree ( name => 'CHECK',
177 strip_open_hints => 1,
178 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
180 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
181 # - <@> lineseq KP ->4
182 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
183 # 3 <1> postinc[t3] sK/1 ->4
184 # - <1> ex-rv2sv sKRM/1 ->3
185 # 2 <#> gvsv[*chk] s ->3
188 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
189 # - <@> lineseq KP ->4
190 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
191 # 3 <1> postinc[t2] sK/1 ->4
192 # - <1> ex-rv2sv sKRM/1 ->3
193 # 2 <$> gvsv(*chk) s ->3
197 checkOptree ( name => 'UNITCHECK',
198 bcopts=> 'UNITCHECK',
200 strip_open_hints => 1,
201 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
203 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
204 # - <@> lineseq KP ->4
205 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
206 # 3 <1> postinc[t3] sK/1 ->4
207 # - <1> ex-rv2sv sKRM/1 ->3
208 # 2 <#> gvsv[*uc] s ->3
211 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
212 # - <@> lineseq KP ->4
213 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
214 # 3 <1> postinc[t2] sK/1 ->4
215 # - <1> ex-rv2sv sKRM/1 ->3
216 # 2 <$> gvsv(*uc) s ->3
220 checkOptree ( name => 'INIT',
222 #todo => 'get working',
224 strip_open_hints => 1,
225 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
227 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
228 # - <@> lineseq KP ->4
229 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
230 # 3 <1> postinc[t3] sK/1 ->4
231 # - <1> ex-rv2sv sKRM/1 ->3
232 # 2 <#> gvsv[*init] s ->3
235 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
236 # - <@> lineseq KP ->4
237 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
238 # 3 <1> postinc[t2] sK/1 ->4
239 # - <1> ex-rv2sv sKRM/1 ->3
240 # 2 <$> gvsv(*init) s ->3
244 checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
245 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
248 strip_open_hints => 1,
249 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
251 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
252 # 2 <$> const[PV "strict.pm"] s/BARE
254 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
256 # 6 <$> const[PV "strict"] sM
257 # 7 <$> const[PV "refs"] sM
258 # 8 <$> method_named[PV "unimport"]
259 # 9 <1> entersub[t1] KS*/TARG,2
260 # a <1> leavesub[1 ref] K/REFC,1
262 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
263 # c <$> const[PV "strict.pm"] s/BARE
265 # e <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
267 # g <$> const[PV "strict"] sM
268 # h <$> const[PV "refs"] sM
269 # i <$> method_named[PV "unimport"]
270 # j <1> entersub[t1] KS*/TARG,2
271 # k <1> leavesub[1 ref] K/REFC,1
273 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
274 # m <$> const[PV "warnings.pm"] s/BARE
276 # o <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
278 # q <$> const[PV "warnings"] sM
279 # r <$> const[PV "qw"] sM
280 # s <$> method_named[PV "unimport"]
281 # t <1> entersub[t1] KS*/TARG,2
282 # u <1> leavesub[1 ref] K/REFC,1
284 # v <;> nextstate(main 2 -e:1) v:>,<,%,{
286 # x <1> postinc[t3] sK/1
287 # y <1> leavesub[1 ref] K/REFC,1
289 # z <;> nextstate(main 5 -e:1) v:>,<,%,{
290 # 10 <#> gvsv[*end] s
291 # 11 <1> postinc[t3] sK/1
292 # 12 <1> leavesub[1 ref] K/REFC,1
294 # 13 <;> nextstate(main 4 -e:1) v:>,<,%,{
295 # 14 <#> gvsv[*init] s
296 # 15 <1> postinc[t3] sK/1
297 # 16 <1> leavesub[1 ref] K/REFC,1
299 # 17 <;> nextstate(main 3 -e:1) v:>,<,%,{
300 # 18 <#> gvsv[*chk] s
301 # 19 <1> postinc[t3] sK/1
302 # 1a <1> leavesub[1 ref] K/REFC,1
304 # 1b <;> nextstate(main 6 -e:1) v:>,<,%,{
306 # 1d <1> postinc[t3] sK/1
307 # 1e <1> leavesub[1 ref] K/REFC,1
310 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
311 # 2 <$> const(PV "strict.pm") s/BARE
313 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
315 # 6 <$> const(PV "strict") sM
316 # 7 <$> const(PV "refs") sM
317 # 8 <$> method_named(PV "unimport")
318 # 9 <1> entersub[t1] KS*/TARG,2
319 # a <1> leavesub[1 ref] K/REFC,1
321 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
322 # c <$> const(PV "strict.pm") s/BARE
324 # e <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
326 # g <$> const(PV "strict") sM
327 # h <$> const(PV "refs") sM
328 # i <$> method_named(PV "unimport")
329 # j <1> entersub[t1] KS*/TARG,2
330 # k <1> leavesub[1 ref] K/REFC,1
332 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
333 # m <$> const(PV "warnings.pm") s/BARE
335 # o <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
337 # q <$> const(PV "warnings") sM
338 # r <$> const(PV "qw") sM
339 # s <$> method_named(PV "unimport")
340 # t <1> entersub[t1] KS*/TARG,2
341 # u <1> leavesub[1 ref] K/REFC,1
343 # v <;> nextstate(main 2 -e:1) v:>,<,%,{
345 # x <1> postinc[t2] sK/1
346 # y <1> leavesub[1 ref] K/REFC,1
348 # z <;> nextstate(main 5 -e:1) v:>,<,%,{
349 # 10 <$> gvsv(*end) s
350 # 11 <1> postinc[t2] sK/1
351 # 12 <1> leavesub[1 ref] K/REFC,1
353 # 13 <;> nextstate(main 4 -e:1) v:>,<,%,{
354 # 14 <$> gvsv(*init) s
355 # 15 <1> postinc[t2] sK/1
356 # 16 <1> leavesub[1 ref] K/REFC,1
358 # 17 <;> nextstate(main 3 -e:1) v:>,<,%,{
359 # 18 <$> gvsv(*chk) s
360 # 19 <1> postinc[t2] sK/1
361 # 1a <1> leavesub[1 ref] K/REFC,1
363 # 1b <;> nextstate(main 6 -e:1) v:>,<,%,{
365 # 1d <1> postinc[t2] sK/1
366 # 1e <1> leavesub[1 ref] K/REFC,1
370 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
374 checkOptree ( name => 'regression test for patch 25352',
375 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
376 prog => 'print q/foo/',
378 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
380 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
381 # 2 <$> const[PV "strict.pm"] s/BARE
383 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
385 # 6 <$> const[PV "strict"] sM
386 # 7 <$> const[PV "refs"] sM
387 # 8 <$> method_named[PV "unimport"]
388 # 9 <1> entersub[t1] KS*/TARG,2
389 # a <1> leavesub[1 ref] K/REFC,1
391 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
392 # c <$> const[PV "strict.pm"] s/BARE
394 # e <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
396 # g <$> const[PV "strict"] sM
397 # h <$> const[PV "refs"] sM
398 # i <$> method_named[PV "unimport"]
399 # j <1> entersub[t1] KS*/TARG,2
400 # k <1> leavesub[1 ref] K/REFC,1
402 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
403 # m <$> const[PV "warnings.pm"] s/BARE
405 # o <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
407 # q <$> const[PV "warnings"] sM
408 # r <$> const[PV "qw"] sM
409 # s <$> method_named[PV "unimport"]
410 # t <1> entersub[t1] KS*/TARG,2
411 # u <1> leavesub[1 ref] K/REFC,1
414 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
415 # 2 <$> const(PV "strict.pm") s/BARE
417 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
419 # 6 <$> const(PV "strict") sM
420 # 7 <$> const(PV "refs") sM
421 # 8 <$> method_named(PV "unimport")
422 # 9 <1> entersub[t1] KS*/TARG,2
423 # a <1> leavesub[1 ref] K/REFC,1
425 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
426 # c <$> const(PV "strict.pm") s/BARE
428 # e <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
430 # g <$> const(PV "strict") sM
431 # h <$> const(PV "refs") sM
432 # i <$> method_named(PV "unimport")
433 # j <1> entersub[t1] KS*/TARG,2
434 # k <1> leavesub[1 ref] K/REFC,1
436 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
437 # m <$> const(PV "warnings.pm") s/BARE
439 # o <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
441 # q <$> const(PV "warnings") sM
442 # r <$> const(PV "qw") sM
443 # s <$> method_named(PV "unimport")
444 # t <1> entersub[t1] KS*/TARG,2
445 # u <1> leavesub[1 ref] K/REFC,1