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")
51 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',
105 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
107 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
108 # - <@> lineseq KP ->4
109 # 1 <;> nextstate(main 5 -e:6) v:{ ->2
110 # 3 <1> postinc[t3] sK/1 ->4
111 # - <1> ex-rv2sv sKRM/1 ->3
112 # 2 <#> gvsv[*end] s ->3
115 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
116 # - <@> lineseq KP ->4
117 # 1 <;> nextstate(main 5 -e:6) v:{ ->2
118 # 3 <1> postinc[t2] sK/1 ->4
119 # - <1> ex-rv2sv sKRM/1 ->3
120 # 2 <$> gvsv(*end) s ->3
124 checkOptree ( name => 'CHECK',
127 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
129 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
130 # - <@> lineseq KP ->4
131 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
132 # 3 <1> postinc[t3] sK/1 ->4
133 # - <1> ex-rv2sv sKRM/1 ->3
134 # 2 <#> gvsv[*chk] s ->3
137 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
138 # - <@> lineseq KP ->4
139 # 1 <;> nextstate(main 3 -e:4) v:{ ->2
140 # 3 <1> postinc[t2] sK/1 ->4
141 # - <1> ex-rv2sv sKRM/1 ->3
142 # 2 <$> gvsv(*chk) s ->3
146 checkOptree ( name => 'INIT',
148 #todo => 'get working',
150 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
152 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
153 # - <@> lineseq KP ->4
154 # 1 <;> nextstate(main 4 -e:5) v:{ ->2
155 # 3 <1> postinc[t3] sK/1 ->4
156 # - <1> ex-rv2sv sKRM/1 ->3
157 # 2 <#> gvsv[*init] s ->3
160 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
161 # - <@> lineseq KP ->4
162 # 1 <;> nextstate(main 4 -e:5) v:{ ->2
163 # 3 <1> postinc[t2] sK/1 ->4
164 # - <1> ex-rv2sv sKRM/1 ->3
165 # 2 <$> gvsv(*init) s ->3
169 checkOptree ( name => 'all of BEGIN END INIT CHECK -exec',
170 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
173 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
175 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
176 # 2 <$> const[PV "warnings.pm"] s/BARE
178 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
179 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
181 # 7 <$> const[PV "warnings"] sM
182 # 8 <$> const[PV "qw"] sM
183 # 9 <$> method_named[PV "unimport"]
184 # a <1> entersub[t1] KS*/TARG,2
185 # b <1> leavesub[1 ref] K/REFC,1
187 # c <;> nextstate(main 2 -e:1) v:{
189 # e <1> postinc[t3] sK/1
190 # f <1> leavesub[1 ref] K/REFC,1
192 # g <;> nextstate(main 5 -e:1) v:{
194 # i <1> postinc[t3] sK/1
195 # j <1> leavesub[1 ref] K/REFC,1
197 # k <;> nextstate(main 4 -e:1) v:{
198 # l <#> gvsv[*init] s
199 # m <1> postinc[t3] sK/1
200 # n <1> leavesub[1 ref] K/REFC,1
202 # o <;> nextstate(main 3 -e:1) v:{
204 # q <1> postinc[t3] sK/1
205 # r <1> leavesub[1 ref] K/REFC,1
208 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
209 # 2 <$> const(PV "warnings.pm") s/BARE
211 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$
212 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$
214 # 7 <$> const(PV "warnings") sM
215 # 8 <$> const(PV "qw") sM
216 # 9 <$> method_named(PV "unimport")
217 # a <1> entersub[t1] KS*/TARG,2
218 # b <1> leavesub[1 ref] K/REFC,1
220 # c <;> nextstate(main 2 -e:1) v:{
222 # e <1> postinc[t2] sK/1
223 # f <1> leavesub[1 ref] K/REFC,1
225 # g <;> nextstate(main 5 -e:1) v:{
227 # i <1> postinc[t2] sK/1
228 # j <1> leavesub[1 ref] K/REFC,1
230 # k <;> nextstate(main 4 -e:1) v:{
231 # l <$> gvsv(*init) s
232 # m <1> postinc[t2] sK/1
233 # n <1> leavesub[1 ref] K/REFC,1
235 # o <;> nextstate(main 3 -e:1) v:{
237 # q <1> postinc[t2] sK/1
238 # r <1> leavesub[1 ref] K/REFC,1
242 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
246 checkOptree ( name => 'regression test for patch 25352',
247 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
248 prog => 'print q/foo/',
250 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
252 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
253 # 2 <$> const[PV "warnings.pm"] s/BARE
255 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
256 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
258 # 7 <$> const[PV "warnings"] sM
259 # 8 <$> const[PV "qw"] sM
260 # 9 <$> method_named[PV "unimport"]
261 # a <1> entersub[t1] KS*/TARG,2
262 # b <1> leavesub[1 ref] K/REFC,1
265 # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
266 # 2 <$> const(PV "warnings.pm") s/BARE
268 # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$
269 # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$
271 # 7 <$> const(PV "warnings") sM
272 # 8 <$> const(PV "qw") sM
273 # 9 <$> method_named(PV "unimport")
274 # a <1> entersub[t1] KS*/TARG,2
275 # b <1> leavesub[1 ref] K/REFC,1