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 if ($Config::Config{'extensions'} !~ /\bData\/Dumper\b/) {
25 "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
31 # import checkOptree(), and %gOpts (containing test state)
32 use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
37 require_ok("B::Concise");
40 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"],
41 prog => q{$a=$b && print q/foo/},
46 my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }];
49 checkOptree ( name => 'BEGIN',
52 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
54 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
55 # - <@> lineseq KP ->b
56 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
57 # 3 <1> require sK/1 ->4
58 # 2 <$> const[PV "warnings.pm"] s/BARE ->3
59 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
61 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
62 # a <1> entersub[t1] KS*/TARG,2 ->b
63 # 6 <0> pushmark s ->7
64 # 7 <$> const[PV "warnings"] sM ->8
65 # 8 <$> const[PV "qw"] sM ->9
66 # 9 <$> method_named[PVIV 1520340202] ->a
68 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
69 # - <@> lineseq KP ->f
70 # c <;> nextstate(main 2 -e:1) v ->d
71 # e <1> postinc[t3] sK/1 ->f
72 # - <1> ex-rv2sv sKRM/1 ->e
73 # d <#> gvsv[*beg] s ->e
76 # b <1> leavesub[1 ref] K/REFC,1 ->(end)
77 # - <@> lineseq KP ->b
78 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
79 # 3 <1> require sK/1 ->4
80 # 2 <$> const(PV "warnings.pm") s/BARE ->3
81 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
83 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
84 # a <1> entersub[t1] KS*/TARG,2 ->b
85 # 6 <0> pushmark s ->7
86 # 7 <$> const(PV "warnings") sM ->8
87 # 8 <$> const(PV "qw") sM ->9
88 # 9 <$> method_named(PVIV 1520340202) ->a
90 # f <1> leavesub[1 ref] K/REFC,1 ->(end)
91 # - <@> lineseq KP ->f
92 # c <;> nextstate(main 2 -e:1) v ->d
93 # e <1> postinc[t2] sK/1 ->f
94 # - <1> ex-rv2sv sKRM/1 ->e
95 # d <$> gvsv(*beg) s ->e
99 checkOptree ( name => 'END',
102 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
104 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
105 # - <@> lineseq KP ->4
106 # 1 <;> nextstate(main 5 -e:6) v ->2
107 # 3 <1> postinc[t3] sK/1 ->4
108 # - <1> ex-rv2sv sKRM/1 ->3
109 # 2 <#> gvsv[*end] s ->3
112 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
113 # - <@> lineseq KP ->4
114 # 1 <;> nextstate(main 5 -e:6) v ->2
115 # 3 <1> postinc[t2] sK/1 ->4
116 # - <1> ex-rv2sv sKRM/1 ->3
117 # 2 <$> gvsv(*end) s ->3
121 checkOptree ( name => 'CHECK',
124 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
126 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
127 # - <@> lineseq KP ->4
128 # 1 <;> nextstate(main 3 -e:4) v ->2
129 # 3 <1> postinc[t3] sK/1 ->4
130 # - <1> ex-rv2sv sKRM/1 ->3
131 # 2 <#> gvsv[*chk] s ->3
134 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
135 # - <@> lineseq KP ->4
136 # 1 <;> nextstate(main 3 -e:4) v ->2
137 # 3 <1> postinc[t2] sK/1 ->4
138 # - <1> ex-rv2sv sKRM/1 ->3
139 # 2 <$> gvsv(*chk) s ->3
143 checkOptree ( name => 'INIT',
145 #todo => 'get working',
147 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
149 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
150 # - <@> lineseq KP ->4
151 # 1 <;> nextstate(main 4 -e:5) v ->2
152 # 3 <1> postinc[t3] sK/1 ->4
153 # - <1> ex-rv2sv sKRM/1 ->3
154 # 2 <#> gvsv[*init] s ->3
157 # 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
158 # - <@> lineseq KP ->4
159 # 1 <;> nextstate(main 4 -e:5) v ->2
160 # 3 <1> postinc[t2] sK/1 ->4
161 # - <1> ex-rv2sv sKRM/1 ->3
162 # 2 <$> gvsv(*init) s ->3
166 checkOptree ( name => 'all of BEGIN END INIT CHECK -exec',
167 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
168 #todo => 'get working',
170 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
172 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
173 # 2 <$> const[PV "warnings.pm"] s/BARE
175 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
176 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2
178 # 7 <$> const[PV "warnings"] sM
179 # 8 <$> const[PV "qw"] sM
180 # 9 <$> method_named[PVIV 1520340202]
181 # a <1> entersub[t1] KS*/TARG,2
182 # b <1> leavesub[1 ref] K/REFC,1
184 # c <;> nextstate(main 2 -e:1) v
186 # e <1> postinc[t3] sK/1
187 # f <1> leavesub[1 ref] K/REFC,1
189 # g <;> nextstate(main 5 -e:1) v
191 # i <1> postinc[t3] sK/1
192 # j <1> leavesub[1 ref] K/REFC,1
194 # k <;> nextstate(main 4 -e:1) v
195 # l <#> gvsv[*init] s
196 # m <1> postinc[t3] sK/1
197 # n <1> leavesub[1 ref] K/REFC,1
199 # o <;> nextstate(main 3 -e:1) v
201 # q <1> postinc[t3] sK/1
202 # r <1> leavesub[1 ref] K/REFC,1
205 # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
206 # 2 <$> const(PV "warnings.pm") s/BARE
208 # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
209 # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2
211 # 7 <$> const(PV "warnings") sM
212 # 8 <$> const(PV "qw") sM
213 # 9 <$> method_named(PVIV 1520340202)
214 # a <1> entersub[t1] KS*/TARG,2
215 # b <1> leavesub[1 ref] K/REFC,1
217 # c <;> nextstate(main 2 -e:1) v
219 # e <1> postinc[t2] sK/1
220 # f <1> leavesub[1 ref] K/REFC,1
222 # g <;> nextstate(main 5 -e:1) v
224 # i <1> postinc[t2] sK/1
225 # j <1> leavesub[1 ref] K/REFC,1
227 # k <;> nextstate(main 4 -e:1) v
228 # l <$> gvsv(*init) s
229 # m <1> postinc[t2] sK/1
230 # n <1> leavesub[1 ref] K/REFC,1
232 # o <;> nextstate(main 3 -e:1) v
234 # q <1> postinc[t2] sK/1
235 # r <1> leavesub[1 ref] K/REFC,1