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 @INC = ('.', '../lib', '../ext/B/t');
19 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
20 print "1..0 # Skip -- Perl configured without B module\n";
23 # require 'test.pl'; # now done by OptreeCheck
26 # import checkOptree(), and %gOpts (containing test state)
27 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
30 plan tests => 7 + ($] > 5.009 ? 1 : 0);
32 require_ok("B::Concise");
35 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
36 prog => q{$a=$b && print q/foo/},
41 my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
45 @warnings_todo = (todo =>
46 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
47 . "propagated to 5.8.x")
50 checkOptree ( name => 'BEGIN',
54 strip_open_hints => 1,
55 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
57 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
58 # - <@> lineseq KP ->b
59 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->2
60 # 3 <1> require sK/1 ->4
61 # 2 <$> const[PV "strict.pm"] s/BARE ->3
62 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->5
64 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ ->6
65 # a <1> entersub[t1] KS*/TARG,2 ->b
66 # 6 <0> pushmark s ->7
67 # 7 <$> const[PV "strict"] sM ->8
68 # 8 <$> const[PV "refs"] sM ->9
69 # 9 <$> method_named[PV "unimport"] ->a
71 # m <1> leavesub[1 ref] K/REFC,1 ->(end)
73 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->d
74 # e <1> require sK/1 ->f
75 # d <$> const[PV "strict.pm"] s/BARE ->e
76 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->g
78 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ ->h
79 # l <1> entersub[t1] KS*/TARG,2 ->m
80 # h <0> pushmark s ->i
81 # i <$> const[PV "strict"] sM ->j
82 # j <$> const[PV "refs"] sM ->k
83 # k <$> method_named[PV "unimport"] ->l
85 # x <1> leavesub[1 ref] K/REFC,1 ->(end)
86 # - <@> lineseq KP ->x
87 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->o
88 # p <1> require sK/1 ->q
89 # o <$> const[PV "warnings.pm"] s/BARE ->p
90 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->r
92 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ ->s
93 # w <1> entersub[t1] KS*/TARG,2 ->x
94 # s <0> pushmark s ->t
95 # t <$> const[PV "warnings"] sM ->u
96 # u <$> const[PV "qw"] sM ->v
97 # v <$> method_named[PV "unimport"] ->w
99 # 11 <1> leavesub[1 ref] K/REFC,1 ->(end)
100 # - <@> lineseq KP ->11
101 # y <;> nextstate(main 2 -e:1) v:>,<,%,{ ->z
102 # 10 <1> postinc[t3] sK/1 ->11
103 # - <1> ex-rv2sv sKRM/1 ->10
104 # z <#> gvsv[*beg] s ->10
107 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
108 # - <@> lineseq KP ->b
109 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->2
110 # 3 <1> require sK/1 ->4
111 # 2 <$> const(PV "strict.pm") s/BARE ->3
112 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->5
113 # - <@> lineseq K ->-
114 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ ->6
115 # a <1> entersub[t1] KS*/TARG,2 ->b
116 # 6 <0> pushmark s ->7
117 # 7 <$> const(PV "strict") sM ->8
118 # 8 <$> const(PV "refs") sM ->9
119 # 9 <$> method_named(PV "unimport") ->a
121 # m <1> leavesub[1 ref] K/REFC,1 ->(end)
122 # - <@> lineseq K ->m
123 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->d
124 # e <1> require sK/1 ->f
125 # d <$> const(PV "strict.pm") s/BARE ->e
126 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->g
127 # - <@> lineseq K ->-
128 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ ->h
129 # l <1> entersub[t1] KS*/TARG,2 ->m
130 # h <0> pushmark s ->i
131 # i <$> const(PV "strict") sM ->j
132 # j <$> const(PV "refs") sM ->k
133 # k <$> method_named(PV "unimport") ->l
135 # x <1> leavesub[1 ref] K/REFC,1 ->(end)
136 # - <@> lineseq KP ->x
137 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->o
138 # p <1> require sK/1 ->q
139 # o <$> const(PV "warnings.pm") s/BARE ->p
140 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->r
141 # - <@> lineseq K ->-
142 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ ->s
143 # w <1> entersub[t1] KS*/TARG,2 ->x
144 # s <0> pushmark s ->t
145 # t <$> const(PV "warnings") sM ->u
146 # u <$> const(PV "qw") sM ->v
147 # v <$> method_named(PV "unimport") ->w
149 # 11 <1> leavesub[1 ref] K/REFC,1 ->(end)
150 # - <@> lineseq KP ->11
151 # y <;> nextstate(main 2 -e:1) v:>,<,%,{ ->z
152 # 10 <1> postinc[t2] sK/1 ->11
153 # - <1> ex-rv2sv sKRM/1 ->10
154 # z <$> gvsv(*beg) s ->10
158 checkOptree ( name => 'END',
161 strip_open_hints => 1,
162 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
164 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
165 # - <@> lineseq KP ->4
166 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
167 # 3 <1> postinc[t3] sK/1 ->4
168 # - <1> ex-rv2sv sKRM/1 ->3
169 # 2 <#> gvsv[*end] s ->3
172 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
173 # - <@> lineseq KP ->4
174 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
175 # 3 <1> postinc[t2] sK/1 ->4
176 # - <1> ex-rv2sv sKRM/1 ->3
177 # 2 <$> gvsv(*end) s ->3
181 checkOptree ( name => 'CHECK',
184 strip_open_hints => 1,
185 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
187 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
188 # - <@> lineseq KP ->4
189 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
190 # 3 <1> postinc[t3] sK/1 ->4
191 # - <1> ex-rv2sv sKRM/1 ->3
192 # 2 <#> gvsv[*chk] s ->3
195 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
196 # - <@> lineseq KP ->4
197 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
198 # 3 <1> postinc[t2] sK/1 ->4
199 # - <1> ex-rv2sv sKRM/1 ->3
200 # 2 <$> gvsv(*chk) s ->3
204 checkOptree ( name => 'UNITCHECK',
205 bcopts=> 'UNITCHECK',
207 strip_open_hints => 1,
208 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
210 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
211 # - <@> lineseq KP ->4
212 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
213 # 3 <1> postinc[t3] sK/1 ->4
214 # - <1> ex-rv2sv sKRM/1 ->3
215 # 2 <#> gvsv[*uc] s ->3
218 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
219 # - <@> lineseq KP ->4
220 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
221 # 3 <1> postinc[t2] sK/1 ->4
222 # - <1> ex-rv2sv sKRM/1 ->3
223 # 2 <$> gvsv(*uc) s ->3
227 checkOptree ( name => 'INIT',
229 #todo => 'get working',
231 strip_open_hints => 1,
232 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
234 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
235 # - <@> lineseq KP ->4
236 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
237 # 3 <1> postinc[t3] sK/1 ->4
238 # - <1> ex-rv2sv sKRM/1 ->3
239 # 2 <#> gvsv[*init] s ->3
242 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
243 # - <@> lineseq KP ->4
244 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
245 # 3 <1> postinc[t2] sK/1 ->4
246 # - <1> ex-rv2sv sKRM/1 ->3
247 # 2 <$> gvsv(*init) s ->3
251 checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
252 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
255 strip_open_hints => 1,
256 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
258 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
259 # 2 <$> const[PV "strict.pm"] s/BARE
261 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
262 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
264 # 7 <$> const[PV "strict"] sM
265 # 8 <$> const[PV "refs"] sM
266 # 9 <$> method_named[PV "unimport"]
267 # a <1> entersub[t1] KS*/TARG,2
268 # b <1> leavesub[1 ref] K/REFC,1
270 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
271 # d <$> const[PV "strict.pm"] s/BARE
273 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
274 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
276 # i <$> const[PV "strict"] sM
277 # j <$> const[PV "refs"] sM
278 # k <$> method_named[PV "unimport"]
279 # l <1> entersub[t1] KS*/TARG,2
280 # m <1> leavesub[1 ref] K/REFC,1
282 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
283 # o <$> const[PV "warnings.pm"] s/BARE
285 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
286 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
288 # t <$> const[PV "warnings"] sM
289 # u <$> const[PV "qw"] sM
290 # v <$> method_named[PV "unimport"]
291 # w <1> entersub[t1] KS*/TARG,2
292 # x <1> leavesub[1 ref] K/REFC,1
294 # y <;> nextstate(main 2 -e:1) v:>,<,%,{
296 # 10 <1> postinc[t3] sK/1
297 # 11 <1> leavesub[1 ref] K/REFC,1
299 # 12 <;> nextstate(main 5 -e:1) v:>,<,%,{
300 # 13 <#> gvsv[*end] s
301 # 14 <1> postinc[t3] sK/1
302 # 15 <1> leavesub[1 ref] K/REFC,1
304 # 16 <;> nextstate(main 4 -e:1) v:>,<,%,{
305 # 17 <#> gvsv[*init] s
306 # 18 <1> postinc[t3] sK/1
307 # 19 <1> leavesub[1 ref] K/REFC,1
309 # 1a <;> nextstate(main 3 -e:1) v:>,<,%,{
310 # 1b <#> gvsv[*chk] s
311 # 1c <1> postinc[t3] sK/1
312 # 1d <1> leavesub[1 ref] K/REFC,1
314 # 1e <;> nextstate(main 6 -e:1) v:>,<,%,{
316 # 1g <1> postinc[t3] sK/1
317 # 1h <1> leavesub[1 ref] K/REFC,1
320 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
321 # 2 <$> const(PV "strict.pm") s/BARE
323 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
324 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
326 # 7 <$> const(PV "strict") sM
327 # 8 <$> const(PV "refs") sM
328 # 9 <$> method_named(PV "unimport")
329 # a <1> entersub[t1] KS*/TARG,2
330 # b <1> leavesub[1 ref] K/REFC,1
332 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
333 # d <$> const(PV "strict.pm") s/BARE
335 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
336 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
338 # i <$> const(PV "strict") sM
339 # j <$> const(PV "refs") sM
340 # k <$> method_named(PV "unimport")
341 # l <1> entersub[t1] KS*/TARG,2
342 # m <1> leavesub[1 ref] K/REFC,1
344 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
345 # o <$> const(PV "warnings.pm") s/BARE
347 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
348 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
350 # t <$> const(PV "warnings") sM
351 # u <$> const(PV "qw") sM
352 # v <$> method_named(PV "unimport")
353 # w <1> entersub[t1] KS*/TARG,2
354 # x <1> leavesub[1 ref] K/REFC,1
356 # y <;> nextstate(main 2 -e:1) v:>,<,%,{
358 # 10 <1> postinc[t2] sK/1
359 # 11 <1> leavesub[1 ref] K/REFC,1
361 # 12 <;> nextstate(main 5 -e:1) v:>,<,%,{
362 # 13 <$> gvsv(*end) s
363 # 14 <1> postinc[t2] sK/1
364 # 15 <1> leavesub[1 ref] K/REFC,1
366 # 16 <;> nextstate(main 4 -e:1) v:>,<,%,{
367 # 17 <$> gvsv(*init) s
368 # 18 <1> postinc[t2] sK/1
369 # 19 <1> leavesub[1 ref] K/REFC,1
371 # 1a <;> nextstate(main 3 -e:1) v:>,<,%,{
372 # 1b <$> gvsv(*chk) s
373 # 1c <1> postinc[t2] sK/1
374 # 1d <1> leavesub[1 ref] K/REFC,1
376 # 1e <;> nextstate(main 6 -e:1) v:>,<,%,{
378 # 1g <1> postinc[t2] sK/1
379 # 1h <1> leavesub[1 ref] K/REFC,1
383 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
387 checkOptree ( name => 'regression test for patch 25352',
388 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
389 prog => 'print q/foo/',
391 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
393 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
394 # 2 <$> const[PV "strict.pm"] s/BARE
396 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
397 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
399 # 7 <$> const[PV "strict"] sM
400 # 8 <$> const[PV "refs"] sM
401 # 9 <$> method_named[PV "unimport"]
402 # a <1> entersub[t1] KS*/TARG,2
403 # b <1> leavesub[1 ref] K/REFC,1
405 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
406 # d <$> const[PV "strict.pm"] s/BARE
408 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
409 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
411 # i <$> const[PV "strict"] sM
412 # j <$> const[PV "refs"] sM
413 # k <$> method_named[PV "unimport"]
414 # l <1> entersub[t1] KS*/TARG,2
415 # m <1> leavesub[1 ref] K/REFC,1
417 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
418 # o <$> const[PV "warnings.pm"] s/BARE
420 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
421 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
423 # t <$> const[PV "warnings"] sM
424 # u <$> const[PV "qw"] sM
425 # v <$> method_named[PV "unimport"]
426 # w <1> entersub[t1] KS*/TARG,2
427 # x <1> leavesub[1 ref] K/REFC,1
430 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
431 # 2 <$> const(PV "strict.pm") s/BARE
433 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
434 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
436 # 7 <$> const(PV "strict") sM
437 # 8 <$> const(PV "refs") sM
438 # 9 <$> method_named(PV "unimport")
439 # a <1> entersub[t1] KS*/TARG,2
440 # b <1> leavesub[1 ref] K/REFC,1
442 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
443 # d <$> const(PV "strict.pm") s/BARE
445 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
446 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
448 # i <$> const(PV "strict") sM
449 # j <$> const(PV "refs") sM
450 # k <$> method_named(PV "unimport")
451 # l <1> entersub[t1] KS*/TARG,2
452 # m <1> leavesub[1 ref] K/REFC,1
454 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
455 # o <$> const(PV "warnings.pm") s/BARE
457 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
458 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
460 # t <$> const(PV "warnings") sM
461 # u <$> const(PV "qw") sM
462 # v <$> method_named(PV "unimport")
463 # w <1> entersub[t1] KS*/TARG,2
464 # x <1> leavesub[1 ref] K/REFC,1