5 @INC = ('../lib', '../ext/B/t');
7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
11 if ($Config::Config{'extensions'} !~ /\bData\/Dumper\b/) {
13 "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
17 print "1..0 # Skip -- TODO - provide golden result regexps for 5.8\n";
26 skip "no perlio in this build", 20 unless $Config::Config{useperlio};
28 pass("GENERAL OPTREE EXAMPLES");
30 pass("IF,THEN,ELSE, ?:");
32 checkOptree ( name => '-basic sub {if shift print then,else}',
34 code => sub { if (shift) { print "then" }
37 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
38 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
39 # - <@> lineseq KP ->9
40 # 1 <;> nextstate(main 426 optree.t:16) v ->2
42 # 5 <|> cond_expr(other->6) K/1 ->a
43 # 4 <1> shift sK/1 ->5
44 # 3 <1> rv2av[t2] sKRM/1 ->4
47 # - <0> ex-nextstate v ->6
49 # 6 <0> pushmark s ->7
50 # 7 <$> const[PV "then"] s ->8
53 # b <;> nextstate(main 424 optree.t:17) v ->c
55 # c <0> pushmark s ->d
56 # d <$> const[PV "else"] s ->e
58 # 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
59 # - <@> lineseq KP ->9
60 # 1 <;> nextstate(main 427 optree_samples.t:18) v ->2
62 # 5 <|> cond_expr(other->6) K/1 ->a
63 # 4 <1> shift sK/1 ->5
64 # 3 <1> rv2av[t1] sKRM/1 ->4
67 # - <0> ex-nextstate v ->6
69 # 6 <0> pushmark s ->7
70 # 7 <$> const(PV "then") s ->8
73 # b <;> nextstate(main 425 optree_samples.t:19) v ->c
75 # c <0> pushmark s ->d
76 # d <$> const(PV "else") s ->e
79 checkOptree ( name => '-basic (see above, with my $a = shift)',
81 code => sub { my $a = shift;
82 if ($a) { print "foo" }
85 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
86 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
87 # - <@> lineseq KP ->d
88 # 1 <;> nextstate(main 431 optree.t:68) v ->2
89 # 6 <2> sassign vKS/2 ->7
90 # 4 <1> shift sK/1 ->5
91 # 3 <1> rv2av[t3] sKRM/1 ->4
93 # 5 <0> padsv[$a:431,435] sRM*/LVINTRO ->6
94 # 7 <;> nextstate(main 435 optree.t:69) v ->8
96 # 9 <|> cond_expr(other->a) K/1 ->e
97 # 8 <0> padsv[$a:431,435] s ->9
99 # - <0> ex-nextstate v ->a
101 # a <0> pushmark s ->b
102 # b <$> const[PV "foo"] s ->c
105 # f <;> nextstate(main 433 optree.t:70) v ->g
107 # g <0> pushmark s ->h
108 # h <$> const[PV "bar"] s ->i
110 # d <1> leavesub[1 ref] K/REFC,1 ->(end)
111 # - <@> lineseq KP ->d
112 # 1 <;> nextstate(main 428 optree_samples.t:48) v ->2
113 # 6 <2> sassign vKS/2 ->7
114 # 4 <1> shift sK/1 ->5
115 # 3 <1> rv2av[t2] sKRM/1 ->4
117 # 5 <0> padsv[$a:428,432] sRM*/LVINTRO ->6
118 # 7 <;> nextstate(main 432 optree_samples.t:49) v ->8
120 # 9 <|> cond_expr(other->a) K/1 ->e
121 # 8 <0> padsv[$a:428,432] s ->9
123 # - <0> ex-nextstate v ->a
125 # a <0> pushmark s ->b
126 # b <$> const(PV "foo") s ->c
129 # f <;> nextstate(main 430 optree_samples.t:50) v ->g
131 # g <0> pushmark s ->h
132 # h <$> const(PV "bar") s ->i
135 checkOptree ( name => '-exec sub {if shift print then,else}',
137 code => sub { if (shift) { print "then" }
138 else { print "else" }
140 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
141 # 1 <;> nextstate(main 426 optree.t:16) v
143 # 3 <1> rv2av[t2] sKRM/1
145 # 5 <|> cond_expr(other->6) K/1
147 # 7 <$> const[PV "then"] s
151 # b <;> nextstate(main 424 optree.t:17) v
153 # d <$> const[PV "else"] s
156 # 9 <1> leavesub[1 ref] K/REFC,1
158 # 1 <;> nextstate(main 436 optree_samples.t:123) v
160 # 3 <1> rv2av[t1] sKRM/1
162 # 5 <|> cond_expr(other->6) K/1
164 # 7 <$> const(PV "then") s
168 # b <;> nextstate(main 434 optree_samples.t:124) v
170 # d <$> const(PV "else") s
173 # 9 <1> leavesub[1 ref] K/REFC,1
176 checkOptree ( name => '-exec (see above, with my $a = shift)',
178 code => sub { my $a = shift;
179 if ($a) { print "foo" }
182 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
183 # 1 <;> nextstate(main 423 optree.t:16) v
185 # 3 <1> rv2av[t3] sKRM/1
187 # 5 <0> padsv[$a:423,427] sRM*/LVINTRO
188 # 6 <2> sassign vKS/2
189 # 7 <;> nextstate(main 427 optree.t:17) v
190 # 8 <0> padsv[$a:423,427] s
191 # 9 <|> cond_expr(other->a) K/1
193 # b <$> const[PV "foo"] s
197 # f <;> nextstate(main 425 optree.t:18) v
199 # h <$> const[PV "bar"] s
202 # d <1> leavesub[1 ref] K/REFC,1
204 # 1 <;> nextstate(main 437 optree_samples.t:112) v
206 # 3 <1> rv2av[t2] sKRM/1
208 # 5 <0> padsv[$a:437,441] sRM*/LVINTRO
209 # 6 <2> sassign vKS/2
210 # 7 <;> nextstate(main 441 optree_samples.t:113) v
211 # 8 <0> padsv[$a:437,441] s
212 # 9 <|> cond_expr(other->a) K/1
214 # b <$> const(PV "foo") s
218 # f <;> nextstate(main 439 optree_samples.t:114) v
220 # h <$> const(PV "bar") s
223 # d <1> leavesub[1 ref] K/REFC,1
226 checkOptree ( name => '-exec sub { print (shift) ? "foo" : "bar" }',
227 code => sub { print (shift) ? "foo" : "bar" },
229 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
230 # 1 <;> nextstate(main 428 optree.t:31) v
233 # 4 <1> rv2av[t2] sKRM/1
236 # 7 <|> cond_expr(other->8) K/1
237 # 8 <$> const[PV "foo"] s
239 # a <$> const[PV "bar"] s
240 # 9 <1> leavesub[1 ref] K/REFC,1
242 # 1 <;> nextstate(main 442 optree_samples.t:144) v
245 # 4 <1> rv2av[t1] sKRM/1
248 # 7 <|> cond_expr(other->8) K/1
249 # 8 <$> const(PV "foo") s
251 # a <$> const(PV "bar") s
252 # 9 <1> leavesub[1 ref] K/REFC,1
257 checkOptree ( name => '-exec sub { foreach (1..10) {print "foo $_"} }',
258 code => sub { foreach (1..10) {print "foo $_"} },
260 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
261 # 1 <;> nextstate(main 443 optree.t:158) v
263 # 3 <$> const[IV 1] s
264 # 4 <$> const[IV 10] s
266 # 6 <{> enteriter(next->d last->g redo->7) lKS
268 # f <|> and(other->7) K/1
269 # 7 <;> nextstate(main 442 optree.t:158) v
271 # 9 <$> const[PV "foo "] s
273 # b <2> concat[t4] sK/2
277 # g <2> leaveloop K/2
278 # h <1> leavesub[1 ref] K/REFC,1
280 # 1 <;> nextstate(main 444 optree_samples.t:182) v
282 # 3 <$> const(IV 1) s
283 # 4 <$> const(IV 10) s
285 # 6 <{> enteriter(next->d last->g redo->7) lKS
287 # f <|> and(other->7) K/1
288 # 7 <;> nextstate(main 443 optree_samples.t:182) v
290 # 9 <$> const(PV "foo ") s
292 # b <2> concat[t3] sK/2
296 # g <2> leaveloop K/2
297 # h <1> leavesub[1 ref] K/REFC,1
300 checkOptree ( name => '-basic sub { print "foo $_" foreach (1..10) }',
301 code => sub { print "foo $_" foreach (1..10) },
303 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
304 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
305 # - <@> lineseq KP ->h
306 # 1 <;> nextstate(main 445 optree.t:167) v ->2
307 # 2 <;> nextstate(main 445 optree.t:167) v ->3
308 # g <2> leaveloop K/2 ->h
309 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
310 # - <0> ex-pushmark s ->3
311 # - <1> ex-list lK ->6
312 # 3 <0> pushmark s ->4
313 # 4 <$> const[IV 1] s ->5
314 # 5 <$> const[IV 10] s ->6
317 # f <|> and(other->8) K/1 ->g
319 # - <@> lineseq sK ->-
321 # 8 <0> pushmark s ->9
322 # - <1> ex-stringify sK/1 ->c
323 # - <0> ex-pushmark s ->9
324 # b <2> concat[t2] sK/2 ->c
325 # 9 <$> const[PV "foo "] s ->a
326 # - <1> ex-rv2sv sK/1 ->b
327 # a <#> gvsv[*_] s ->b
328 # d <0> unstack s ->e
330 # h <1> leavesub[1 ref] K/REFC,1 ->(end)
331 # - <@> lineseq KP ->h
332 # 1 <;> nextstate(main 446 optree_samples.t:192) v ->2
333 # 2 <;> nextstate(main 446 optree_samples.t:192) v ->3
334 # g <2> leaveloop K/2 ->h
335 # 7 <{> enteriter(next->d last->g redo->8) lKS ->e
336 # - <0> ex-pushmark s ->3
337 # - <1> ex-list lK ->6
338 # 3 <0> pushmark s ->4
339 # 4 <$> const(IV 1) s ->5
340 # 5 <$> const(IV 10) s ->6
343 # f <|> and(other->8) K/1 ->g
345 # - <@> lineseq sK ->-
347 # 8 <0> pushmark s ->9
348 # - <1> ex-stringify sK/1 ->c
349 # - <0> ex-pushmark s ->9
350 # b <2> concat[t1] sK/2 ->c
351 # 9 <$> const(PV "foo ") s ->a
352 # - <1> ex-rv2sv sK/1 ->b
353 # a <$> gvsv(*_) s ->b
354 # d <0> unstack s ->e
357 checkOptree ( name => '-exec -e foreach (1..10) {print qq{foo $_}}',
358 prog => 'foreach (1..10) {print qq{foo $_}}',
360 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
362 # 2 <;> nextstate(main 2 -e:1) v
364 # 4 <$> const[IV 1] s
365 # 5 <$> const[IV 10] s
367 # 7 <{> enteriter(next->e last->h redo->8) lKS
369 # g <|> and(other->8) vK/1
370 # 8 <;> nextstate(main 1 -e:1) v
372 # a <$> const[PV "foo "] s
374 # c <2> concat[t4] sK/2
378 # h <2> leaveloop vK/2
379 # i <@> leave[1 ref] vKP/REFC
382 # 2 <;> nextstate(main 2 -e:1) v
384 # 4 <$> const(IV 1) s
385 # 5 <$> const(IV 10) s
387 # 7 <{> enteriter(next->e last->h redo->8) lKS
389 # g <|> and(other->8) vK/1
390 # 8 <;> nextstate(main 1 -e:1) v
392 # a <$> const(PV "foo ") s
394 # c <2> concat[t3] sK/2
398 # h <2> leaveloop vK/2
399 # i <@> leave[1 ref] vKP/REFC
402 checkOptree ( name => '-exec sub { print "foo $_" foreach (1..10) }',
403 code => sub { print "foo $_" foreach (1..10) },
405 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
406 # 1 <;> nextstate(main 445 optree.t:167) v
407 # 2 <;> nextstate(main 445 optree.t:167) v
409 # 4 <$> const[IV 1] s
410 # 5 <$> const[IV 10] s
412 # 7 <{> enteriter(next->d last->g redo->8) lKS
414 # f <|> and(other->8) K/1
416 # 9 <$> const[PV "foo "] s
418 # b <2> concat[t2] sK/2
422 # g <2> leaveloop K/2
423 # h <1> leavesub[1 ref] K/REFC,1
425 # 1 <;> nextstate(main 447 optree_samples.t:252) v
426 # 2 <;> nextstate(main 447 optree_samples.t:252) v
428 # 4 <$> const(IV 1) s
429 # 5 <$> const(IV 10) s
431 # 7 <{> enteriter(next->d last->g redo->8) lKS
433 # f <|> and(other->8) K/1
435 # 9 <$> const(PV "foo ") s
437 # b <2> concat[t1] sK/2
441 # g <2> leaveloop K/2
442 # h <1> leavesub[1 ref] K/REFC,1
445 pass("GREP: SAMPLES FROM PERLDOC -F GREP");
447 checkOptree ( name => '@foo = grep(!/^\#/, @bar)',
448 code => '@foo = grep(!/^\#/, @bar)',
450 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
451 # 1 <;> nextstate(main 496 (eval 20):1) v
455 # 5 <1> rv2av[t4] lKM/1
457 # 7 <|> grepwhile(other->8)[t5] lK
458 # 8 </> match(/"^#"/) s/RTIME
463 # c <1> rv2av[t2] lKRM*/1
464 # d <2> aassign[t6] KS/COMMON
465 # e <1> leavesub[1 ref] K/REFC,1
467 # 1 <;> nextstate(main 496 (eval 20):1) v
471 # 5 <1> rv2av[t2] lKM/1
473 # 7 <|> grepwhile(other->8)[t3] lK
474 # 8 </> match(/"^\\#"/) s/RTIME
479 # c <1> rv2av[t1] lKRM*/1
480 # d <2> aassign[t4] KS/COMMON
481 # e <1> leavesub[1 ref] K/REFC,1
485 pass("MAP: SAMPLES FROM PERLDOC -F MAP");
487 checkOptree ( name => '%h = map { getkey($_) => $_ } @a',
488 code => '%h = map { getkey($_) => $_ } @a',
490 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
491 # 1 <;> nextstate(main 501 (eval 22):1) v
495 # 5 <1> rv2av[t8] lKM/1
497 # 7 <|> mapwhile(other->8)[t9] lK
499 # 9 <;> nextstate(main 500 (eval 22):1) v
503 # d <#> gv[*getkey] s/EARLYCV
504 # e <1> entersub[t5] lKS/TARG,1
511 # k <1> rv2hv[t2] lKRM*/1
512 # l <2> aassign[t10] KS/COMMON
513 # m <1> leavesub[1 ref] K/REFC,1
515 # 1 <;> nextstate(main 501 (eval 22):1) v
519 # 5 <1> rv2av[t3] lKM/1
521 # 7 <|> mapwhile(other->8)[t4] lK
523 # 9 <;> nextstate(main 500 (eval 22):1) v
527 # d <$> gv(*getkey) s/EARLYCV
528 # e <1> entersub[t2] lKS/TARG,1
535 # k <1> rv2hv[t1] lKRM*/1
536 # l <2> aassign[t5] KS/COMMON
537 # m <1> leavesub[1 ref] K/REFC,1
540 checkOptree ( name => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
541 code => '%h=(); for $_(@a){$h{getkey($_)} = $_}',
543 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
544 # 1 <;> nextstate(main 505 (eval 24):1) v
548 # 5 <1> rv2hv[t2] lKRM*/1
549 # 6 <2> aassign[t3] vKS
550 # 7 <;> nextstate(main 506 (eval 24):1) v
553 # a <1> rv2av[t6] sKRM/1
556 # d <{> enteriter(next->o last->r redo->e) lKS
558 # q <|> and(other->e) K/1
559 # e <;> nextstate(main 505 (eval 24):1) v
565 # k <#> gv[*getkey] s/EARLYCV
566 # l <1> entersub[t10] sKS/TARG,1
567 # m <2> helem sKRM*/2
568 # n <2> sassign vKS/2
571 # r <2> leaveloop K/2
572 # s <1> leavesub[1 ref] K/REFC,1
574 # 1 <;> nextstate(main 505 (eval 24):1) v
578 # 5 <1> rv2hv[t1] lKRM*/1
579 # 6 <2> aassign[t2] vKS
580 # 7 <;> nextstate(main 506 (eval 24):1) v
583 # a <1> rv2av[t3] sKRM/1
586 # d <{> enteriter(next->o last->r redo->e) lKS
588 # q <|> and(other->e) K/1
589 # e <;> nextstate(main 505 (eval 24):1) v
595 # k <$> gv(*getkey) s/EARLYCV
596 # l <1> entersub[t4] sKS/TARG,1
597 # m <2> helem sKRM*/2
598 # n <2> sassign vKS/2
601 # r <2> leaveloop K/2
602 # s <1> leavesub[1 ref] K/REFC,1
605 checkOptree ( name => 'map $_+42, 10..20',
606 code => 'map $_+42, 10..20',
608 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
609 # 1 <;> nextstate(main 497 (eval 20):1) v
614 # 6 <|> mapwhile(other->7)[t7] K
616 # 8 <$> const[IV 42] s
619 # a <1> leavesub[1 ref] K/REFC,1
621 # 1 <;> nextstate(main 511 (eval 26):1) v
626 # 6 <|> mapwhile(other->7)[t4] K
628 # 8 <$> const(IV 42) s
631 # a <1> leavesub[1 ref] K/REFC,1
636 checkOptree ( name => '-e use constant j => qq{junk}; print j',
637 prog => 'use constant j => qq{junk}; print j',
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