6 @INC = ('.', '../lib', '../ext/B/t');
12 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
13 print "1..0 # Skip -- Perl configured without B module\n";
16 if ($Config::Config{'extensions'} !~ /\bData\/Dumper\b/) {
18 "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
22 print "1..0 # Skip -- TODO - provide golden result regexps for 5.8\n";
31 skip "no perlio in this build", 20 unless $Config::Config{useperlio};
33 pass("GENERAL OPTREE EXAMPLES");
35 pass("IF,THEN,ELSE, ?:");
37 checkOptree ( name => '-basic sub {if shift print then,else}',
39 code => sub { if (shift) { print "then" }
42 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
43 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
44 # - <@> lineseq KP ->9
45 # 1 <;> nextstate(main 426 optree.t:16) v ->2
47 # 5 <|> cond_expr(other->6) K/1 ->a
48 # 4 <1> shift sK/1 ->5
49 # 3 <1> rv2av[t2] sKRM/1 ->4
52 # - <0> ex-nextstate v ->6
54 # 6 <0> pushmark s ->7
55 # 7 <$> const[PV "then"] s ->8
58 # b <;> nextstate(main 424 optree.t:17) v ->c
60 # c <0> pushmark s ->d
61 # d <$> const[PV "else"] s ->e
63 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
64 # - <@> lineseq KP ->9
65 # 1 <;> nextstate(main 427 optree_samples.t:18) v ->2
67 # 5 <|> cond_expr(other->6) K/1 ->a
68 # 4 <1> shift sK/1 ->5
69 # 3 <1> rv2av[t1] sKRM/1 ->4
72 # - <0> ex-nextstate v ->6
74 # 6 <0> pushmark s ->7
75 # 7 <$> const(PV "then") s ->8
78 # b <;> nextstate(main 425 optree_samples.t:19) v ->c
80 # c <0> pushmark s ->d
81 # d <$> const(PV "else") s ->e
84 checkOptree ( name => '-basic (see above, with my $a = shift)',
86 code => sub { my $a = shift;
87 if ($a) { print "foo" }
90 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
91 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
92 # - <@> lineseq KP ->d
93 # 1 <;> nextstate(main 431 optree.t:68) v ->2
94 # 6 <2> sassign vKS/2 ->7
95 # 4 <1> shift sK/1 ->5
96 # 3 <1> rv2av[t3] sKRM/1 ->4
98 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
99 # 7 <;> nextstate(main 435 optree.t:69) v ->8
101 # 9 <|> cond_expr(other->a) K/1 ->e
102 # 8 <0> padsv[$a:431,435] s ->9
104 # - <0> ex-nextstate v ->a
106 # a <0> pushmark s ->b
107 # b <$> const[PV "foo"] s ->c
110 # f <;> nextstate(main 433 optree.t:70) v ->g
112 # g <0> pushmark s ->h
113 # h <$> const[PV "bar"] s ->i
115 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
116 # - <@> lineseq KP ->d
117 # 1 <;> nextstate(main 428 optree_samples.t:48) v ->2
118 # 6 <2> sassign vKS/2 ->7
119 # 4 <1> shift sK/1 ->5
120 # 3 <1> rv2av[t2] sKRM/1 ->4
122 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
123 # 7 <;> nextstate(main 432 optree_samples.t:49) v ->8
125 # 9 <|> cond_expr(other->a) K/1 ->e
126 # 8 <0> padsv[$a:428,432] s ->9
128 # - <0> ex-nextstate v ->a
130 # a <0> pushmark s ->b
131 # b <$> const(PV "foo") s ->c
134 # f <;> nextstate(main 430 optree_samples.t:50) v ->g
136 # g <0> pushmark s ->h
137 # h <$> const(PV "bar") s ->i
140 checkOptree ( name => '-exec sub {if shift print then,else}',
142 code => sub { if (shift) { print "then" }
143 else { print "else" }
145 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
146 # 1 <;> nextstate(main 426 optree.t:16) v
148 # 3 <1> rv2av[t2] sKRM/1
150 # 5 <|> cond_expr(other->6) K/1
152 # 7 <$> const[PV "then"] s
156 # b <;> nextstate(main 424 optree.t:17) v
158 # d <$> const[PV "else"] s
161 # 9 <1> leavesub[1 ref] K/REFC,1
163 # 1 <;> nextstate(main 436 optree_samples.t:123) v
165 # 3 <1> rv2av[t1] sKRM/1
167 # 5 <|> cond_expr(other->6) K/1
169 # 7 <$> const(PV "then") s
173 # b <;> nextstate(main 434 optree_samples.t:124) v
175 # d <$> const(PV "else") s
178 # 9 <1> leavesub[1 ref] K/REFC,1
181 checkOptree ( name => '-exec (see above, with my $a = shift)',
183 code => sub { my $a = shift;
184 if ($a) { print "foo" }
187 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
188 # 1 <;> nextstate(main 423 optree.t:16) v
190 # 3 <1> rv2av[t3] sKRM/1
192 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
193 # 6 <2> sassign vKS/2
194 # 7 <;> nextstate(main 427 optree.t:17) v
195 # 8 <0> padsv[$a:423,427] s
196 # 9 <|> cond_expr(other->a) K/1
198 # b <$> const[PV "foo"] s
202 # f <;> nextstate(main 425 optree.t:18) v
204 # h <$> const[PV "bar"] s
207 # d <1> leavesub[1 ref] K/REFC,1
209 # 1 <;> nextstate(main 437 optree_samples.t:112) v
211 # 3 <1> rv2av[t2] sKRM/1
213 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
214 # 6 <2> sassign vKS/2
215 # 7 <;> nextstate(main 441 optree_samples.t:113) v
216 # 8 <0> padsv[$a:437,441] s
217 # 9 <|> cond_expr(other->a) K/1
219 # b <$> const(PV "foo") s
223 # f <;> nextstate(main 439 optree_samples.t:114) v
225 # h <$> const(PV "bar") s
228 # d <1> leavesub[1 ref] K/REFC,1
231 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
232 code => sub { print (shift) ? "foo" : "bar" },
234 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
235 # 1 <;> nextstate(main 428 optree.t:31) v
238 # 4 <1> rv2av[t2] sKRM/1
241 # 7 <|> cond_expr(other->8) K/1
242 # 8 <$> const[PV "foo"] s
244 # a <$> const[PV "bar"] s
245 # 9 <1> leavesub[1 ref] K/REFC,1
247 # 1 <;> nextstate(main 442 optree_samples.t:144) v
250 # 4 <1> rv2av[t1] sKRM/1
253 # 7 <|> cond_expr(other->8) K/1
254 # 8 <$> const(PV "foo") s
256 # a <$> const(PV "bar") s
257 # 9 <1> leavesub[1 ref] K/REFC,1
262 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
263 code => sub { foreach (1..10) {print "foo $_"} },
265 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
266 # 1 <;> nextstate(main 443 optree.t:158) v
268 # 3 <$> const[IV 1] s
269 # 4 <$> const[IV 10] s
271 # 6 <{> enteriter(next->d last->g redo->7) lKS
273 # f <|> and(other->7) K/1
274 # 7 <;> nextstate(main 442 optree.t:158) v
276 # 9 <$> const[PV "foo "] s
278 # b <2> concat[t4] sK/2
282 # g <2> leaveloop K/2
283 # h <1> leavesub[1 ref] K/REFC,1
285 # 1 <;> nextstate(main 444 optree_samples.t:182) v
287 # 3 <$> const(IV 1) s
288 # 4 <$> const(IV 10) s
290 # 6 <{> enteriter(next->d last->g redo->7) lKS
292 # f <|> and(other->7) K/1
293 # 7 <;> nextstate(main 443 optree_samples.t:182) v
295 # 9 <$> const(PV "foo ") s
297 # b <2> concat[t3] sK/2
301 # g <2> leaveloop K/2
302 # h <1> leavesub[1 ref] K/REFC,1
305 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
306 code => sub { print "foo $_" foreach (1..10) },
308 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
309 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
310 # - <@> lineseq KP ->h
311 # 1 <;> nextstate(main 445 optree.t:167) v ->2
312 # 2 <;> nextstate(main 445 optree.t:167) v ->3
313 # g <2> leaveloop K/2 ->h
314 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
315 # - <0> ex-pushmark s ->3
316 # - <1> ex-list lK ->6
317 # 3 <0> pushmark s ->4
318 # 4 <$> const[IV 1] s ->5
319 # 5 <$> const[IV 10] s ->6
322 # f <|> and(other->8) K/1 ->g
324 # - <@> lineseq sK ->-
326 # 8 <0> pushmark s ->9
327 # - <1> ex-stringify sK/1 ->c
328 # - <0> ex-pushmark s ->9
329 # b <2> concat[t2] sK/2 ->c
330 # 9 <$> const[PV "foo "] s ->a
331 # - <1> ex-rv2sv sK/1 ->b
332 # a <#> gvsv[*_] s ->b
333 # d <0> unstack s ->e
335 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
336 # - <@> lineseq KP ->h
337 # 1 <;> nextstate(main 446 optree_samples.t:192) v ->2
338 # 2 <;> nextstate(main 446 optree_samples.t:192) v ->3
339 # g <2> leaveloop K/2 ->h
340 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
341 # - <0> ex-pushmark s ->3
342 # - <1> ex-list lK ->6
343 # 3 <0> pushmark s ->4
344 # 4 <$> const(IV 1) s ->5
345 # 5 <$> const(IV 10) s ->6
348 # f <|> and(other->8) K/1 ->g
350 # - <@> lineseq sK ->-
352 # 8 <0> pushmark s ->9
353 # - <1> ex-stringify sK/1 ->c
354 # - <0> ex-pushmark s ->9
355 # b <2> concat[t1] sK/2 ->c
356 # 9 <$> const(PV "foo ") s ->a
357 # - <1> ex-rv2sv sK/1 ->b
358 # a <$> gvsv(*_) s ->b
359 # d <0> unstack s ->e
362 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
363 prog => 'foreach (1..10) {print qq{foo $_}}',
365 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
367 # 2 <;> nextstate(main 2 -e:1) v
369 # 4 <$> const[IV 1] s
370 # 5 <$> const[IV 10] s
372 # 7 <{> enteriter(next->e last->h redo->8) lKS
374 # g <|> and(other->8) vK/1
375 # 8 <;> nextstate(main 1 -e:1) v
377 # a <$> const[PV "foo "] s
379 # c <2> concat[t4] sK/2
383 # h <2> leaveloop vK/2
384 # i <@> leave[1 ref] vKP/REFC
387 # 2 <;> nextstate(main 2 -e:1) v
389 # 4 <$> const(IV 1) s
390 # 5 <$> const(IV 10) s
392 # 7 <{> enteriter(next->e last->h redo->8) lKS
394 # g <|> and(other->8) vK/1
395 # 8 <;> nextstate(main 1 -e:1) v
397 # a <$> const(PV "foo ") s
399 # c <2> concat[t3] sK/2
403 # h <2> leaveloop vK/2
404 # i <@> leave[1 ref] vKP/REFC
407 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
408 code => sub { print "foo $_" foreach (1..10) },
410 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
411 # 1 <;> nextstate(main 445 optree.t:167) v
412 # 2 <;> nextstate(main 445 optree.t:167) v
414 # 4 <$> const[IV 1] s
415 # 5 <$> const[IV 10] s
417 # 7 <{> enteriter(next->d last->g redo->8) lKS
419 # f <|> and(other->8) K/1
421 # 9 <$> const[PV "foo "] s
423 # b <2> concat[t2] sK/2
427 # g <2> leaveloop K/2
428 # h <1> leavesub[1 ref] K/REFC,1
430 # 1 <;> nextstate(main 447 optree_samples.t:252) v
431 # 2 <;> nextstate(main 447 optree_samples.t:252) v
433 # 4 <$> const(IV 1) s
434 # 5 <$> const(IV 10) s
436 # 7 <{> enteriter(next->d last->g redo->8) lKS
438 # f <|> and(other->8) K/1
440 # 9 <$> const(PV "foo ") s
442 # b <2> concat[t1] sK/2
446 # g <2> leaveloop K/2
447 # h <1> leavesub[1 ref] K/REFC,1
450 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
452 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
453 code => '@foo = grep(!/^\#/, @bar)',
455 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
456 # 1 <;> nextstate(main 496 (eval 20):1) v
460 # 5 <1> rv2av[t4] lKM/1
462 # 7 <|> grepwhile(other->8)[t5] lK
463 # 8 </> match(/"^#"/) s/RTIME
468 # c <1> rv2av[t2] lKRM*/1
469 # d <2> aassign[t6] KS/COMMON
470 # e <1> leavesub[1 ref] K/REFC,1
472 # 1 <;> nextstate(main 496 (eval 20):1) v
476 # 5 <1> rv2av[t2] lKM/1
478 # 7 <|> grepwhile(other->8)[t3] lK
479 # 8 </> match(/"^\\#"/) s/RTIME
484 # c <1> rv2av[t1] lKRM*/1
485 # d <2> aassign[t4] KS/COMMON
486 # e <1> leavesub[1 ref] K/REFC,1
490 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
492 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
493 code => '%h = map { getkey($_) => $_ } @a',
495 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
496 # 1 <;> nextstate(main 501 (eval 22):1) v
500 # 5 <1> rv2av[t8] lKM/1
502 # 7 <|> mapwhile(other->8)[t9] lK
504 # 9 <;> nextstate(main 500 (eval 22):1) v
508 # d <#> gv[*getkey] s/EARLYCV
509 # e <1> entersub[t5] lKS/TARG,1
516 # k <1> rv2hv[t2] lKRM*/1
517 # l <2> aassign[t10] KS/COMMON
518 # m <1> leavesub[1 ref] K/REFC,1
520 # 1 <;> nextstate(main 501 (eval 22):1) v
524 # 5 <1> rv2av[t3] lKM/1
526 # 7 <|> mapwhile(other->8)[t4] lK
528 # 9 <;> nextstate(main 500 (eval 22):1) v
532 # d <$> gv(*getkey) s/EARLYCV
533 # e <1> entersub[t2] lKS/TARG,1
540 # k <1> rv2hv[t1] lKRM*/1
541 # l <2> aassign[t5] KS/COMMON
542 # m <1> leavesub[1 ref] K/REFC,1
545 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
546 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
548 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
549 # 1 <;> nextstate(main 505 (eval 24):1) v
553 # 5 <1> rv2hv[t2] lKRM*/1
554 # 6 <2> aassign[t3] vKS
555 # 7 <;> nextstate(main 506 (eval 24):1) v
558 # a <1> rv2av[t6] sKRM/1
561 # d <{> enteriter(next->o last->r redo->e) lKS
563 # q <|> and(other->e) K/1
564 # e <;> nextstate(main 505 (eval 24):1) v
570 # k <#> gv[*getkey] s/EARLYCV
571 # l <1> entersub[t10] sKS/TARG,1
572 # m <2> helem sKRM*/2
573 # n <2> sassign vKS/2
576 # r <2> leaveloop K/2
577 # s <1> leavesub[1 ref] K/REFC,1
579 # 1 <;> nextstate(main 505 (eval 24):1) v
583 # 5 <1> rv2hv[t1] lKRM*/1
584 # 6 <2> aassign[t2] vKS
585 # 7 <;> nextstate(main 506 (eval 24):1) v
588 # a <1> rv2av[t3] sKRM/1
591 # d <{> enteriter(next->o last->r redo->e) lKS
593 # q <|> and(other->e) K/1
594 # e <;> nextstate(main 505 (eval 24):1) v
600 # k <$> gv(*getkey) s/EARLYCV
601 # l <1> entersub[t4] sKS/TARG,1
602 # m <2> helem sKRM*/2
603 # n <2> sassign vKS/2
606 # r <2> leaveloop K/2
607 # s <1> leavesub[1 ref] K/REFC,1
610 checkOptree ( name => 'map $_+42, 10..20',
611 code => 'map $_+42, 10..20',
613 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
614 # 1 <;> nextstate(main 497 (eval 20):1) v
619 # 6 <|> mapwhile(other->7)[t7] K
621 # 8 <$> const[IV 42] s
624 # a <1> leavesub[1 ref] K/REFC,1
626 # 1 <;> nextstate(main 511 (eval 26):1) v
631 # 6 <|> mapwhile(other->7)[t4] K
633 # 8 <$> const(IV 42) s
636 # a <1> leavesub[1 ref] K/REFC,1
641 checkOptree ( name => '-e use constant j => qq{junk}; print j',
642 prog => 'use constant j => qq{junk}; print j',
644 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
646 # 2 <;> nextstate(main 71 -e:1) v
648 # 4 <$> const[PV "junk"] s
650 # 6 <@> leave[1 ref] vKP/REFC
653 # 2 <;> nextstate(main 71 -e:1) v
655 # 4 <$> const(PV "junk") s
657 # 6 <@> leave[1 ref] vKP/REFC
664 #######################################################################
666 checkOptree ( name => '-exec sub a { print (shift) ? "foo" : "bar" }',
667 code => sub { print (shift) ? "foo" : "bar" },
669 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
670 insert threaded reference here
672 insert non-threaded reference here