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 !!!!!!
30 plan tests => 7 + ($] > 5.009 ? 1 : 0);
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',
54 strip_open_hints => 1,
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',
105 strip_open_hints => 1,
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',
128 strip_open_hints => 1,
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
148 checkOptree ( name => 'UNITCHECK',
149 bcopts=> 'UNITCHECK',
151 strip_open_hints => 1,
152 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
154 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
155 # - <@> lineseq KP ->4
156 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
157 # 3 <1> postinc[t3] sK/1 ->4
158 # - <1> ex-rv2sv sKRM/1 ->3
159 # 2 <#> gvsv[*uc] s ->3
162 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
163 # - <@> lineseq KP ->4
164 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
165 # 3 <1> postinc[t2] sK/1 ->4
166 # - <1> ex-rv2sv sKRM/1 ->3
167 # 2 <$> gvsv(*uc) s ->3
171 checkOptree ( name => 'INIT',
173 #todo => 'get working',
175 strip_open_hints => 1,
176 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
178 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
179 # - <@> lineseq KP ->4
180 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
181 # 3 <1> postinc[t3] sK/1 ->4
182 # - <1> ex-rv2sv sKRM/1 ->3
183 # 2 <#> gvsv[*init] s ->3
186 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
187 # - <@> lineseq KP ->4
188 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
189 # 3 <1> postinc[t2] sK/1 ->4
190 # - <1> ex-rv2sv sKRM/1 ->3
191 # 2 <$> gvsv(*init) s ->3
195 checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
196 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
199 strip_open_hints => 1,
200 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
202 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
203 # 2 <$> const[PV "warnings.pm"] s/BARE
205 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
206 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
208 # 7 <$> const[PV "warnings"] sM
209 # 8 <$> const[PV "qw"] sM
210 # 9 <$> method_named[PV "unimport"]
211 # a <1> entersub[t1] KS*/TARG,2
212 # b <1> leavesub[1 ref] K/REFC,1
214 # c <;> nextstate(main 2 -e:1) v:>,<,%,{
216 # e <1> postinc[t3] sK/1
217 # f <1> leavesub[1 ref] K/REFC,1
219 # g <;> nextstate(main 5 -e:1) v:>,<,%,{
221 # i <1> postinc[t3] sK/1
222 # j <1> leavesub[1 ref] K/REFC,1
224 # k <;> nextstate(main 4 -e:1) v:>,<,%,{
225 # l <#> gvsv[*init] s
226 # m <1> postinc[t3] sK/1
227 # n <1> leavesub[1 ref] K/REFC,1
229 # o <;> nextstate(main 3 -e:1) v:>,<,%,{
231 # q <1> postinc[t3] sK/1
232 # r <1> leavesub[1 ref] K/REFC,1
234 # s <;> nextstate(main 6 -e:1) v:>,<,%,{
236 # u <1> postinc[t3] sK/1
237 # v <1> leavesub[1 ref] K/REFC,1
240 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
241 # 2 <$> const(PV "warnings.pm") s/BARE
243 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
244 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
246 # 7 <$> const(PV "warnings") sM
247 # 8 <$> const(PV "qw") sM
248 # 9 <$> method_named(PV "unimport")
249 # a <1> entersub[t1] KS*/TARG,2
250 # b <1> leavesub[1 ref] K/REFC,1
252 # c <;> nextstate(main 2 -e:1) v:>,<,%,{
254 # e <1> postinc[t2] sK/1
255 # f <1> leavesub[1 ref] K/REFC,1
257 # g <;> nextstate(main 5 -e:1) v:>,<,%,{
259 # i <1> postinc[t2] sK/1
260 # j <1> leavesub[1 ref] K/REFC,1
262 # k <;> nextstate(main 4 -e:1) v:>,<,%,{
263 # l <$> gvsv(*init) s
264 # m <1> postinc[t2] sK/1
265 # n <1> leavesub[1 ref] K/REFC,1
267 # o <;> nextstate(main 3 -e:1) v:>,<,%,{
269 # q <1> postinc[t2] sK/1
270 # r <1> leavesub[1 ref] K/REFC,1
272 # s <;> nextstate(main 6 -e:1) v:>,<,%,{
274 # u <1> postinc[t2] sK/1
275 # v <1> leavesub[1 ref] K/REFC,1
279 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
283 checkOptree ( name => 'regression test for patch 25352',
284 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
285 prog => 'print q/foo/',
287 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
289 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
290 # 2 <$> const[PV "warnings.pm"] s/BARE
292 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
293 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
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
302 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
303 # 2 <$> const(PV "warnings.pm") s/BARE
305 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
306 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
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