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";
17 # require 'test.pl'; # now done by OptreeCheck
20 # import checkOptree(), and %gOpts (containing test state)
21 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
24 plan tests => 7 + ($] > 5.009 ? 1 : 0);
26 require_ok("B::Concise");
29 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
30 prog => q{$a=$b && print q/foo/},
35 my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
39 @warnings_todo = (todo =>
40 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
41 . "propagated to 5.8.x")
44 checkOptree ( name => 'BEGIN',
48 strip_open_hints => 1,
49 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
51 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
52 # - <@> lineseq KP ->b
53 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->2
54 # 3 <1> require sK/1 ->4
55 # 2 <$> const[PV "strict.pm"] s/BARE ->3
56 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->5
58 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ ->6
59 # a <1> entersub[t1] KS*/TARG,2 ->b
60 # 6 <0> pushmark s ->7
61 # 7 <$> const[PV "strict"] sM ->8
62 # 8 <$> const[PV "refs"] sM ->9
63 # 9 <$> method_named[PV "unimport"] ->a
65 # m <1> leavesub[1 ref] K/REFC,1 ->(end)
67 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->d
68 # e <1> require sK/1 ->f
69 # d <$> const[PV "strict.pm"] s/BARE ->e
70 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->g
72 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ ->h
73 # l <1> entersub[t1] KS*/TARG,2 ->m
74 # h <0> pushmark s ->i
75 # i <$> const[PV "strict"] sM ->j
76 # j <$> const[PV "refs"] sM ->k
77 # k <$> method_named[PV "unimport"] ->l
79 # x <1> leavesub[1 ref] K/REFC,1 ->(end)
80 # - <@> lineseq KP ->x
81 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->o
82 # p <1> require sK/1 ->q
83 # o <$> const[PV "warnings.pm"] s/BARE ->p
84 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->r
86 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ ->s
87 # w <1> entersub[t1] KS*/TARG,2 ->x
88 # s <0> pushmark s ->t
89 # t <$> const[PV "warnings"] sM ->u
90 # u <$> const[PV "qw"] sM ->v
91 # v <$> method_named[PV "unimport"] ->w
93 # 11 <1> leavesub[1 ref] K/REFC,1 ->(end)
94 # - <@> lineseq KP ->11
95 # y <;> nextstate(main 2 -e:1) v:>,<,%,{ ->z
96 # 10 <1> postinc[t3] sK/1 ->11
97 # - <1> ex-rv2sv sKRM/1 ->10
98 # z <#> gvsv[*beg] s ->10
101 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
102 # - <@> lineseq KP ->b
103 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->2
104 # 3 <1> require sK/1 ->4
105 # 2 <$> const(PV "strict.pm") s/BARE ->3
106 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->5
107 # - <@> lineseq K ->-
108 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ ->6
109 # a <1> entersub[t1] KS*/TARG,2 ->b
110 # 6 <0> pushmark s ->7
111 # 7 <$> const(PV "strict") sM ->8
112 # 8 <$> const(PV "refs") sM ->9
113 # 9 <$> method_named(PV "unimport") ->a
115 # m <1> leavesub[1 ref] K/REFC,1 ->(end)
116 # - <@> lineseq K ->m
117 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->d
118 # e <1> require sK/1 ->f
119 # d <$> const(PV "strict.pm") s/BARE ->e
120 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->g
121 # - <@> lineseq K ->-
122 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ ->h
123 # l <1> entersub[t1] KS*/TARG,2 ->m
124 # h <0> pushmark s ->i
125 # i <$> const(PV "strict") sM ->j
126 # j <$> const(PV "refs") sM ->k
127 # k <$> method_named(PV "unimport") ->l
129 # x <1> leavesub[1 ref] K/REFC,1 ->(end)
130 # - <@> lineseq KP ->x
131 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->o
132 # p <1> require sK/1 ->q
133 # o <$> const(PV "warnings.pm") s/BARE ->p
134 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->r
135 # - <@> lineseq K ->-
136 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ ->s
137 # w <1> entersub[t1] KS*/TARG,2 ->x
138 # s <0> pushmark s ->t
139 # t <$> const(PV "warnings") sM ->u
140 # u <$> const(PV "qw") sM ->v
141 # v <$> method_named(PV "unimport") ->w
143 # 11 <1> leavesub[1 ref] K/REFC,1 ->(end)
144 # - <@> lineseq KP ->11
145 # y <;> nextstate(main 2 -e:1) v:>,<,%,{ ->z
146 # 10 <1> postinc[t2] sK/1 ->11
147 # - <1> ex-rv2sv sKRM/1 ->10
148 # z <$> gvsv(*beg) s ->10
152 checkOptree ( name => 'END',
155 strip_open_hints => 1,
156 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
158 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
159 # - <@> lineseq KP ->4
160 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
161 # 3 <1> postinc[t3] sK/1 ->4
162 # - <1> ex-rv2sv sKRM/1 ->3
163 # 2 <#> gvsv[*end] s ->3
166 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
167 # - <@> lineseq KP ->4
168 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
169 # 3 <1> postinc[t2] sK/1 ->4
170 # - <1> ex-rv2sv sKRM/1 ->3
171 # 2 <$> gvsv(*end) s ->3
175 checkOptree ( name => 'CHECK',
178 strip_open_hints => 1,
179 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
181 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
182 # - <@> lineseq KP ->4
183 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
184 # 3 <1> postinc[t3] sK/1 ->4
185 # - <1> ex-rv2sv sKRM/1 ->3
186 # 2 <#> gvsv[*chk] s ->3
189 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
190 # - <@> lineseq KP ->4
191 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
192 # 3 <1> postinc[t2] sK/1 ->4
193 # - <1> ex-rv2sv sKRM/1 ->3
194 # 2 <$> gvsv(*chk) s ->3
198 checkOptree ( name => 'UNITCHECK',
199 bcopts=> 'UNITCHECK',
201 strip_open_hints => 1,
202 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
204 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
205 # - <@> lineseq KP ->4
206 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
207 # 3 <1> postinc[t3] sK/1 ->4
208 # - <1> ex-rv2sv sKRM/1 ->3
209 # 2 <#> gvsv[*uc] s ->3
212 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
213 # - <@> lineseq KP ->4
214 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
215 # 3 <1> postinc[t2] sK/1 ->4
216 # - <1> ex-rv2sv sKRM/1 ->3
217 # 2 <$> gvsv(*uc) s ->3
221 checkOptree ( name => 'INIT',
223 #todo => 'get working',
225 strip_open_hints => 1,
226 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
228 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
229 # - <@> lineseq KP ->4
230 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
231 # 3 <1> postinc[t3] sK/1 ->4
232 # - <1> ex-rv2sv sKRM/1 ->3
233 # 2 <#> gvsv[*init] s ->3
236 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
237 # - <@> lineseq KP ->4
238 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
239 # 3 <1> postinc[t2] sK/1 ->4
240 # - <1> ex-rv2sv sKRM/1 ->3
241 # 2 <$> gvsv(*init) s ->3
245 checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
246 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
249 strip_open_hints => 1,
250 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
252 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
253 # 2 <$> const[PV "strict.pm"] s/BARE
255 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
256 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
258 # 7 <$> const[PV "strict"] sM
259 # 8 <$> const[PV "refs"] sM
260 # 9 <$> method_named[PV "unimport"]
261 # a <1> entersub[t1] KS*/TARG,2
262 # b <1> leavesub[1 ref] K/REFC,1
264 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
265 # d <$> const[PV "strict.pm"] s/BARE
267 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
268 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
270 # i <$> const[PV "strict"] sM
271 # j <$> const[PV "refs"] sM
272 # k <$> method_named[PV "unimport"]
273 # l <1> entersub[t1] KS*/TARG,2
274 # m <1> leavesub[1 ref] K/REFC,1
276 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
277 # o <$> const[PV "warnings.pm"] s/BARE
279 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
280 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
282 # t <$> const[PV "warnings"] sM
283 # u <$> const[PV "qw"] sM
284 # v <$> method_named[PV "unimport"]
285 # w <1> entersub[t1] KS*/TARG,2
286 # x <1> leavesub[1 ref] K/REFC,1
288 # y <;> nextstate(main 2 -e:1) v:>,<,%,{
290 # 10 <1> postinc[t3] sK/1
291 # 11 <1> leavesub[1 ref] K/REFC,1
293 # 12 <;> nextstate(main 5 -e:1) v:>,<,%,{
294 # 13 <#> gvsv[*end] s
295 # 14 <1> postinc[t3] sK/1
296 # 15 <1> leavesub[1 ref] K/REFC,1
298 # 16 <;> nextstate(main 4 -e:1) v:>,<,%,{
299 # 17 <#> gvsv[*init] s
300 # 18 <1> postinc[t3] sK/1
301 # 19 <1> leavesub[1 ref] K/REFC,1
303 # 1a <;> nextstate(main 3 -e:1) v:>,<,%,{
304 # 1b <#> gvsv[*chk] s
305 # 1c <1> postinc[t3] sK/1
306 # 1d <1> leavesub[1 ref] K/REFC,1
308 # 1e <;> nextstate(main 6 -e:1) v:>,<,%,{
310 # 1g <1> postinc[t3] sK/1
311 # 1h <1> leavesub[1 ref] K/REFC,1
314 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
315 # 2 <$> const(PV "strict.pm") s/BARE
317 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
318 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
320 # 7 <$> const(PV "strict") sM
321 # 8 <$> const(PV "refs") sM
322 # 9 <$> method_named(PV "unimport")
323 # a <1> entersub[t1] KS*/TARG,2
324 # b <1> leavesub[1 ref] K/REFC,1
326 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
327 # d <$> const(PV "strict.pm") s/BARE
329 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
330 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
332 # i <$> const(PV "strict") sM
333 # j <$> const(PV "refs") sM
334 # k <$> method_named(PV "unimport")
335 # l <1> entersub[t1] KS*/TARG,2
336 # m <1> leavesub[1 ref] K/REFC,1
338 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
339 # o <$> const(PV "warnings.pm") s/BARE
341 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
342 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
344 # t <$> const(PV "warnings") sM
345 # u <$> const(PV "qw") sM
346 # v <$> method_named(PV "unimport")
347 # w <1> entersub[t1] KS*/TARG,2
348 # x <1> leavesub[1 ref] K/REFC,1
350 # y <;> nextstate(main 2 -e:1) v:>,<,%,{
352 # 10 <1> postinc[t2] sK/1
353 # 11 <1> leavesub[1 ref] K/REFC,1
355 # 12 <;> nextstate(main 5 -e:1) v:>,<,%,{
356 # 13 <$> gvsv(*end) s
357 # 14 <1> postinc[t2] sK/1
358 # 15 <1> leavesub[1 ref] K/REFC,1
360 # 16 <;> nextstate(main 4 -e:1) v:>,<,%,{
361 # 17 <$> gvsv(*init) s
362 # 18 <1> postinc[t2] sK/1
363 # 19 <1> leavesub[1 ref] K/REFC,1
365 # 1a <;> nextstate(main 3 -e:1) v:>,<,%,{
366 # 1b <$> gvsv(*chk) s
367 # 1c <1> postinc[t2] sK/1
368 # 1d <1> leavesub[1 ref] K/REFC,1
370 # 1e <;> nextstate(main 6 -e:1) v:>,<,%,{
372 # 1g <1> postinc[t2] sK/1
373 # 1h <1> leavesub[1 ref] K/REFC,1
377 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
381 checkOptree ( name => 'regression test for patch 25352',
382 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
383 prog => 'print q/foo/',
385 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
387 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
388 # 2 <$> const[PV "strict.pm"] s/BARE
390 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
391 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
393 # 7 <$> const[PV "strict"] sM
394 # 8 <$> const[PV "refs"] sM
395 # 9 <$> method_named[PV "unimport"]
396 # a <1> entersub[t1] KS*/TARG,2
397 # b <1> leavesub[1 ref] K/REFC,1
399 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
400 # d <$> const[PV "strict.pm"] s/BARE
402 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
403 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
405 # i <$> const[PV "strict"] sM
406 # j <$> const[PV "refs"] sM
407 # k <$> method_named[PV "unimport"]
408 # l <1> entersub[t1] KS*/TARG,2
409 # m <1> leavesub[1 ref] K/REFC,1
411 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
412 # o <$> const[PV "warnings.pm"] s/BARE
414 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
415 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
417 # t <$> const[PV "warnings"] sM
418 # u <$> const[PV "qw"] sM
419 # v <$> method_named[PV "unimport"]
420 # w <1> entersub[t1] KS*/TARG,2
421 # x <1> leavesub[1 ref] K/REFC,1
424 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
425 # 2 <$> const(PV "strict.pm") s/BARE
427 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$
428 # 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$
430 # 7 <$> const(PV "strict") sM
431 # 8 <$> const(PV "refs") sM
432 # 9 <$> method_named(PV "unimport")
433 # a <1> entersub[t1] KS*/TARG,2
434 # b <1> leavesub[1 ref] K/REFC,1
436 # c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
437 # d <$> const(PV "strict.pm") s/BARE
439 # f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$
440 # g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$
442 # i <$> const(PV "strict") sM
443 # j <$> const(PV "refs") sM
444 # k <$> method_named(PV "unimport")
445 # l <1> entersub[t1] KS*/TARG,2
446 # m <1> leavesub[1 ref] K/REFC,1
448 # n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
449 # o <$> const(PV "warnings.pm") s/BARE
451 # q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$
452 # r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$
454 # t <$> const(PV "warnings") sM
455 # u <$> const(PV "qw") sM
456 # v <$> method_named(PV "unimport")
457 # w <1> entersub[t1] KS*/TARG,2
458 # x <1> leavesub[1 ref] K/REFC,1