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++ }];
44 checkOptree ( name => 'BEGIN',
47 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
49 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
50 # - <@> lineseq KP ->b
51 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
52 # 3 <1> require sK/1 ->4
53 # 2 <$> const[PV "warnings.pm"] s/BARE ->3
54 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
56 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
57 # a <1> entersub[t1] KS*/TARG,2 ->b
58 # 6 <0> pushmark s ->7
59 # 7 <$> const[PV "warnings"] sM ->8
60 # 8 <$> const[PV "qw"] sM ->9
61 # 9 <$> method_named[PVIV 1520340202] ->a
63 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
64 # - <@> lineseq KP ->f
65 # c <;> nextstate(main 2 -e:1) v ->d
66 # e <1> postinc[t3] sK/1 ->f
67 # - <1> ex-rv2sv sKRM/1 ->e
68 # d <#> gvsv[*beg] s ->e
71 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
72 # - <@> lineseq KP ->b
73 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
74 # 3 <1> require sK/1 ->4
75 # 2 <$> const(PV "warnings.pm") s/BARE ->3
76 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
78 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
79 # a <1> entersub[t1] KS*/TARG,2 ->b
80 # 6 <0> pushmark s ->7
81 # 7 <$> const(PV "warnings") sM ->8
82 # 8 <$> const(PV "qw") sM ->9
83 # 9 <$> method_named(PVIV 1520340202) ->a
85 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
86 # - <@> lineseq KP ->f
87 # c <;> nextstate(main 2 -e:1) v ->d
88 # e <1> postinc[t2] sK/1 ->f
89 # - <1> ex-rv2sv sKRM/1 ->e
90 # d <$> gvsv(*beg) s ->e
94 checkOptree ( name => 'END',
97 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
99 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
100 # - <@> lineseq KP ->4
101 # 1 <;> nextstate(main 5 -e:6) v ->2
102 # 3 <1> postinc[t3] sK/1 ->4
103 # - <1> ex-rv2sv sKRM/1 ->3
104 # 2 <#> gvsv[*end] s ->3
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[t2] sK/1 ->4
111 # - <1> ex-rv2sv sKRM/1 ->3
112 # 2 <$> gvsv(*end) s ->3
116 checkOptree ( name => 'CHECK',
119 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
121 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
122 # - <@> lineseq KP ->4
123 # 1 <;> nextstate(main 3 -e:4) v ->2
124 # 3 <1> postinc[t3] sK/1 ->4
125 # - <1> ex-rv2sv sKRM/1 ->3
126 # 2 <#> gvsv[*chk] s ->3
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[t2] sK/1 ->4
133 # - <1> ex-rv2sv sKRM/1 ->3
134 # 2 <$> gvsv(*chk) s ->3
138 checkOptree ( name => 'INIT',
140 #todo => 'get working',
142 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
144 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
145 # - <@> lineseq KP ->4
146 # 1 <;> nextstate(main 4 -e:5) v ->2
147 # 3 <1> postinc[t3] sK/1 ->4
148 # - <1> ex-rv2sv sKRM/1 ->3
149 # 2 <#> gvsv[*init] s ->3
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[t2] sK/1 ->4
156 # - <1> ex-rv2sv sKRM/1 ->3
157 # 2 <$> gvsv(*init) s ->3
161 checkOptree ( name => 'all of BEGIN END INIT CHECK -exec',
162 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
163 #todo => 'get working',
165 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
167 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
168 # 2 <$> const[PV "warnings.pm"] s/BARE
170 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
171 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2
173 # 7 <$> const[PV "warnings"] sM
174 # 8 <$> const[PV "qw"] sM
175 # 9 <$> method_named[PVIV 1520340202]
176 # a <1> entersub[t1] KS*/TARG,2
177 # b <1> leavesub[1 ref] K/REFC,1
179 # c <;> nextstate(main 2 -e:1) v
181 # e <1> postinc[t3] sK/1
182 # f <1> leavesub[1 ref] K/REFC,1
184 # g <;> nextstate(main 5 -e:1) v
186 # i <1> postinc[t3] sK/1
187 # j <1> leavesub[1 ref] K/REFC,1
189 # k <;> nextstate(main 4 -e:1) v
190 # l <#> gvsv[*init] s
191 # m <1> postinc[t3] sK/1
192 # n <1> leavesub[1 ref] K/REFC,1
194 # o <;> nextstate(main 3 -e:1) v
196 # q <1> postinc[t3] sK/1
197 # r <1> leavesub[1 ref] K/REFC,1
200 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
201 # 2 <$> const(PV "warnings.pm") s/BARE
203 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
204 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2
206 # 7 <$> const(PV "warnings") sM
207 # 8 <$> const(PV "qw") sM
208 # 9 <$> method_named(PVIV 1520340202)
209 # a <1> entersub[t1] KS*/TARG,2
210 # b <1> leavesub[1 ref] K/REFC,1
212 # c <;> nextstate(main 2 -e:1) v
214 # e <1> postinc[t2] sK/1
215 # f <1> leavesub[1 ref] K/REFC,1
217 # g <;> nextstate(main 5 -e:1) v
219 # i <1> postinc[t2] sK/1
220 # j <1> leavesub[1 ref] K/REFC,1
222 # k <;> nextstate(main 4 -e:1) v
223 # l <$> gvsv(*init) s
224 # m <1> postinc[t2] sK/1
225 # n <1> leavesub[1 ref] K/REFC,1
227 # o <;> nextstate(main 3 -e:1) v
229 # q <1> postinc[t2] sK/1
230 # r <1> leavesub[1 ref] K/REFC,1