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
13 @INC = ('.', '../lib', '../ext/B/t');
19 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
20 print "1..0 # Skip -- Perl configured without B module\n";
23 # require 'test.pl'; # now done by OptreeCheck
26 # import checkOptree(), and %gOpts (containing test state)
27 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
32 require_ok("B::Concise");
35 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
36 prog => q{$a=$b && print q/foo/},
41 my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }];
45 @warnings_todo = (todo =>
46 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
47 . "propagated to 5.8.x")
52 if (((caller 0)[10]||{})->{open}) {
53 @open_todo = (skip => "\$^OPEN is set");
58 checkOptree ( name => 'BEGIN',
63 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
65 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
66 # - <@> lineseq KP ->b
67 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2
68 # 3 <1> require sK/1 ->4
69 # 2 <$> const[PV "warnings.pm"] s/BARE ->3
70 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5
72 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6
73 # a <1> entersub[t1] KS*/TARG,2 ->b
74 # 6 <0> pushmark s ->7
75 # 7 <$> const[PV "warnings"] sM ->8
76 # 8 <$> const[PV "qw"] sM ->9
77 # 9 <$> method_named[PV "import"] ->a
79 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
80 # - <@> lineseq KP ->f
81 # c <;> nextstate(main 2 -e:1) v:{ ->d
82 # e <1> postinc[t3] sK/1 ->f
83 # - <1> ex-rv2sv sKRM/1 ->e
84 # d <#> gvsv[*beg] s ->e
87 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
88 # - <@> lineseq KP ->b
89 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2
90 # 3 <1> require sK/1 ->4
91 # 2 <$> const(PV "warnings.pm") s/BARE ->3
92 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5
94 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6
95 # a <1> entersub[t1] KS*/TARG,2 ->b
96 # 6 <0> pushmark s ->7
97 # 7 <$> const(PV "warnings") sM ->8
98 # 8 <$> const(PV "qw") sM ->9
99 # 9 <$> method_named(PV "import") ->a
101 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
102 # - <@> lineseq KP ->f
103 # c <;> nextstate(main 2 -e:1) v:{ ->d
104 # e <1> postinc[t2] sK/1 ->f
105 # - <1> ex-rv2sv sKRM/1 ->e
106 # d <$> gvsv(*beg) s ->e
110 checkOptree ( name => 'END',
114 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
116 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
117 # - <@> lineseq KP ->4
118 # 1 <;> nextstate(main 5 -e:6) v:{ ->2
119 # 3 <1> postinc[t3] sK/1 ->4
120 # - <1> ex-rv2sv sKRM/1 ->3
121 # 2 <#> gvsv[*end] s ->3
124 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
125 # - <@> lineseq KP ->4
126 # 1 <;> nextstate(main 5 -e:6) v:{ ->2
127 # 3 <1> postinc[t2] sK/1 ->4
128 # - <1> ex-rv2sv sKRM/1 ->3
129 # 2 <$> gvsv(*end) s ->3
133 checkOptree ( name => 'CHECK',
137 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
139 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
140 # - <@> lineseq KP ->4
141 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
142 # 3 <1> postinc[t3] sK/1 ->4
143 # - <1> ex-rv2sv sKRM/1 ->3
144 # 2 <#> gvsv[*chk] s ->3
147 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
148 # - <@> lineseq KP ->4
149 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
150 # 3 <1> postinc[t2] sK/1 ->4
151 # - <1> ex-rv2sv sKRM/1 ->3
152 # 2 <$> gvsv(*chk) s ->3
156 checkOptree ( name => 'INIT',
158 #todo => 'get working',
161 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
163 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
164 # - <@> lineseq KP ->4
165 # 1 <;> nextstate(main 4 -e:5) v:{ ->2
166 # 3 <1> postinc[t3] sK/1 ->4
167 # - <1> ex-rv2sv sKRM/1 ->3
168 # 2 <#> gvsv[*init] s ->3
171 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
172 # - <@> lineseq KP ->4
173 # 1 <;> nextstate(main 4 -e:5) v:{ ->2
174 # 3 <1> postinc[t2] sK/1 ->4
175 # - <1> ex-rv2sv sKRM/1 ->3
176 # 2 <$> gvsv(*init) s ->3
180 checkOptree ( name => 'all of BEGIN END INIT CHECK -exec',
181 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
185 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
187 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
188 # 2 <$> const[PV "warnings.pm"] s/BARE
190 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
191 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
193 # 7 <$> const[PV "warnings"] sM
194 # 8 <$> const[PV "qw"] sM
195 # 9 <$> method_named[PV "unimport"]
196 # a <1> entersub[t1] KS*/TARG,2
197 # b <1> leavesub[1 ref] K/REFC,1
199 # c <;> nextstate(main 2 -e:1) v:{
201 # e <1> postinc[t3] sK/1
202 # f <1> leavesub[1 ref] K/REFC,1
204 # g <;> nextstate(main 5 -e:1) v:{
206 # i <1> postinc[t3] sK/1
207 # j <1> leavesub[1 ref] K/REFC,1
209 # k <;> nextstate(main 4 -e:1) v:{
210 # l <#> gvsv[*init] s
211 # m <1> postinc[t3] sK/1
212 # n <1> leavesub[1 ref] K/REFC,1
214 # o <;> nextstate(main 3 -e:1) v:{
216 # q <1> postinc[t3] sK/1
217 # r <1> leavesub[1 ref] K/REFC,1
220 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
221 # 2 <$> const(PV "warnings.pm") s/BARE
223 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
224 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
226 # 7 <$> const(PV "warnings") sM
227 # 8 <$> const(PV "qw") sM
228 # 9 <$> method_named(PV "unimport")
229 # a <1> entersub[t1] KS*/TARG,2
230 # b <1> leavesub[1 ref] K/REFC,1
232 # c <;> nextstate(main 2 -e:1) v:{
234 # e <1> postinc[t2] sK/1
235 # f <1> leavesub[1 ref] K/REFC,1
237 # g <;> nextstate(main 5 -e:1) v:{
239 # i <1> postinc[t2] sK/1
240 # j <1> leavesub[1 ref] K/REFC,1
242 # k <;> nextstate(main 4 -e:1) v:{
243 # l <$> gvsv(*init) s
244 # m <1> postinc[t2] sK/1
245 # n <1> leavesub[1 ref] K/REFC,1
247 # o <;> nextstate(main 3 -e:1) v:{
249 # q <1> postinc[t2] sK/1
250 # r <1> leavesub[1 ref] K/REFC,1
254 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
258 checkOptree ( name => 'regression test for patch 25352',
259 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
260 prog => 'print q/foo/',
262 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
264 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
265 # 2 <$> const[PV "warnings.pm"] s/BARE
267 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
268 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
270 # 7 <$> const[PV "warnings"] sM
271 # 8 <$> const[PV "qw"] sM
272 # 9 <$> method_named[PV "unimport"]
273 # a <1> entersub[t1] KS*/TARG,2
274 # b <1> leavesub[1 ref] K/REFC,1
277 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
278 # 2 <$> const(PV "warnings.pm") s/BARE
280 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
281 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
283 # 7 <$> const(PV "warnings") sM
284 # 8 <$> const(PV "qw") sM
285 # 9 <$> method_named(PV "unimport")
286 # a <1> entersub[t1] KS*/TARG,2
287 # b <1> leavesub[1 ref] K/REFC,1