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, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
45 @warnings_todo = (todo =>
46 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not"
47 . "propagated to 5.8.x")
50 checkOptree ( name => 'BEGIN',
55 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
57 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
58 # - <@> lineseq KP ->b
59 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2
60 # 3 <1> require sK/1 ->4
61 # 2 <$> const[PV "warnings.pm"] s/BARE ->3
62 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5
64 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6
65 # a <1> entersub[t1] KS*/TARG,2 ->b
66 # 6 <0> pushmark s ->7
67 # 7 <$> const[PV "warnings"] sM ->8
68 # 8 <$> const[PV "qw"] sM ->9
69 # 9 <$> method_named[PV "import"] ->a
71 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
72 # - <@> lineseq KP ->f
73 # c <;> nextstate(main 2 -e:1) v:{ ->d
74 # e <1> postinc[t3] sK/1 ->f
75 # - <1> ex-rv2sv sKRM/1 ->e
76 # d <#> gvsv[*beg] s ->e
79 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
80 # - <@> lineseq KP ->b
81 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2
82 # 3 <1> require sK/1 ->4
83 # 2 <$> const(PV "warnings.pm") s/BARE ->3
84 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5
86 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6
87 # a <1> entersub[t1] KS*/TARG,2 ->b
88 # 6 <0> pushmark s ->7
89 # 7 <$> const(PV "warnings") sM ->8
90 # 8 <$> const(PV "qw") sM ->9
91 # 9 <$> method_named(PV "import") ->a
93 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
94 # - <@> lineseq KP ->f
95 # c <;> nextstate(main 2 -e:1) v:{ ->d
96 # e <1> postinc[t2] sK/1 ->f
97 # - <1> ex-rv2sv sKRM/1 ->e
98 # d <$> gvsv(*beg) s ->e
102 checkOptree ( name => 'END',
106 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
108 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
109 # - <@> lineseq KP ->4
110 # 1 <;> nextstate(main 5 -e:6) v:{ ->2
111 # 3 <1> postinc[t3] sK/1 ->4
112 # - <1> ex-rv2sv sKRM/1 ->3
113 # 2 <#> gvsv[*end] s ->3
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[t2] sK/1 ->4
120 # - <1> ex-rv2sv sKRM/1 ->3
121 # 2 <$> gvsv(*end) s ->3
125 checkOptree ( name => 'CHECK',
129 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
131 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
132 # - <@> lineseq KP ->4
133 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
134 # 3 <1> postinc[t3] sK/1 ->4
135 # - <1> ex-rv2sv sKRM/1 ->3
136 # 2 <#> gvsv[*chk] s ->3
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[t2] sK/1 ->4
143 # - <1> ex-rv2sv sKRM/1 ->3
144 # 2 <$> gvsv(*chk) s ->3
147 checkOptree ( name => 'UNITCHECK',
148 bcopts => 'UNITCHECK',
151 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
153 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
154 # - <@> lineseq KP ->4
155 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
156 # 3 <1> postinc[t3] sK/1 ->4
157 # - <1> ex-rv2sv sKRM/1 ->3
158 # 2 <#> gvsv[*uc] s ->3
161 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
162 # - <@> lineseq KP ->4
163 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
164 # 3 <1> postinc[t2] sK/1 ->4
165 # - <1> ex-rv2sv sKRM/1 ->3
166 # 2 <$> gvsv(*uc) s ->3
170 checkOptree ( name => 'INIT',
172 #todo => 'get working',
175 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
177 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
178 # - <@> lineseq KP ->4
179 # 1 <;> nextstate(main 4 -e:5) v:{ ->2
180 # 3 <1> postinc[t3] sK/1 ->4
181 # - <1> ex-rv2sv sKRM/1 ->3
182 # 2 <#> gvsv[*init] s ->3
185 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
186 # - <@> lineseq KP ->4
187 # 1 <;> nextstate(main 4 -e:5) v:{ ->2
188 # 3 <1> postinc[t2] sK/1 ->4
189 # - <1> ex-rv2sv sKRM/1 ->3
190 # 2 <$> gvsv(*init) s ->3
194 checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
195 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
199 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
201 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
202 # 2 <$> const[PV "warnings.pm"] s/BARE
204 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
205 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
207 # 7 <$> const[PV "warnings"] sM
208 # 8 <$> const[PV "qw"] sM
209 # 9 <$> method_named[PV "unimport"]
210 # a <1> entersub[t1] KS*/TARG,2
211 # b <1> leavesub[1 ref] K/REFC,1
213 # c <;> nextstate(main 2 -e:1) v:{
215 # e <1> postinc[t3] sK/1
216 # f <1> leavesub[1 ref] K/REFC,1
218 # g <;> nextstate(main 5 -e:1) v:{
220 # i <1> postinc[t3] sK/1
221 # j <1> leavesub[1 ref] K/REFC,1
223 # k <;> nextstate(main 4 -e:1) v:{
224 # l <#> gvsv[*init] s
225 # m <1> postinc[t3] sK/1
226 # n <1> leavesub[1 ref] K/REFC,1
228 # o <;> nextstate(main 3 -e:1) v:{
230 # q <1> postinc[t3] sK/1
231 # r <1> leavesub[1 ref] K/REFC,1
233 # s <;> nextstate(main 6 -e:1) v:{
235 # u <1> postinc[t3] sK/1
236 # v <1> leavesub[1 ref] K/REFC,1
239 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
240 # 2 <$> const(PV "warnings.pm") s/BARE
242 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
243 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
245 # 7 <$> const(PV "warnings") sM
246 # 8 <$> const(PV "qw") sM
247 # 9 <$> method_named(PV "unimport")
248 # a <1> entersub[t1] KS*/TARG,2
249 # b <1> leavesub[1 ref] K/REFC,1
251 # c <;> nextstate(main 2 -e:1) v:{
253 # e <1> postinc[t2] sK/1
254 # f <1> leavesub[1 ref] K/REFC,1
256 # g <;> nextstate(main 5 -e:1) v:{
258 # i <1> postinc[t2] sK/1
259 # j <1> leavesub[1 ref] K/REFC,1
261 # k <;> nextstate(main 4 -e:1) v:{
262 # l <$> gvsv(*init) s
263 # m <1> postinc[t2] sK/1
264 # n <1> leavesub[1 ref] K/REFC,1
266 # o <;> nextstate(main 3 -e:1) v:{
268 # q <1> postinc[t2] sK/1
269 # r <1> leavesub[1 ref] K/REFC,1
271 # s <;> nextstate(main 6 -e:1) v:{
273 # u <1> postinc[t2] sK/1
274 # v <1> leavesub[1 ref] K/REFC,1
278 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
282 checkOptree ( name => 'regression test for patch 25352',
283 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
284 prog => 'print q/foo/',
286 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
288 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
289 # 2 <$> const[PV "warnings.pm"] s/BARE
291 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
292 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
294 # 7 <$> const[PV "warnings"] sM
295 # 8 <$> const[PV "qw"] sM
296 # 9 <$> method_named[PV "unimport"]
297 # a <1> entersub[t1] KS*/TARG,2
298 # b <1> leavesub[1 ref] K/REFC,1
301 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
302 # 2 <$> const(PV "warnings.pm") s/BARE
304 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
305 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
307 # 7 <$> const(PV "warnings") sM
308 # 8 <$> const(PV "qw") sM
309 # 9 <$> method_named(PV "unimport")
310 # a <1> entersub[t1] KS*/TARG,2
311 # b <1> leavesub[1 ref] K/REFC,1