5 @INC = ('../lib', '../ext/B/t');
9 # import checkOptree(), and %gOpts (containing test state)
10 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
15 skip "no perlio in this build", 24 unless $Config::Config{useperlio};
17 $SIG{__WARN__} = sub {
19 $err =~ m/Subroutine re::(un)?install redefined/ and return;
21 #################################
22 pass("CANONICAL B::Concise EXAMPLE");
24 checkOptree ( name => 'canonical example w -basic',
26 code => sub{$a=$b+42},
27 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
28 # 7 <1> leavesub[\d+ refs?] K/REFC,1 ->(end)
29 # - <@> lineseq KP ->7
30 # 1 <;> nextstate(foo bar) v ->2
31 # 6 <2> sassign sKS/2 ->7
32 # 4 <2> add[t\d+] sK/2 ->5
33 # - <1> ex-rv2sv sK/1 ->3
34 # 2 <#> gvsv[*b] s ->3
35 # 3 <$> const[IV 42] s ->4
36 # - <1> ex-rv2sv sKRM*/1 ->6
37 # 5 <#> gvsv[*a] s ->6
39 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
40 # - <@> lineseq KP ->7
41 # 1 <;> nextstate(main 60 optree_concise.t:122) v ->2
42 # 6 <2> sassign sKS/2 ->7
43 # 4 <2> add[t1] sK/2 ->5
44 # - <1> ex-rv2sv sK/1 ->3
45 # 2 <$> gvsv(*b) s ->3
46 # 3 <$> const(IV 42) s ->4
47 # - <1> ex-rv2sv sKRM*/1 ->6
48 # 5 <$> gvsv(*a) s ->6
51 checkOptree ( name => 'canonical example w -exec',
53 code => sub{$a=$b+42},
54 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
56 # 1 <;> nextstate(main 61 optree_concise.t:139) v
58 # 3 <$> const[IV 42] s
62 # 7 <1> leavesub[1 ref] K/REFC,1
65 # 1 <;> nextstate(main 61 optree_concise.t:139) v
67 # 3 <$> const(IV 42) s
71 # 7 <1> leavesub[1 ref] K/REFC,1
74 checkOptree ( name => 'tree reftext is messy cut-paste',
78 #################################
79 pass("B::Concise OPTION TESTS");
81 checkOptree ( name => '-base3 sticky-exec',
83 code => sub{$a=$b+42},
84 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
86 1 <;> dbstate(main 24 optree_concise.t:132) v
92 21 <1> leavesub[2 refs] K/REFC,1
95 # 1 <;> nextstate(main 62 optree_concise.t:161) v
97 # 10 <$> const(IV 42) s
100 # 20 <2> sassign sKS/2
101 # 21 <1> leavesub[1 ref] K/REFC,1
104 checkOptree ( name => 'sticky-base3, -basic over sticky-exec',
106 code => sub{$a=$b+42},
107 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
108 21 <1> leavesub[1 ref] K/REFC,1 ->(end)
109 - <@> lineseq KP ->21
110 1 <;> nextstate(main 32 optree_concise.t:164) v ->2
111 20 <2> sassign sKS/2 ->21
112 11 <2> add[t3] sK/2 ->12
113 - <1> ex-rv2sv sK/1 ->10
114 2 <#> gvsv[*b] s ->10
115 10 <$> const[IV 42] s ->11
116 - <1> ex-rv2sv sKRM*/1 ->20
117 12 <#> gvsv[*a] s ->20
119 # 21 <1> leavesub[1 ref] K/REFC,1 ->(end)
120 # - <@> lineseq KP ->21
121 # 1 <;> nextstate(main 63 optree_concise.t:186) v ->2
122 # 20 <2> sassign sKS/2 ->21
123 # 11 <2> add[t1] sK/2 ->12
124 # - <1> ex-rv2sv sK/1 ->10
125 # 2 <$> gvsv(*b) s ->10
126 # 10 <$> const(IV 42) s ->11
127 # - <1> ex-rv2sv sKRM*/1 ->20
128 # 12 <$> gvsv(*a) s ->20
131 checkOptree ( name => '-base4',
132 bcopts => [qw/ -basic -base4 /],
133 code => sub{$a=$b+42},
134 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
135 13 <1> leavesub[1 ref] K/REFC,1 ->(end)
136 - <@> lineseq KP ->13
137 1 <;> nextstate(main 26 optree_concise.t:145) v ->2
138 12 <2> sassign sKS/2 ->13
139 10 <2> add[t3] sK/2 ->11
140 - <1> ex-rv2sv sK/1 ->3
142 3 <$> const[IV 42] s ->10
143 - <1> ex-rv2sv sKRM*/1 ->12
144 11 <#> gvsv[*a] s ->12
146 # 13 <1> leavesub[1 ref] K/REFC,1 ->(end)
147 # - <@> lineseq KP ->13
148 # 1 <;> nextstate(main 64 optree_concise.t:193) v ->2
149 # 12 <2> sassign sKS/2 ->13
150 # 10 <2> add[t1] sK/2 ->11
151 # - <1> ex-rv2sv sK/1 ->3
152 # 2 <$> gvsv(*b) s ->3
153 # 3 <$> const(IV 42) s ->10
154 # - <1> ex-rv2sv sKRM*/1 ->12
155 # 11 <$> gvsv(*a) s ->12
158 checkOptree ( name => "restore -base36 default",
159 bcopts => [qw/ -basic -base36 /],
162 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
163 3 <1> leavesub[1 ref] K/REFC,1 ->(end)
165 1 <;> nextstate(main 27 optree_concise.t:161) v ->2
166 - <1> ex-rv2sv sK/1 ->-
169 # 3 <1> leavesub[1 ref] K/REFC,1 ->(end)
170 # - <@> lineseq KP ->3
171 # 1 <;> nextstate(main 65 optree_concise.t:210) v ->2
172 # - <1> ex-rv2sv sK/1 ->-
173 # 2 <$> gvsv(*a) s ->3
176 checkOptree ( name => "terse basic",
177 bcopts => [qw/ -basic -terse /],
179 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
180 UNOP (0x82b0918) leavesub [1]
181 LISTOP (0x82b08d8) lineseq
182 COP (0x82b0880) nextstate
183 UNOP (0x82b0860) null [15]
184 PADOP (0x82b0840) gvsv GV (0x82a818c) *a
186 # UNOP (0x8282310) leavesub [1]
187 # LISTOP (0x82822f0) lineseq
188 # COP (0x82822b8) nextstate
189 # UNOP (0x812fc20) null [15]
190 # SVOP (0x812fc00) gvsv GV (0x814692c) *a
193 checkOptree ( name => "sticky-terse exec",
194 bcopts => [qw/ -exec /],
196 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
197 goto UNOP (0x82b0918)
198 COP (0x82b0d70) nextstate
199 PADOP (0x82b0d30) gvsv GV (0x82a818c) *a
200 UNOP (0x82b0e08) leavesub [1]
202 # goto UNOP (0x8282310)
203 # COP (0x82828e0) nextstate
204 # SVOP (0x82828a0) gvsv GV (0x814692c) *a
205 # UNOP (0x8282938) leavesub [1]
208 pass("OPTIONS IN CMDLINE MODE");
210 checkOptree ( name => 'cmdline invoke -basic works',
212 #bcopts => '-basic', # default
213 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
214 # 7 <@> leave[1 ref] vKP/REFC ->(end)
216 # 2 <;> nextstate(main 1 -e:1) v ->3
218 # 3 <0> pushmark s ->4
219 # 5 <1> rv2av[t2] lK/1 ->6
222 # 7 <@> leave[1 ref] vKP/REFC ->(end)
224 # 2 <;> nextstate(main 1 -e:1) v ->3
226 # 3 <0> pushmark s ->4
227 # 5 <1> rv2av[t1] lK/1 ->6
231 checkOptree ( name => 'cmdline invoke -exec works',
234 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
236 2 <;> nextstate(main 1 -e:1) v
241 7 <@> leave[1 ref] vKP/REFC
244 # 2 <;> nextstate(main 1 -e:1) v
247 # 5 <1> rv2av[t1] lK/1
249 # 7 <@> leave[1 ref] vKP/REFC
252 checkOptree ( name => 'cmdline self-strict compile err',
253 prog => 'use strict; sort @a',
254 bcopts => [qw/ -basic -concise -exec /],
255 expect => 'compilation errors',
256 expect_nt => 'compilation errors');
258 checkOptree ( name => 'error at -e line 1',
259 prog => 'our @a; sort @a',
260 bcopts => [qw/ -basic -concise -exec /],
261 expect => 'at -e line 1',
262 expect_nt => 'at -e line 1');
264 checkOptree ( name => 'cmdline -basic -concise -exec works',
265 prog => 'our @a; sort @a',
266 bcopts => [qw/ -basic -concise -exec /],
267 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
269 # 2 <;> nextstate(main 1 -e:1) v
271 # 4 <1> rv2av[t3] vK/OURINTR,1
272 # 5 <;> nextstate(main 2 -e:1) v
275 # 8 <1> rv2av[t5] lK/1
277 # a <@> leave[1 ref] vKP/REFC
280 # 2 <;> nextstate(main 1 -e:1) v
282 # 4 <1> rv2av[t2] vK/OURINTR,1
283 # 5 <;> nextstate(main 2 -e:1) v
286 # 8 <1> rv2av[t3] lK/1
288 # a <@> leave[1 ref] vKP/REFC
292 #################################
293 pass("B::Concise STYLE/CALLBACK TESTS");
295 use B::Concise qw( walk_output add_style set_style_standard add_callback );
297 # new relative style, added by set_up_relative_test()
299 ( "#hyphseq2 (*( (x( ;)x))*)<#classsym> "
300 . "#exname#arg(?([#targarglife])?)~#flags(?(/#privateb)?)(x(;~->#next)x) "
301 . "(x(;~=> #extra)x)\n" # new 'variable' used here
303 , " (*( )*) goto #seq\n"
304 , "(?(<#speq>)?)#exname#arg(?([#targarglife])?)"
305 #. "(x(;~=> #extra)x)\n" # new 'variable' used here
308 sub set_up_relative_test {
309 # add a new style, and a callback which adds an 'extra' property
311 add_style ( "relative" => @stylespec );
312 #set_style_standard ( "relative" );
316 my ($h, $op, $format, $level, $style) = @_;
318 # callback marks up const ops
319 $h->{arg} .= ' CALLBACK' if $h->{name} eq 'const';
322 # 2 style specific behaviors
323 if ($style eq 'relative') {
324 $h->{extra} = 'RELATIVE';
325 $h->{arg} .= ' RELATIVE' if $h->{name} eq 'leavesub';
327 elsif ($style eq 'scope') {
328 # supress printout entirely
329 $$format="" unless grep { $h->{name} eq $_ } @scopeops;
334 #################################
335 set_up_relative_test();
336 pass("set_up_relative_test, new callback installed");
338 checkOptree ( name => 'callback used, independent of style',
339 bcopts => [qw/ -concise -exec /],
340 code => sub{$a=$b+42},
341 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
343 1 <;> nextstate(main 76 optree_concise.t:337) v
345 3 <$> const[IV 42] CALLBACK s
349 7 <1> leavesub[1 ref] K/REFC,1
351 # 1 <;> nextstate(main 455 optree_concise.t:328) v
353 # 3 <$> const(IV 42) CALLBACK s
356 # 6 <2> sassign sKS/2
357 # 7 <1> leavesub[1 ref] K/REFC,1
360 checkOptree ( name => "new 'relative' style, -exec mode",
361 bcopts => [qw/ -basic -relative /],
362 code => sub{$a=$b+42},
365 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
366 7 <1> leavesub RELATIVE[1 ref] K ->(end) => RELATIVE
367 - <@> lineseq KP ->7 => RELATIVE
368 1 <;> nextstate(main 49 optree_concise.t:309) v ->2 => RELATIVE
369 6 <2> sassign sKS ->7 => RELATIVE
370 4 <2> add[t3] sK ->5 => RELATIVE
371 - <1> ex-rv2sv sK ->3 => RELATIVE
372 2 <#> gvsv[*b] s ->3 => RELATIVE
373 3 <$> const[IV 42] CALLBACK s ->4 => RELATIVE
374 - <1> ex-rv2sv sKRM* ->6 => RELATIVE
375 5 <#> gvsv[*a] s ->6 => RELATIVE
377 # 7 <1> leavesub RELATIVE[1 ref] K ->(end) => RELATIVE
378 # - <@> lineseq KP ->7 => RELATIVE
379 # 1 <;> nextstate(main 77 optree_concise.t:353) v ->2 => RELATIVE
380 # 6 <2> sassign sKS ->7 => RELATIVE
381 # 4 <2> add[t1] sK ->5 => RELATIVE
382 # - <1> ex-rv2sv sK ->3 => RELATIVE
383 # 2 <$> gvsv(*b) s ->3 => RELATIVE
384 # 3 <$> const(IV 42) CALLBACK s ->4 => RELATIVE
385 # - <1> ex-rv2sv sKRM* ->6 => RELATIVE
386 # 5 <$> gvsv(*a) s ->6 => RELATIVE
389 checkOptree ( name => "both -exec -relative",
390 bcopts => [qw/ -exec -relative /],
391 code => sub{$a=$b+42},
393 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
395 1 <;> nextstate(main 50 optree_concise.t:326) v
397 3 <$> const[IV 42] CALLBACK s
401 7 <1> leavesub RELATIVE[1 ref] K
403 # 1 <;> nextstate(main 78 optree_concise.t:371) v
405 # 3 <$> const(IV 42) CALLBACK s
409 # 7 <1> leavesub RELATIVE[1 ref] K
412 #################################
414 @scopeops = qw( leavesub enter leave nextstate );
416 ( 'scope' # concise copy
417 , "#hyphseq2 (*( (x( ;)x))*)<#classsym> "
418 . "#exname#arg(?([#targarglife])?)~#flags(?(/#private)?)(x(;~->#next)x) "
419 , " (*( )*) goto #seq\n"
420 , "(?(<#seq>)?)#exname#arg(?([#targarglife])?)"
423 checkOptree ( name => "both -exec -scope",
424 bcopts => [qw/ -exec -scope /],
425 code => sub{$a=$b+42},
426 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
428 1 <;> nextstate(main 50 optree_concise.t:337) v
429 7 <1> leavesub[1 ref] K/REFC,1
432 1 <;> nextstate(main 75 optree_concise.t:396) v
433 7 <1> leavesub[1 ref] K/REFC,1
437 checkOptree ( name => "both -basic -scope",
438 bcopts => [qw/ -basic -scope /],
439 code => sub{$a=$b+42},
440 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
441 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
442 1 <;> nextstate(main 51 optree_concise.t:347) v ->2
444 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
445 1 <;> nextstate(main 76 optree_concise.t:407) v ->2