Re: perlfunc.pod/split; concerning trailing fields
[p5sagit/p5-mst-13.2.git] / ext / B / t / optree_specials.t
CommitLineData
cc02ea56 1#!./perl
2
09e96b99 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
cc02ea56 10BEGIN {
5638aaac 11 if ($ENV{PERL_CORE}){
12 chdir('t') if -d 't';
13 @INC = ('.', '../lib', '../ext/B/t');
14 } else {
15 unshift @INC, 't';
16 push @INC, "../../t";
17 }
9cd8f857 18 require Config;
19 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
20 print "1..0 # Skip -- Perl configured without B module\n";
21 exit 0;
22 }
19e169bf 23 # require 'test.pl'; # now done by OptreeCheck
cc02ea56 24}
25
26# import checkOptree(), and %gOpts (containing test state)
27use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
28use Config;
29
e412117e 30plan tests => 7 + ($] > 5.009 ? 1 : 0);
cc02ea56 31
32require_ok("B::Concise");
33
34my $out = runperl(
35 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
36 prog => q{$a=$b && print q/foo/},
37 stderr => 1 );
38
39#print "out:$out\n";
40
676456c2 41my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
cc02ea56 42
43
b8443148 44my @warnings_todo;
45@warnings_todo = (todo =>
46 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
47 . "propagated to 5.8.x")
48 if $] < 5.009;
49
cc02ea56 50checkOptree ( name => 'BEGIN',
51 bcopts => 'BEGIN',
52 prog => $src,
b8443148 53 @warnings_todo,
be2b1c74 54 strip_open_hints => 1,
cc02ea56 55 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
56# BEGIN 1:
57# b <1> leavesub[1 ref] K/REFC,1 ->(end)
58# - <@> lineseq KP ->b
d5ec2987 59# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2
cc02ea56 60# 3 <1> require sK/1 ->4
09e96b99 61# 2 <$> const[PV "warnings.pm"] s/BARE ->3
d5ec2987 62# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5
cc02ea56 63# - <@> lineseq K ->-
d5ec2987 64# 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6
cc02ea56 65# a <1> entersub[t1] KS*/TARG,2 ->b
66# 6 <0> pushmark s ->7
09e96b99 67# 7 <$> const[PV "warnings"] sM ->8
68# 8 <$> const[PV "qw"] sM ->9
427d62a4 69# 9 <$> method_named[PV "import"] ->a
cc02ea56 70# BEGIN 2:
09e96b99 71# f <1> leavesub[1 ref] K/REFC,1 ->(end)
72# - <@> lineseq KP ->f
be2b1c74 73# c <;> nextstate(main 2 -e:1) v:>,<,%,{ ->d
09e96b99 74# e <1> postinc[t3] sK/1 ->f
75# - <1> ex-rv2sv sKRM/1 ->e
76# d <#> gvsv[*beg] s ->e
cc02ea56 77EOT_EOT
78# BEGIN 1:
79# b <1> leavesub[1 ref] K/REFC,1 ->(end)
80# - <@> lineseq KP ->b
d5ec2987 81# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2
cc02ea56 82# 3 <1> require sK/1 ->4
09e96b99 83# 2 <$> const(PV "warnings.pm") s/BARE ->3
d5ec2987 84# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5
cc02ea56 85# - <@> lineseq K ->-
d5ec2987 86# 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6
cc02ea56 87# a <1> entersub[t1] KS*/TARG,2 ->b
88# 6 <0> pushmark s ->7
09e96b99 89# 7 <$> const(PV "warnings") sM ->8
90# 8 <$> const(PV "qw") sM ->9
427d62a4 91# 9 <$> method_named(PV "import") ->a
cc02ea56 92# BEGIN 2:
09e96b99 93# f <1> leavesub[1 ref] K/REFC,1 ->(end)
94# - <@> lineseq KP ->f
be2b1c74 95# c <;> nextstate(main 2 -e:1) v:>,<,%,{ ->d
09e96b99 96# e <1> postinc[t2] sK/1 ->f
97# - <1> ex-rv2sv sKRM/1 ->e
98# d <$> gvsv(*beg) s ->e
cc02ea56 99EONT_EONT
100
101
102checkOptree ( name => 'END',
103 bcopts => 'END',
104 prog => $src,
be2b1c74 105 strip_open_hints => 1,
cc02ea56 106 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
107# END 1:
108# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
109# - <@> lineseq KP ->4
be2b1c74 110# 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
cc02ea56 111# 3 <1> postinc[t3] sK/1 ->4
112# - <1> ex-rv2sv sKRM/1 ->3
113# 2 <#> gvsv[*end] s ->3
114EOT_EOT
115# END 1:
116# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
117# - <@> lineseq KP ->4
be2b1c74 118# 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
cc02ea56 119# 3 <1> postinc[t2] sK/1 ->4
120# - <1> ex-rv2sv sKRM/1 ->3
121# 2 <$> gvsv(*end) s ->3
122EONT_EONT
123
124
125checkOptree ( name => 'CHECK',
126 bcopts => 'CHECK',
127 prog => $src,
be2b1c74 128 strip_open_hints => 1,
cc02ea56 129 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
130# CHECK 1:
131# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
132# - <@> lineseq KP ->4
be2b1c74 133# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
cc02ea56 134# 3 <1> postinc[t3] sK/1 ->4
135# - <1> ex-rv2sv sKRM/1 ->3
136# 2 <#> gvsv[*chk] s ->3
137EOT_EOT
138# CHECK 1:
139# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
140# - <@> lineseq KP ->4
be2b1c74 141# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
cc02ea56 142# 3 <1> postinc[t2] sK/1 ->4
143# - <1> ex-rv2sv sKRM/1 ->3
144# 2 <$> gvsv(*chk) s ->3
145EONT_EONT
146
e412117e 147if ($] >= 5.009) {
148 checkOptree ( name => 'UNITCHECK',
149 bcopts=> 'UNITCHECK',
150 prog => $src,
151 strip_open_hints => 1,
152 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
676456c2 153# UNITCHECK 1:
154# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
155# - <@> lineseq KP ->4
be2b1c74 156# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
676456c2 157# 3 <1> postinc[t3] sK/1 ->4
158# - <1> ex-rv2sv sKRM/1 ->3
159# 2 <#> gvsv[*uc] s ->3
160EOT_EOT
161# UNITCHECK 1:
162# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
163# - <@> lineseq KP ->4
be2b1c74 164# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
676456c2 165# 3 <1> postinc[t2] sK/1 ->4
166# - <1> ex-rv2sv sKRM/1 ->3
167# 2 <$> gvsv(*uc) s ->3
168EONT_EONT
e412117e 169}
cc02ea56 170
171checkOptree ( name => 'INIT',
172 bcopts => 'INIT',
173 #todo => 'get working',
174 prog => $src,
be2b1c74 175 strip_open_hints => 1,
cc02ea56 176 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
177# INIT 1:
178# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
179# - <@> lineseq KP ->4
be2b1c74 180# 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
cc02ea56 181# 3 <1> postinc[t3] sK/1 ->4
182# - <1> ex-rv2sv sKRM/1 ->3
183# 2 <#> gvsv[*init] s ->3
184EOT_EOT
185# INIT 1:
186# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
187# - <@> lineseq KP ->4
be2b1c74 188# 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
cc02ea56 189# 3 <1> postinc[t2] sK/1 ->4
190# - <1> ex-rv2sv sKRM/1 ->3
191# 2 <$> gvsv(*init) s ->3
192EONT_EONT
193
194
676456c2 195checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
196 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
cc02ea56 197 prog => $src,
b8443148 198 @warnings_todo,
be2b1c74 199 strip_open_hints => 1,
cc02ea56 200 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
201# BEGIN 1:
d5ec2987 202# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
09e96b99 203# 2 <$> const[PV "warnings.pm"] s/BARE
cc02ea56 204# 3 <1> require sK/1
d5ec2987 205# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
206# 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
cc02ea56 207# 6 <0> pushmark s
09e96b99 208# 7 <$> const[PV "warnings"] sM
209# 8 <$> const[PV "qw"] sM
427d62a4 210# 9 <$> method_named[PV "unimport"]
cc02ea56 211# a <1> entersub[t1] KS*/TARG,2
212# b <1> leavesub[1 ref] K/REFC,1
213# BEGIN 2:
be2b1c74 214# c <;> nextstate(main 2 -e:1) v:>,<,%,{
09e96b99 215# d <#> gvsv[*beg] s
216# e <1> postinc[t3] sK/1
217# f <1> leavesub[1 ref] K/REFC,1
cc02ea56 218# END 1:
be2b1c74 219# g <;> nextstate(main 5 -e:1) v:>,<,%,{
09e96b99 220# h <#> gvsv[*end] s
221# i <1> postinc[t3] sK/1
222# j <1> leavesub[1 ref] K/REFC,1
cc02ea56 223# INIT 1:
be2b1c74 224# k <;> nextstate(main 4 -e:1) v:>,<,%,{
09e96b99 225# l <#> gvsv[*init] s
226# m <1> postinc[t3] sK/1
227# n <1> leavesub[1 ref] K/REFC,1
cc02ea56 228# CHECK 1:
be2b1c74 229# o <;> nextstate(main 3 -e:1) v:>,<,%,{
09e96b99 230# p <#> gvsv[*chk] s
231# q <1> postinc[t3] sK/1
232# r <1> leavesub[1 ref] K/REFC,1
676456c2 233# UNITCHECK 1:
be2b1c74 234# s <;> nextstate(main 6 -e:1) v:>,<,%,{
676456c2 235# t <#> gvsv[*uc] s
236# u <1> postinc[t3] sK/1
237# v <1> leavesub[1 ref] K/REFC,1
cc02ea56 238EOT_EOT
239# BEGIN 1:
d5ec2987 240# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
09e96b99 241# 2 <$> const(PV "warnings.pm") s/BARE
cc02ea56 242# 3 <1> require sK/1
d5ec2987 243# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
244# 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
cc02ea56 245# 6 <0> pushmark s
09e96b99 246# 7 <$> const(PV "warnings") sM
247# 8 <$> const(PV "qw") sM
427d62a4 248# 9 <$> method_named(PV "unimport")
cc02ea56 249# a <1> entersub[t1] KS*/TARG,2
250# b <1> leavesub[1 ref] K/REFC,1
251# BEGIN 2:
be2b1c74 252# c <;> nextstate(main 2 -e:1) v:>,<,%,{
09e96b99 253# d <$> gvsv(*beg) s
254# e <1> postinc[t2] sK/1
255# f <1> leavesub[1 ref] K/REFC,1
cc02ea56 256# END 1:
be2b1c74 257# g <;> nextstate(main 5 -e:1) v:>,<,%,{
09e96b99 258# h <$> gvsv(*end) s
259# i <1> postinc[t2] sK/1
260# j <1> leavesub[1 ref] K/REFC,1
cc02ea56 261# INIT 1:
be2b1c74 262# k <;> nextstate(main 4 -e:1) v:>,<,%,{
09e96b99 263# l <$> gvsv(*init) s
264# m <1> postinc[t2] sK/1
265# n <1> leavesub[1 ref] K/REFC,1
cc02ea56 266# CHECK 1:
be2b1c74 267# o <;> nextstate(main 3 -e:1) v:>,<,%,{
09e96b99 268# p <$> gvsv(*chk) s
269# q <1> postinc[t2] sK/1
270# r <1> leavesub[1 ref] K/REFC,1
676456c2 271# UNITCHECK 1:
be2b1c74 272# s <;> nextstate(main 6 -e:1) v:>,<,%,{
676456c2 273# t <$> gvsv(*uc) s
274# u <1> postinc[t2] sK/1
275# v <1> leavesub[1 ref] K/REFC,1
cc02ea56 276EONT_EONT
2c394315 277
278
279# perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
280
281
282
283checkOptree ( name => 'regression test for patch 25352',
284 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
285 prog => 'print q/foo/',
286 @warnings_todo,
287 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
288# BEGIN 1:
d5ec2987 289# 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
2c394315 290# 2 <$> const[PV "warnings.pm"] s/BARE
291# 3 <1> require sK/1
d5ec2987 292# 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
293# 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
2c394315 294# 6 <0> pushmark s
295# 7 <$> const[PV "warnings"] sM
296# 8 <$> const[PV "qw"] sM
297# 9 <$> method_named[PV "unimport"]
298# a <1> entersub[t1] KS*/TARG,2
299# b <1> leavesub[1 ref] K/REFC,1
300EOT_EOT
301# BEGIN 1:
d5ec2987 302# 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
2c394315 303# 2 <$> const(PV "warnings.pm") s/BARE
304# 3 <1> require sK/1
d5ec2987 305# 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
306# 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
2c394315 307# 6 <0> pushmark s
308# 7 <$> const(PV "warnings") sM
309# 8 <$> const(PV "qw") sM
310# 9 <$> method_named(PV "unimport")
311# a <1> entersub[t1] KS*/TARG,2
312# b <1> leavesub[1 ref] K/REFC,1
313EONT_EONT