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 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
14 print "1..0 # Skip -- Perl configured without B module\n";
19 # import checkOptree(), and %gOpts (containing test state)
20 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
25 require_ok("B::Concise");
28 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
29 prog => q{$a=$b && print q/foo/},
34 my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}];
37 checkOptree ( name => 'BEGIN',
40 strip_open_hints => 1,
41 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
43 # a <1> leavesub[1 ref] K/REFC,1 ->(end)
44 # - <@> lineseq KP ->a
45 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$ ->2
46 # 3 <1> require sK/1 ->4
47 # 2 <$> const[PV "strict.pm"] s/BARE ->3
48 # - <;> ex-nextstate(B::Concise -837 Concise.pm:366) v:*,&,{,x*,x&,x$,$ ->4
50 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,x*,x&,x$,$ ->5
51 # 9 <1> entersub[t1] KS*/TARG,STRICT ->a
52 # 5 <0> pushmark s ->6
53 # 6 <$> const[PV "strict"] sM ->7
54 # 7 <$> const[PV "refs"] sM ->8
55 # 8 <.> method_named[PV "unimport"] ->9
57 # k <1> leavesub[1 ref] K/REFC,1 ->(end)
59 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$ ->c
60 # d <1> require sK/1 ->e
61 # c <$> const[PV "strict.pm"] s/BARE ->d
62 # - <;> ex-nextstate(B::Concise -812 Concise.pm:386) v:*,&,x*,x&,x$,$ ->e
64 # e <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,x*,x&,x$,$ ->f
65 # j <1> entersub[t1] KS*/TARG,STRICT ->k
66 # f <0> pushmark s ->g
67 # g <$> const[PV "strict"] sM ->h
68 # h <$> const[PV "refs"] sM ->i
69 # i <.> method_named[PV "unimport"] ->j
71 # u <1> leavesub[1 ref] K/REFC,1 ->(end)
72 # - <@> lineseq KP ->u
73 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$ ->m
74 # n <1> require sK/1 ->o
75 # m <$> const[PV "warnings.pm"] s/BARE ->n
76 # - <;> ex-nextstate(B::Concise -798 Concise.pm:406) v:*,&,{,x*,x&,x$,$ ->o
78 # o <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,x*,x&,x$,$ ->p
79 # t <1> entersub[t1] KS*/TARG,STRICT ->u
80 # p <0> pushmark s ->q
81 # q <$> const[PV "warnings"] sM ->r
82 # r <$> const[PV "qw"] sM ->s
83 # s <.> method_named[PV "unimport"] ->t
85 # y <1> leavesub[1 ref] K/REFC,1 ->(end)
86 # - <@> lineseq KP ->y
87 # v <;> nextstate(main 2 -e:1) v:>,<,%,{ ->w
88 # x <1> postinc[t3] sK/1 ->y
89 # - <1> ex-rv2sv sKRM/1 ->x
90 # w <#> gvsv[*beg] s ->x
93 # a <1> leavesub[1 ref] K/REFC,1 ->(end)
94 # - <@> lineseq KP ->a
95 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$ ->2
96 # 3 <1> require sK/1 ->4
97 # 2 <$> const(PV "strict.pm") s/BARE ->3
98 # - <;> ex-nextstate(B::Concise -837 Concise.pm:366) v:*,&,{,x*,x&,x$,$ ->4
100 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,x*,x&,x$,$ ->5
101 # 9 <1> entersub[t1] KS*/TARG,STRICT ->a
102 # 5 <0> pushmark s ->6
103 # 6 <$> const(PV "strict") sM ->7
104 # 7 <$> const(PV "refs") sM ->8
105 # 8 <.> method_named(PV "unimport") ->9
107 # k <1> leavesub[1 ref] K/REFC,1 ->(end)
108 # - <@> lineseq K ->k
109 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$ ->c
110 # d <1> require sK/1 ->e
111 # c <$> const(PV "strict.pm") s/BARE ->d
112 # - <;> ex-nextstate(B::Concise -812 Concise.pm:386) v:*,&,x*,x&,x$,$ ->e
113 # - <@> lineseq K ->-
114 # e <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,x*,x&,x$,$ ->f
115 # j <1> entersub[t1] KS*/TARG,STRICT ->k
116 # f <0> pushmark s ->g
117 # g <$> const(PV "strict") sM ->h
118 # h <$> const(PV "refs") sM ->i
119 # i <.> method_named(PV "unimport") ->j
121 # u <1> leavesub[1 ref] K/REFC,1 ->(end)
122 # - <@> lineseq KP ->u
123 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$ ->m
124 # n <1> require sK/1 ->o
125 # m <$> const(PV "warnings.pm") s/BARE ->n
126 # - <;> ex-nextstate(B::Concise -798 Concise.pm:406) v:*,&,{,x*,x&,x$,$ ->o
127 # - <@> lineseq K ->-
128 # o <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,x*,x&,x$,$ ->p
129 # t <1> entersub[t1] KS*/TARG,STRICT ->u
130 # p <0> pushmark s ->q
131 # q <$> const(PV "warnings") sM ->r
132 # r <$> const(PV "qw") sM ->s
133 # s <.> method_named(PV "unimport") ->t
135 # y <1> leavesub[1 ref] K/REFC,1 ->(end)
136 # - <@> lineseq KP ->y
137 # v <;> nextstate(main 2 -e:1) v:>,<,%,{ ->w
138 # x <1> postinc[t2] sK/1 ->y
139 # - <1> ex-rv2sv sKRM/1 ->x
140 # w <$> gvsv(*beg) s ->x
144 checkOptree ( name => 'END',
147 strip_open_hints => 1,
148 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
150 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
151 # - <@> lineseq KP ->4
152 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
153 # 3 <1> postinc[t3] sK/1 ->4
154 # - <1> ex-rv2sv sKRM/1 ->3
155 # 2 <#> gvsv[*end] s ->3
158 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
159 # - <@> lineseq KP ->4
160 # 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2
161 # 3 <1> postinc[t2] sK/1 ->4
162 # - <1> ex-rv2sv sKRM/1 ->3
163 # 2 <$> gvsv(*end) s ->3
167 checkOptree ( name => 'CHECK',
170 strip_open_hints => 1,
171 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
173 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
174 # - <@> lineseq KP ->4
175 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
176 # 3 <1> postinc[t3] sK/1 ->4
177 # - <1> ex-rv2sv sKRM/1 ->3
178 # 2 <#> gvsv[*chk] s ->3
181 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
182 # - <@> lineseq KP ->4
183 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
184 # 3 <1> postinc[t2] sK/1 ->4
185 # - <1> ex-rv2sv sKRM/1 ->3
186 # 2 <$> gvsv(*chk) s ->3
189 checkOptree ( name => 'UNITCHECK',
190 bcopts=> 'UNITCHECK',
192 strip_open_hints => 1,
193 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT');
195 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
196 # - <@> lineseq KP ->4
197 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
198 # 3 <1> postinc[t3] sK/1 ->4
199 # - <1> ex-rv2sv sKRM/1 ->3
200 # 2 <#> gvsv[*uc] s ->3
203 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
204 # - <@> lineseq KP ->4
205 # 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2
206 # 3 <1> postinc[t2] sK/1 ->4
207 # - <1> ex-rv2sv sKRM/1 ->3
208 # 2 <$> gvsv(*uc) s ->3
211 checkOptree ( name => 'INIT',
213 #todo => 'get working',
215 strip_open_hints => 1,
216 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
218 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
219 # - <@> lineseq KP ->4
220 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
221 # 3 <1> postinc[t3] sK/1 ->4
222 # - <1> ex-rv2sv sKRM/1 ->3
223 # 2 <#> gvsv[*init] s ->3
226 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
227 # - <@> lineseq KP ->4
228 # 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2
229 # 3 <1> postinc[t2] sK/1 ->4
230 # - <1> ex-rv2sv sKRM/1 ->3
231 # 2 <$> gvsv(*init) s ->3
235 checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec',
236 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /],
238 strip_open_hints => 1,
239 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
241 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
242 # 2 <$> const[PV "strict.pm"] s/BARE
244 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,x*,x&,x$,$
246 # 6 <$> const[PV "strict"] sM
247 # 7 <$> const[PV "refs"] sM
248 # 8 <.> method_named[PV "unimport"]
249 # 9 <1> entersub[t1] KS*/TARG,STRICT
250 # a <1> leavesub[1 ref] K/REFC,1
252 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
253 # c <$> const[PV "strict.pm"] s/BARE
255 # e <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,x*,x&,x$,$
257 # g <$> const[PV "strict"] sM
258 # h <$> const[PV "refs"] sM
259 # i <.> method_named[PV "unimport"]
260 # j <1> entersub[t1] KS*/TARG,STRICT
261 # k <1> leavesub[1 ref] K/REFC,1
263 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
264 # m <$> const[PV "warnings.pm"] s/BARE
266 # o <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,x*,x&,x$,$
268 # q <$> const[PV "warnings"] sM
269 # r <$> const[PV "qw"] sM
270 # s <.> method_named[PV "unimport"]
271 # t <1> entersub[t1] KS*/TARG,STRICT
272 # u <1> leavesub[1 ref] K/REFC,1
274 # v <;> nextstate(main 2 -e:1) v:>,<,%,{
276 # x <1> postinc[t3] sK/1
277 # y <1> leavesub[1 ref] K/REFC,1
279 # z <;> nextstate(main 5 -e:1) v:>,<,%,{
280 # 10 <#> gvsv[*end] s
281 # 11 <1> postinc[t3] sK/1
282 # 12 <1> leavesub[1 ref] K/REFC,1
284 # 13 <;> nextstate(main 4 -e:1) v:>,<,%,{
285 # 14 <#> gvsv[*init] s
286 # 15 <1> postinc[t3] sK/1
287 # 16 <1> leavesub[1 ref] K/REFC,1
289 # 17 <;> nextstate(main 3 -e:1) v:>,<,%,{
290 # 18 <#> gvsv[*chk] s
291 # 19 <1> postinc[t3] sK/1
292 # 1a <1> leavesub[1 ref] K/REFC,1
294 # 1b <;> nextstate(main 6 -e:1) v:>,<,%,{
296 # 1d <1> postinc[t3] sK/1
297 # 1e <1> leavesub[1 ref] K/REFC,1
300 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
301 # 2 <$> const(PV "strict.pm") s/BARE
303 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,x*,x&,x$,$
305 # 6 <$> const(PV "strict") sM
306 # 7 <$> const(PV "refs") sM
307 # 8 <.> method_named(PV "unimport")
308 # 9 <1> entersub[t1] KS*/TARG,STRICT
309 # a <1> leavesub[1 ref] K/REFC,1
311 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
312 # c <$> const(PV "strict.pm") s/BARE
314 # e <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,x*,x&,x$,$
316 # g <$> const(PV "strict") sM
317 # h <$> const(PV "refs") sM
318 # i <.> method_named(PV "unimport")
319 # j <1> entersub[t1] KS*/TARG,STRICT
320 # k <1> leavesub[1 ref] K/REFC,1
322 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
323 # m <$> const(PV "warnings.pm") s/BARE
325 # o <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,x*,x&,x$,$
327 # q <$> const(PV "warnings") sM
328 # r <$> const(PV "qw") sM
329 # s <.> method_named(PV "unimport")
330 # t <1> entersub[t1] KS*/TARG,STRICT
331 # u <1> leavesub[1 ref] K/REFC,1
333 # v <;> nextstate(main 2 -e:1) v:>,<,%,{
335 # x <1> postinc[t2] sK/1
336 # y <1> leavesub[1 ref] K/REFC,1
338 # z <;> nextstate(main 5 -e:1) v:>,<,%,{
339 # 10 <$> gvsv(*end) s
340 # 11 <1> postinc[t2] sK/1
341 # 12 <1> leavesub[1 ref] K/REFC,1
343 # 13 <;> nextstate(main 4 -e:1) v:>,<,%,{
344 # 14 <$> gvsv(*init) s
345 # 15 <1> postinc[t2] sK/1
346 # 16 <1> leavesub[1 ref] K/REFC,1
348 # 17 <;> nextstate(main 3 -e:1) v:>,<,%,{
349 # 18 <$> gvsv(*chk) s
350 # 19 <1> postinc[t2] sK/1
351 # 1a <1> leavesub[1 ref] K/REFC,1
353 # 1b <;> nextstate(main 6 -e:1) v:>,<,%,{
355 # 1d <1> postinc[t2] sK/1
356 # 1e <1> leavesub[1 ref] K/REFC,1
360 # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/'
364 checkOptree ( name => 'regression test for patch 25352',
365 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
366 prog => 'print q/foo/',
367 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
369 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
370 # 2 <$> const[PV "strict.pm"] s/BARE
372 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,x*,x&,x$,$
374 # 6 <$> const[PV "strict"] sM
375 # 7 <$> const[PV "refs"] sM
376 # 8 <.> method_named[PV "unimport"]
377 # 9 <1> entersub[t1] KS*/TARG,STRICT
378 # a <1> leavesub[1 ref] K/REFC,1
380 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
381 # c <$> const[PV "strict.pm"] s/BARE
383 # e <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,x*,x&,x$,$
385 # g <$> const[PV "strict"] sM
386 # h <$> const[PV "refs"] sM
387 # i <.> method_named[PV "unimport"]
388 # j <1> entersub[t1] KS*/TARG,STRICT
389 # k <1> leavesub[1 ref] K/REFC,1
391 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
392 # m <$> const[PV "warnings.pm"] s/BARE
394 # o <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,x*,x&,x$,$
396 # q <$> const[PV "warnings"] sM
397 # r <$> const[PV "qw"] sM
398 # s <.> method_named[PV "unimport"]
399 # t <1> entersub[t1] KS*/TARG,STRICT
400 # u <1> leavesub[1 ref] K/REFC,1
403 # 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,x*,x&,x$,$
404 # 2 <$> const(PV "strict.pm") s/BARE
406 # 4 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,x*,x&,x$,$
408 # 6 <$> const(PV "strict") sM
409 # 7 <$> const(PV "refs") sM
410 # 8 <.> method_named(PV "unimport")
411 # 9 <1> entersub[t1] KS*/TARG,STRICT
412 # a <1> leavesub[1 ref] K/REFC,1
414 # b <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,x*,x&,x$,$
415 # c <$> const(PV "strict.pm") s/BARE
417 # e <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,x*,x&,x$,$
419 # g <$> const(PV "strict") sM
420 # h <$> const(PV "refs") sM
421 # i <.> method_named(PV "unimport")
422 # j <1> entersub[t1] KS*/TARG,STRICT
423 # k <1> leavesub[1 ref] K/REFC,1
425 # l <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,x*,x&,x$,$
426 # m <$> const(PV "warnings.pm") s/BARE
428 # o <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,x*,x&,x$,$
430 # q <$> const(PV "warnings") sM
431 # r <$> const(PV "qw") sM
432 # s <.> method_named(PV "unimport")
433 # t <1> entersub[t1] KS*/TARG,STRICT
434 # u <1> leavesub[1 ref] K/REFC,1