This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix VMS build broken by d1718a7cf5
[perl5.git] / ext / B / t / optree_specials.t
1 #!./perl
2
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
8 # spaces.
9
10 BEGIN {
11     unshift @INC, 't';
12     require Config;
13     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
14         print "1..0 # Skip -- Perl configured without B module\n";
15         exit 0;
16     }
17 }
18
19 # import checkOptree(), and %gOpts (containing test state)
20 use OptreeCheck;        # ALSO DOES @ARGV HANDLING !!!!!!
21 use Config;
22
23 plan tests => 13 + ($] > 5.009 ? 2 : 0);
24
25 require_ok("B::Concise");
26
27 my $out = runperl(
28     switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
29     prog => q{$a=$b && print q/foo/},
30     stderr => 1 );
31
32 #print "out:$out\n";
33
34 my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
35
36
37 my @warnings_todo;
38 @warnings_todo = (todo =>
39    "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
40    . "propagated to 5.8.x")
41     if $] < 5.009;
42
43 checkOptree ( name      => 'BEGIN',
44               bcopts    => 'BEGIN',
45               prog      => $src,
46               @warnings_todo,
47               strip_open_hints => 1,
48               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
49 # BEGIN 1:
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
56 # -        <@> lineseq K ->-
57 # -           <0> null ->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
63 # BEGIN 2:
64 # k  <1> leavesub[1 ref] K/REFC,1 ->(end)
65 # -     <@> lineseq K ->k
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
70 # -        <@> lineseq K ->-
71 # -           <0> null ->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
77 # BEGIN 3:
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
84 # -        <@> lineseq K ->-
85 # -           <0> null ->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
91 # BEGIN 4:
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
98 EOT_EOT
99 # BEGIN 1:
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 ->-
107 # -           <0> null ->5
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
113 # BEGIN 2:
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 ->-
121 # -           <0> null ->f
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
127 # BEGIN 3:
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 ->-
135 # -           <0> null ->p
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
141 # BEGIN 4:
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
148 EONT_EONT
149
150
151 checkOptree ( name      => 'END',
152               bcopts    => 'END',
153               prog      => $src,
154               strip_open_hints => 1,
155               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
156 # END 1:
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
163 EOT_EOT
164 # END 1:
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
171 EONT_EONT
172
173
174 checkOptree ( name      => 'CHECK',
175               bcopts    => 'CHECK',
176               prog      => $src,
177               strip_open_hints => 1,
178               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
179 # CHECK 1:
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
186 EOT_EOT
187 # CHECK 1:
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
194 EONT_EONT
195
196 if ($] >= 5.009) {
197     checkOptree ( name  => 'UNITCHECK',
198                   bcopts=> 'UNITCHECK',
199                   prog  => $src,
200                   strip_open_hints => 1,
201                   expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
202 # UNITCHECK 1:
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
209 EOT_EOT
210 # UNITCHECK 1:
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
217 EONT_EONT
218 }
219
220 checkOptree ( name      => 'INIT',
221               bcopts    => 'INIT',
222               #todo     => 'get working',
223               prog      => $src,
224               strip_open_hints => 1,
225               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
226 # INIT 1:
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
233 EOT_EOT
234 # INIT 1:
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
241 EONT_EONT
242
243
244 checkOptree ( name      => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
245               bcopts    => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
246               prog      => $src,
247               @warnings_todo,
248               strip_open_hints => 1,
249               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
250 # BEGIN 1:
251 # 1  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
252 # 2  <$> const[PV "strict.pm"] s/BARE
253 # 3  <1> require sK/1
254 # 4  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
255 # 5  <0> pushmark s
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
261 # BEGIN 2:
262 # b  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
263 # c  <$> const[PV "strict.pm"] s/BARE
264 # d  <1> require sK/1
265 # e  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
266 # f  <0> pushmark s
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
272 # BEGIN 3:
273 # l  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
274 # m  <$> const[PV "warnings.pm"] s/BARE
275 # n  <1> require sK/1
276 # o  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
277 # p  <0> pushmark s
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
283 # BEGIN 4:
284 # v  <;> nextstate(main 2 -e:1) v:>,<,%,{
285 # w  <#> gvsv[*beg] s
286 # x  <1> postinc[t3] sK/1
287 # y  <1> leavesub[1 ref] K/REFC,1
288 # END 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
293 # INIT 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
298 # CHECK 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
303 # UNITCHECK 1:
304 # 1b <;> nextstate(main 6 -e:1) v:>,<,%,{
305 # 1c <#> gvsv[*uc] s
306 # 1d <1> postinc[t3] sK/1
307 # 1e <1> leavesub[1 ref] K/REFC,1
308 EOT_EOT
309 # BEGIN 1:
310 # 1  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
311 # 2  <$> const(PV "strict.pm") s/BARE
312 # 3  <1> require sK/1
313 # 4  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
314 # 5  <0> pushmark s
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
320 # BEGIN 2:
321 # b  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
322 # c  <$> const(PV "strict.pm") s/BARE
323 # d  <1> require sK/1
324 # e  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
325 # f  <0> pushmark s
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
331 # BEGIN 3:
332 # l  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
333 # m  <$> const(PV "warnings.pm") s/BARE
334 # n  <1> require sK/1
335 # o  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
336 # p  <0> pushmark s
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
342 # BEGIN 4:
343 # v  <;> nextstate(main 2 -e:1) v:>,<,%,{
344 # w  <$> gvsv(*beg) s
345 # x  <1> postinc[t2] sK/1
346 # y  <1> leavesub[1 ref] K/REFC,1
347 # END 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
352 # INIT 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
357 # CHECK 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
362 # UNITCHECK 1:
363 # 1b <;> nextstate(main 6 -e:1) v:>,<,%,{
364 # 1c <$> gvsv(*uc) s
365 # 1d <1> postinc[t2] sK/1
366 # 1e <1> leavesub[1 ref] K/REFC,1
367 EONT_EONT
368
369
370 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
371
372
373
374 checkOptree ( name      => 'regression test for patch 25352',
375               bcopts    => [qw/ BEGIN END INIT CHECK -exec /],
376               prog      => 'print q/foo/',
377               @warnings_todo,
378               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
379 # BEGIN 1:
380 # 1  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
381 # 2  <$> const[PV "strict.pm"] s/BARE
382 # 3  <1> require sK/1
383 # 4  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
384 # 5  <0> pushmark s
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
390 # BEGIN 2:
391 # b  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
392 # c  <$> const[PV "strict.pm"] s/BARE
393 # d  <1> require sK/1
394 # e  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
395 # f  <0> pushmark s
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
401 # BEGIN 3:
402 # l  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
403 # m  <$> const[PV "warnings.pm"] s/BARE
404 # n  <1> require sK/1
405 # o  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
406 # p  <0> pushmark s
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
412 EOT_EOT
413 # BEGIN 1:
414 # 1  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
415 # 2  <$> const(PV "strict.pm") s/BARE
416 # 3  <1> require sK/1
417 # 4  <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
418 # 5  <0> pushmark s
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
424 # BEGIN 2:
425 # b  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
426 # c  <$> const(PV "strict.pm") s/BARE
427 # d  <1> require sK/1
428 # e  <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
429 # f  <0> pushmark s
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
435 # BEGIN 3:
436 # l  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
437 # m  <$> const(PV "warnings.pm") s/BARE
438 # n  <1> require sK/1
439 # o  <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
440 # p  <0> pushmark s
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
446 EONT_EONT