6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
10 # require 'test.pl'; # now done by OptreeCheck
16 skip "no perlio in this build", 20 unless $Config::Config{useperlio};
18 pass("GENERAL OPTREE EXAMPLES");
20 pass("IF,THEN,ELSE, ?:");
22 checkOptree ( name => '-basic sub {if shift print then,else}',
24 code => sub { if (shift) { print "then" }
27 strip_open_hints => 1,
28 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
29 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
30 # - <@> lineseq KP ->9
31 # 1 <;> nextstate(main 426 optree.t:16) v:>,<,% ->2
33 # 5 <|> cond_expr(other->6) K/1 ->a
34 # 4 <1> shift sK/1 ->5
35 # 3 <1> rv2av[t2] sKRM/1 ->4
38 # - <0> ex-nextstate v ->6
40 # 6 <0> pushmark s ->7
41 # 7 <$> const[PV "then"] s ->8
44 # b <;> nextstate(main 424 optree.t:17) v:>,<,% ->c
46 # c <0> pushmark s ->d
47 # d <$> const[PV "else"] s ->e
49 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
50 # - <@> lineseq KP ->9
51 # 1 <;> nextstate(main 427 optree_samples.t:18) v:>,<,% ->2
53 # 5 <|> cond_expr(other->6) K/1 ->a
54 # 4 <1> shift sK/1 ->5
55 # 3 <1> rv2av[t1] sKRM/1 ->4
58 # - <0> ex-nextstate v ->6
60 # 6 <0> pushmark s ->7
61 # 7 <$> const(PV "then") s ->8
64 # b <;> nextstate(main 425 optree_samples.t:19) v:>,<,% ->c
66 # c <0> pushmark s ->d
67 # d <$> const(PV "else") s ->e
70 checkOptree ( name => '-basic (see above, with my $a = shift)',
72 code => sub { my $a = shift;
73 if ($a) { print "foo" }
76 strip_open_hints => 1,
77 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
78 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
79 # - <@> lineseq KP ->d
80 # 1 <;> nextstate(main 431 optree.t:68) v:>,<,% ->2
81 # 6 <2> sassign vKS/2 ->7
82 # 4 <1> shift sK/1 ->5
83 # 3 <1> rv2av[t3] sKRM/1 ->4
85 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
86 # 7 <;> nextstate(main 435 optree.t:69) v:>,<,% ->8
88 # 9 <|> cond_expr(other->a) K/1 ->e
89 # 8 <0> padsv[$a:431,435] s ->9
91 # - <0> ex-nextstate v ->a
93 # a <0> pushmark s ->b
94 # b <$> const[PV "foo"] s ->c
97 # f <;> nextstate(main 433 optree.t:70) v:>,<,% ->g
99 # g <0> pushmark s ->h
100 # h <$> const[PV "bar"] s ->i
102 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
103 # - <@> lineseq KP ->d
104 # 1 <;> nextstate(main 428 optree_samples.t:48) v:>,<,% ->2
105 # 6 <2> sassign vKS/2 ->7
106 # 4 <1> shift sK/1 ->5
107 # 3 <1> rv2av[t2] sKRM/1 ->4
109 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
110 # 7 <;> nextstate(main 432 optree_samples.t:49) v:>,<,% ->8
112 # 9 <|> cond_expr(other->a) K/1 ->e
113 # 8 <0> padsv[$a:428,432] s ->9
115 # - <0> ex-nextstate v ->a
117 # a <0> pushmark s ->b
118 # b <$> const(PV "foo") s ->c
121 # f <;> nextstate(main 430 optree_samples.t:50) v:>,<,% ->g
123 # g <0> pushmark s ->h
124 # h <$> const(PV "bar") s ->i
127 checkOptree ( name => '-exec sub {if shift print then,else}',
129 code => sub { if (shift) { print "then" }
130 else { print "else" }
132 strip_open_hints => 1,
133 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
134 # 1 <;> nextstate(main 426 optree.t:16) v:>,<,%
136 # 3 <1> rv2av[t2] sKRM/1
138 # 5 <|> cond_expr(other->6) K/1
140 # 7 <$> const[PV "then"] s
144 # b <;> nextstate(main 424 optree.t:17) v:>,<,%
146 # d <$> const[PV "else"] s
149 # 9 <1> leavesub[1 ref] K/REFC,1
151 # 1 <;> nextstate(main 436 optree_samples.t:123) v:>,<,%
153 # 3 <1> rv2av[t1] sKRM/1
155 # 5 <|> cond_expr(other->6) K/1
157 # 7 <$> const(PV "then") s
161 # b <;> nextstate(main 434 optree_samples.t:124) v:>,<,%
163 # d <$> const(PV "else") s
166 # 9 <1> leavesub[1 ref] K/REFC,1
169 checkOptree ( name => '-exec (see above, with my $a = shift)',
171 code => sub { my $a = shift;
172 if ($a) { print "foo" }
175 strip_open_hints => 1,
176 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
177 # 1 <;> nextstate(main 423 optree.t:16) v:>,<,%
179 # 3 <1> rv2av[t3] sKRM/1
181 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
182 # 6 <2> sassign vKS/2
183 # 7 <;> nextstate(main 427 optree.t:17) v:>,<,%
184 # 8 <0> padsv[$a:423,427] s
185 # 9 <|> cond_expr(other->a) K/1
187 # b <$> const[PV "foo"] s
191 # f <;> nextstate(main 425 optree.t:18) v:>,<,%
193 # h <$> const[PV "bar"] s
196 # d <1> leavesub[1 ref] K/REFC,1
198 # 1 <;> nextstate(main 437 optree_samples.t:112) v:>,<,%
200 # 3 <1> rv2av[t2] sKRM/1
202 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
203 # 6 <2> sassign vKS/2
204 # 7 <;> nextstate(main 441 optree_samples.t:113) v:>,<,%
205 # 8 <0> padsv[$a:437,441] s
206 # 9 <|> cond_expr(other->a) K/1
208 # b <$> const(PV "foo") s
212 # f <;> nextstate(main 439 optree_samples.t:114) v:>,<,%
214 # h <$> const(PV "bar") s
217 # d <1> leavesub[1 ref] K/REFC,1
220 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
221 code => sub { print (shift) ? "foo" : "bar" },
223 strip_open_hints => 1,
224 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
225 # 1 <;> nextstate(main 428 optree.t:31) v:>,<,%
228 # 4 <1> rv2av[t2] sKRM/1
231 # 7 <|> cond_expr(other->8) K/1
232 # 8 <$> const[PV "foo"] s
234 # a <$> const[PV "bar"] s
235 # 9 <1> leavesub[1 ref] K/REFC,1
237 # 1 <;> nextstate(main 442 optree_samples.t:144) v:>,<,%
240 # 4 <1> rv2av[t1] sKRM/1
243 # 7 <|> cond_expr(other->8) K/1
244 # 8 <$> const(PV "foo") s
246 # a <$> const(PV "bar") s
247 # 9 <1> leavesub[1 ref] K/REFC,1
252 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
253 code => sub { foreach (1..10) {print "foo $_"} },
255 strip_open_hints => 1,
256 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
257 # 1 <;> nextstate(main 443 optree.t:158) v:>,<,%
259 # 3 <$> const[IV 1] s
260 # 4 <$> const[IV 10] s
262 # 6 <{> enteriter(next->d last->g redo->7) lKS/8
264 # f <|> and(other->7) K/1
265 # 7 <;> nextstate(main 442 optree.t:158) v:>,<,%
267 # 9 <$> const[PV "foo "] s
269 # b <2> concat[t4] sK/2
273 # g <2> leaveloop K/2
274 # h <1> leavesub[1 ref] K/REFC,1
276 # 1 <;> nextstate(main 444 optree_samples.t:182) v:>,<,%
278 # 3 <$> const(IV 1) s
279 # 4 <$> const(IV 10) s
281 # 6 <{> enteriter(next->d last->g redo->7) lKS/8
283 # f <|> and(other->7) K/1
284 # 7 <;> nextstate(main 443 optree_samples.t:182) v:>,<,%
286 # 9 <$> const(PV "foo ") s
288 # b <2> concat[t3] sK/2
292 # g <2> leaveloop K/2
293 # h <1> leavesub[1 ref] K/REFC,1
296 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
297 code => sub { print "foo $_" foreach (1..10) },
299 strip_open_hints => 1,
300 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
301 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
302 # - <@> lineseq KP ->h
303 # 1 <;> nextstate(main 445 optree.t:167) v:>,<,% ->2
304 # 2 <;> nextstate(main 445 optree.t:167) v:>,<,% ->3
305 # g <2> leaveloop K/2 ->h
306 # 7 <{> enteriter(next->d last->g redo->8) lKS/8 ->e
307 # - <0> ex-pushmark s ->3
308 # - <1> ex-list lK ->6
309 # 3 <0> pushmark s ->4
310 # 4 <$> const[IV 1] s ->5
311 # 5 <$> const[IV 10] s ->6
314 # f <|> and(other->8) K/1 ->g
316 # - <@> lineseq sK ->-
318 # 8 <0> pushmark s ->9
319 # - <1> ex-stringify sK/1 ->c
320 # - <0> ex-pushmark s ->9
321 # b <2> concat[t2] sK/2 ->c
322 # 9 <$> const[PV "foo "] s ->a
323 # - <1> ex-rv2sv sK/1 ->b
324 # a <#> gvsv[*_] s ->b
325 # d <0> unstack s ->e
327 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
328 # - <@> lineseq KP ->h
329 # 1 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->2
330 # 2 <;> nextstate(main 446 optree_samples.t:192) v:>,<,% ->3
331 # g <2> leaveloop K/2 ->h
332 # 7 <{> enteriter(next->d last->g redo->8) lKS/8 ->e
333 # - <0> ex-pushmark s ->3
334 # - <1> ex-list lK ->6
335 # 3 <0> pushmark s ->4
336 # 4 <$> const(IV 1) s ->5
337 # 5 <$> const(IV 10) s ->6
340 # f <|> and(other->8) K/1 ->g
342 # - <@> lineseq sK ->-
344 # 8 <0> pushmark s ->9
345 # - <1> ex-stringify sK/1 ->c
346 # - <0> ex-pushmark s ->9
347 # b <2> concat[t1] sK/2 ->c
348 # 9 <$> const(PV "foo ") s ->a
349 # - <1> ex-rv2sv sK/1 ->b
350 # a <$> gvsv(*_) s ->b
351 # d <0> unstack s ->e
354 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
355 prog => 'foreach (1..10) {print qq{foo $_}}',
357 strip_open_hints => 1,
358 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
360 # 2 <;> nextstate(main 2 -e:1) v:>,<,%
362 # 4 <$> const[IV 1] s
363 # 5 <$> const[IV 10] s
365 # 7 <{> enteriter(next->e last->h redo->8) lKS/8
367 # g <|> and(other->8) vK/1
368 # 8 <;> nextstate(main 1 -e:1) v:>,<,%
370 # a <$> const[PV "foo "] s
372 # c <2> concat[t4] sK/2
376 # h <2> leaveloop vK/2
377 # i <@> leave[1 ref] vKP/REFC
380 # 2 <;> nextstate(main 2 -e:1) v:>,<,%
382 # 4 <$> const(IV 1) s
383 # 5 <$> const(IV 10) s
385 # 7 <{> enteriter(next->e last->h redo->8) lKS/8
387 # g <|> and(other->8) vK/1
388 # 8 <;> nextstate(main 1 -e:1) v:>,<,%
390 # a <$> const(PV "foo ") s
392 # c <2> concat[t3] sK/2
396 # h <2> leaveloop vK/2
397 # i <@> leave[1 ref] vKP/REFC
400 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
401 code => sub { print "foo $_" foreach (1..10) },
403 strip_open_hints => 1,
404 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
405 # 1 <;> nextstate(main 445 optree.t:167) v:>,<,%
406 # 2 <;> nextstate(main 445 optree.t:167) v:>,<,%
408 # 4 <$> const[IV 1] s
409 # 5 <$> const[IV 10] s
411 # 7 <{> enteriter(next->d last->g redo->8) lKS/8
413 # f <|> and(other->8) K/1
415 # 9 <$> const[PV "foo "] s
417 # b <2> concat[t2] sK/2
421 # g <2> leaveloop K/2
422 # h <1> leavesub[1 ref] K/REFC,1
424 # 1 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
425 # 2 <;> nextstate(main 447 optree_samples.t:252) v:>,<,%
427 # 4 <$> const(IV 1) s
428 # 5 <$> const(IV 10) s
430 # 7 <{> enteriter(next->d last->g redo->8) lKS/8
432 # f <|> and(other->8) K/1
434 # 9 <$> const(PV "foo ") s
436 # b <2> concat[t1] sK/2
440 # g <2> leaveloop K/2
441 # h <1> leavesub[1 ref] K/REFC,1
444 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
446 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
447 code => '@foo = grep(!/^\#/, @bar)',
449 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
450 # 1 <;> nextstate(main 496 (eval 20):1) v:{
454 # 5 <1> rv2av[t4] lKM/1
456 # 7 <|> grepwhile(other->8)[t5] lK
457 # 8 </> match(/"^#"/) s/RTIME
462 # c <1> rv2av[t2] lKRM*/1
463 # d <2> aassign[t6] KS/COMMON
464 # e <1> leavesub[1 ref] K/REFC,1
466 # 1 <;> nextstate(main 496 (eval 20):1) v:{
470 # 5 <1> rv2av[t2] lKM/1
472 # 7 <|> grepwhile(other->8)[t3] lK
473 # 8 </> match(/"^\\#"/) s/RTIME
478 # c <1> rv2av[t1] lKRM*/1
479 # d <2> aassign[t4] KS/COMMON
480 # e <1> leavesub[1 ref] K/REFC,1
484 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
486 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
487 code => '%h = map { getkey($_) => $_ } @a',
489 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
490 # 1 <;> nextstate(main 501 (eval 22):1) v:{
494 # 5 <1> rv2av[t8] lKM/1
496 # 7 <|> mapwhile(other->8)[t9] lK
498 # 9 <;> nextstate(main 500 (eval 22):1) v:{
502 # d <#> gv[*getkey] s/EARLYCV
503 # e <1> entersub[t5] lKS/TARG,1
510 # k <1> rv2hv[t2] lKRM*/1
511 # l <2> aassign[t10] KS/COMMON
512 # m <1> leavesub[1 ref] K/REFC,1
514 # 1 <;> nextstate(main 501 (eval 22):1) v:{
518 # 5 <1> rv2av[t3] lKM/1
520 # 7 <|> mapwhile(other->8)[t4] lK
522 # 9 <;> nextstate(main 500 (eval 22):1) v:{
526 # d <$> gv(*getkey) s/EARLYCV
527 # e <1> entersub[t2] lKS/TARG,1
534 # k <1> rv2hv[t1] lKRM*/1
535 # l <2> aassign[t5] KS/COMMON
536 # m <1> leavesub[1 ref] K/REFC,1
539 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
540 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
542 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
543 # 1 <;> nextstate(main 505 (eval 24):1) v
547 # 5 <1> rv2hv[t2] lKRM*/1
548 # 6 <2> aassign[t3] vKS
549 # 7 <;> nextstate(main 506 (eval 24):1) v:{
552 # a <1> rv2av[t6] sKRM/1
555 # d <{> enteriter(next->o last->r redo->e) lKS/8
557 # q <|> and(other->e) K/1
558 # e <;> nextstate(main 505 (eval 24):1) v:{
564 # k <#> gv[*getkey] s/EARLYCV
565 # l <1> entersub[t10] sKS/TARG,1
566 # m <2> helem sKRM*/2
567 # n <2> sassign vKS/2
570 # r <2> leaveloop K/2
571 # s <1> leavesub[1 ref] K/REFC,1
573 # 1 <;> nextstate(main 505 (eval 24):1) v
577 # 5 <1> rv2hv[t1] lKRM*/1
578 # 6 <2> aassign[t2] vKS
579 # 7 <;> nextstate(main 506 (eval 24):1) v:{
582 # a <1> rv2av[t3] sKRM/1
585 # d <{> enteriter(next->o last->r redo->e) lKS/8
587 # q <|> and(other->e) K/1
588 # e <;> nextstate(main 505 (eval 24):1) v:{
594 # k <$> gv(*getkey) s/EARLYCV
595 # l <1> entersub[t4] sKS/TARG,1
596 # m <2> helem sKRM*/2
597 # n <2> sassign vKS/2
600 # r <2> leaveloop K/2
601 # s <1> leavesub[1 ref] K/REFC,1
604 checkOptree ( name => 'map $_+42, 10..20',
605 code => 'map $_+42, 10..20',
607 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
608 # 1 <;> nextstate(main 497 (eval 20):1) v
613 # 6 <|> mapwhile(other->7)[t5] K
615 # 8 <$> const[IV 42] s
618 # a <1> leavesub[1 ref] K/REFC,1
620 # 1 <;> nextstate(main 511 (eval 26):1) v
625 # 6 <|> mapwhile(other->7)[t4] K
627 # 8 <$> const(IV 42) s
630 # a <1> leavesub[1 ref] K/REFC,1
635 checkOptree ( name => '-e use constant j => qq{junk}; print j',
636 prog => 'use constant j => qq{junk}; print j',
638 strip_open_hints => 1,
639 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
641 # 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
643 # 4 <$> const[PV "junk"] s
645 # 6 <@> leave[1 ref] vKP/REFC
648 # 2 <;> nextstate(main 71 -e:1) v:>,<,%,{
650 # 4 <$> const(PV "junk") s
652 # 6 <@> leave[1 ref] vKP/REFC
659 #######################################################################
661 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
662 code => sub { print (shift) ? "foo" : "bar" },
664 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
665 insert threaded reference here
667 insert non-threaded reference here