Commit | Line | Data |
cc02ea56 |
1 | #!./perl |
2 | |
09e96b99 |
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 |
8 | # spaces. |
9 | |
cc02ea56 |
10 | BEGIN { |
5638aaac |
11 | if ($ENV{PERL_CORE}){ |
12 | chdir('t') if -d 't'; |
13 | @INC = ('.', '../lib', '../ext/B/t'); |
14 | } else { |
15 | unshift @INC, 't'; |
16 | push @INC, "../../t"; |
17 | } |
9cd8f857 |
18 | require Config; |
19 | if (($Config::Config{'extensions'} !~ /\bB\b/) ){ |
20 | print "1..0 # Skip -- Perl configured without B module\n"; |
21 | exit 0; |
22 | } |
19e169bf |
23 | # require 'test.pl'; # now done by OptreeCheck |
cc02ea56 |
24 | } |
25 | |
26 | # import checkOptree(), and %gOpts (containing test state) |
27 | use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!! |
28 | use Config; |
29 | |
2c394315 |
30 | plan tests => 7; |
cc02ea56 |
31 | |
32 | require_ok("B::Concise"); |
33 | |
34 | my $out = runperl( |
35 | switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"], |
36 | prog => q{$a=$b && print q/foo/}, |
37 | stderr => 1 ); |
38 | |
39 | #print "out:$out\n"; |
40 | |
bc2a472e |
41 | my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }]; |
cc02ea56 |
42 | |
43 | |
b8443148 |
44 | my @warnings_todo; |
45 | @warnings_todo = (todo => |
46 | "Change 23768 (Remove Carp from warnings.pm) alters expected output, not" |
47 | . "propagated to 5.8.x") |
48 | if $] < 5.009; |
49 | |
09337566 |
50 | my @open_todo; |
51 | sub open_todo { |
52 | if (((caller 0)[10]||{})->{open}) { |
53 | @open_todo = (skip => "\$^OPEN is set"); |
54 | } |
55 | } |
56 | open_todo; |
b8443148 |
57 | |
cc02ea56 |
58 | checkOptree ( name => 'BEGIN', |
59 | bcopts => 'BEGIN', |
60 | prog => $src, |
b8443148 |
61 | @warnings_todo, |
09337566 |
62 | @open_todo, |
cc02ea56 |
63 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
64 | # BEGIN 1: |
65 | # b <1> leavesub[1 ref] K/REFC,1 ->(end) |
66 | # - <@> lineseq KP ->b |
d5ec2987 |
67 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2 |
cc02ea56 |
68 | # 3 <1> require sK/1 ->4 |
09e96b99 |
69 | # 2 <$> const[PV "warnings.pm"] s/BARE ->3 |
d5ec2987 |
70 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5 |
cc02ea56 |
71 | # - <@> lineseq K ->- |
d5ec2987 |
72 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6 |
cc02ea56 |
73 | # a <1> entersub[t1] KS*/TARG,2 ->b |
74 | # 6 <0> pushmark s ->7 |
09e96b99 |
75 | # 7 <$> const[PV "warnings"] sM ->8 |
76 | # 8 <$> const[PV "qw"] sM ->9 |
427d62a4 |
77 | # 9 <$> method_named[PV "import"] ->a |
cc02ea56 |
78 | # BEGIN 2: |
09e96b99 |
79 | # f <1> leavesub[1 ref] K/REFC,1 ->(end) |
80 | # - <@> lineseq KP ->f |
d5ec2987 |
81 | # c <;> nextstate(main 2 -e:1) v:{ ->d |
09e96b99 |
82 | # e <1> postinc[t3] sK/1 ->f |
83 | # - <1> ex-rv2sv sKRM/1 ->e |
84 | # d <#> gvsv[*beg] s ->e |
cc02ea56 |
85 | EOT_EOT |
86 | # BEGIN 1: |
87 | # b <1> leavesub[1 ref] K/REFC,1 ->(end) |
88 | # - <@> lineseq KP ->b |
d5ec2987 |
89 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->2 |
cc02ea56 |
90 | # 3 <1> require sK/1 ->4 |
09e96b99 |
91 | # 2 <$> const(PV "warnings.pm") s/BARE ->3 |
d5ec2987 |
92 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ ->5 |
cc02ea56 |
93 | # - <@> lineseq K ->- |
d5ec2987 |
94 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ ->6 |
cc02ea56 |
95 | # a <1> entersub[t1] KS*/TARG,2 ->b |
96 | # 6 <0> pushmark s ->7 |
09e96b99 |
97 | # 7 <$> const(PV "warnings") sM ->8 |
98 | # 8 <$> const(PV "qw") sM ->9 |
427d62a4 |
99 | # 9 <$> method_named(PV "import") ->a |
cc02ea56 |
100 | # BEGIN 2: |
09e96b99 |
101 | # f <1> leavesub[1 ref] K/REFC,1 ->(end) |
102 | # - <@> lineseq KP ->f |
d5ec2987 |
103 | # c <;> nextstate(main 2 -e:1) v:{ ->d |
09e96b99 |
104 | # e <1> postinc[t2] sK/1 ->f |
105 | # - <1> ex-rv2sv sKRM/1 ->e |
106 | # d <$> gvsv(*beg) s ->e |
cc02ea56 |
107 | EONT_EONT |
108 | |
109 | |
110 | checkOptree ( name => 'END', |
111 | bcopts => 'END', |
112 | prog => $src, |
09337566 |
113 | @open_todo, |
cc02ea56 |
114 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
115 | # END 1: |
116 | # 4 <1> leavesub[1 ref] K/REFC,1 ->(end) |
117 | # - <@> lineseq KP ->4 |
d5ec2987 |
118 | # 1 <;> nextstate(main 5 -e:6) v:{ ->2 |
cc02ea56 |
119 | # 3 <1> postinc[t3] sK/1 ->4 |
120 | # - <1> ex-rv2sv sKRM/1 ->3 |
121 | # 2 <#> gvsv[*end] s ->3 |
122 | EOT_EOT |
123 | # END 1: |
124 | # 4 <1> leavesub[1 ref] K/REFC,1 ->(end) |
125 | # - <@> lineseq KP ->4 |
d5ec2987 |
126 | # 1 <;> nextstate(main 5 -e:6) v:{ ->2 |
cc02ea56 |
127 | # 3 <1> postinc[t2] sK/1 ->4 |
128 | # - <1> ex-rv2sv sKRM/1 ->3 |
129 | # 2 <$> gvsv(*end) s ->3 |
130 | EONT_EONT |
131 | |
132 | |
133 | checkOptree ( name => 'CHECK', |
134 | bcopts => 'CHECK', |
135 | prog => $src, |
09337566 |
136 | @open_todo, |
cc02ea56 |
137 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
138 | # CHECK 1: |
139 | # 4 <1> leavesub[1 ref] K/REFC,1 ->(end) |
140 | # - <@> lineseq KP ->4 |
d5ec2987 |
141 | # 1 <;> nextstate(main 3 -e:4) v:{ ->2 |
cc02ea56 |
142 | # 3 <1> postinc[t3] sK/1 ->4 |
143 | # - <1> ex-rv2sv sKRM/1 ->3 |
144 | # 2 <#> gvsv[*chk] s ->3 |
145 | EOT_EOT |
146 | # CHECK 1: |
147 | # 4 <1> leavesub[1 ref] K/REFC,1 ->(end) |
148 | # - <@> lineseq KP ->4 |
d5ec2987 |
149 | # 1 <;> nextstate(main 3 -e:4) v:{ ->2 |
cc02ea56 |
150 | # 3 <1> postinc[t2] sK/1 ->4 |
151 | # - <1> ex-rv2sv sKRM/1 ->3 |
152 | # 2 <$> gvsv(*chk) s ->3 |
153 | EONT_EONT |
154 | |
155 | |
156 | checkOptree ( name => 'INIT', |
157 | bcopts => 'INIT', |
158 | #todo => 'get working', |
159 | prog => $src, |
09337566 |
160 | @open_todo, |
cc02ea56 |
161 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
162 | # INIT 1: |
163 | # 4 <1> leavesub[1 ref] K/REFC,1 ->(end) |
164 | # - <@> lineseq KP ->4 |
d5ec2987 |
165 | # 1 <;> nextstate(main 4 -e:5) v:{ ->2 |
cc02ea56 |
166 | # 3 <1> postinc[t3] sK/1 ->4 |
167 | # - <1> ex-rv2sv sKRM/1 ->3 |
168 | # 2 <#> gvsv[*init] s ->3 |
169 | EOT_EOT |
170 | # INIT 1: |
171 | # 4 <1> leavesub[1 ref] K/REFC,1 ->(end) |
172 | # - <@> lineseq KP ->4 |
d5ec2987 |
173 | # 1 <;> nextstate(main 4 -e:5) v:{ ->2 |
cc02ea56 |
174 | # 3 <1> postinc[t2] sK/1 ->4 |
175 | # - <1> ex-rv2sv sKRM/1 ->3 |
176 | # 2 <$> gvsv(*init) s ->3 |
177 | EONT_EONT |
178 | |
179 | |
180 | checkOptree ( name => 'all of BEGIN END INIT CHECK -exec', |
181 | bcopts => [qw/ BEGIN END INIT CHECK -exec /], |
cc02ea56 |
182 | prog => $src, |
b8443148 |
183 | @warnings_todo, |
09337566 |
184 | @open_todo, |
cc02ea56 |
185 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
186 | # BEGIN 1: |
d5ec2987 |
187 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ |
09e96b99 |
188 | # 2 <$> const[PV "warnings.pm"] s/BARE |
cc02ea56 |
189 | # 3 <1> require sK/1 |
d5ec2987 |
190 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ |
191 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ |
cc02ea56 |
192 | # 6 <0> pushmark s |
09e96b99 |
193 | # 7 <$> const[PV "warnings"] sM |
194 | # 8 <$> const[PV "qw"] sM |
427d62a4 |
195 | # 9 <$> method_named[PV "unimport"] |
cc02ea56 |
196 | # a <1> entersub[t1] KS*/TARG,2 |
197 | # b <1> leavesub[1 ref] K/REFC,1 |
198 | # BEGIN 2: |
d5ec2987 |
199 | # c <;> nextstate(main 2 -e:1) v:{ |
09e96b99 |
200 | # d <#> gvsv[*beg] s |
201 | # e <1> postinc[t3] sK/1 |
202 | # f <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
203 | # END 1: |
d5ec2987 |
204 | # g <;> nextstate(main 5 -e:1) v:{ |
09e96b99 |
205 | # h <#> gvsv[*end] s |
206 | # i <1> postinc[t3] sK/1 |
207 | # j <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
208 | # INIT 1: |
d5ec2987 |
209 | # k <;> nextstate(main 4 -e:1) v:{ |
09e96b99 |
210 | # l <#> gvsv[*init] s |
211 | # m <1> postinc[t3] sK/1 |
212 | # n <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
213 | # CHECK 1: |
d5ec2987 |
214 | # o <;> nextstate(main 3 -e:1) v:{ |
09e96b99 |
215 | # p <#> gvsv[*chk] s |
216 | # q <1> postinc[t3] sK/1 |
217 | # r <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
218 | EOT_EOT |
219 | # BEGIN 1: |
d5ec2987 |
220 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ |
09e96b99 |
221 | # 2 <$> const(PV "warnings.pm") s/BARE |
cc02ea56 |
222 | # 3 <1> require sK/1 |
d5ec2987 |
223 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v:*,&,{,$ |
224 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) :*,&,{,$ |
cc02ea56 |
225 | # 6 <0> pushmark s |
09e96b99 |
226 | # 7 <$> const(PV "warnings") sM |
227 | # 8 <$> const(PV "qw") sM |
427d62a4 |
228 | # 9 <$> method_named(PV "unimport") |
cc02ea56 |
229 | # a <1> entersub[t1] KS*/TARG,2 |
230 | # b <1> leavesub[1 ref] K/REFC,1 |
231 | # BEGIN 2: |
d5ec2987 |
232 | # c <;> nextstate(main 2 -e:1) v:{ |
09e96b99 |
233 | # d <$> gvsv(*beg) s |
234 | # e <1> postinc[t2] sK/1 |
235 | # f <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
236 | # END 1: |
d5ec2987 |
237 | # g <;> nextstate(main 5 -e:1) v:{ |
09e96b99 |
238 | # h <$> gvsv(*end) s |
239 | # i <1> postinc[t2] sK/1 |
240 | # j <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
241 | # INIT 1: |
d5ec2987 |
242 | # k <;> nextstate(main 4 -e:1) v:{ |
09e96b99 |
243 | # l <$> gvsv(*init) s |
244 | # m <1> postinc[t2] sK/1 |
245 | # n <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
246 | # CHECK 1: |
d5ec2987 |
247 | # o <;> nextstate(main 3 -e:1) v:{ |
09e96b99 |
248 | # p <$> gvsv(*chk) s |
249 | # q <1> postinc[t2] sK/1 |
250 | # r <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
251 | EONT_EONT |
2c394315 |
252 | |
253 | |
254 | # perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/' |
255 | |
256 | |
257 | |
258 | checkOptree ( name => 'regression test for patch 25352', |
259 | bcopts => [qw/ BEGIN END INIT CHECK -exec /], |
260 | prog => 'print q/foo/', |
261 | @warnings_todo, |
262 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
263 | # BEGIN 1: |
d5ec2987 |
264 | # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$ |
2c394315 |
265 | # 2 <$> const[PV "warnings.pm"] s/BARE |
266 | # 3 <1> require sK/1 |
d5ec2987 |
267 | # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$ |
268 | # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$ |
2c394315 |
269 | # 6 <0> pushmark s |
270 | # 7 <$> const[PV "warnings"] sM |
271 | # 8 <$> const[PV "qw"] sM |
272 | # 9 <$> method_named[PV "unimport"] |
273 | # a <1> entersub[t1] KS*/TARG,2 |
274 | # b <1> leavesub[1 ref] K/REFC,1 |
275 | EOT_EOT |
276 | # BEGIN 1: |
d5ec2987 |
277 | # 1 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$ |
2c394315 |
278 | # 2 <$> const(PV "warnings.pm") s/BARE |
279 | # 3 <1> require sK/1 |
d5ec2987 |
280 | # 4 <;> nextstate(B::Concise -234 Concise.pm:359) v:*,&,{,$ |
281 | # 5 <;> nextstate(B::Concise -234 Concise.pm:359) :*,&,{,$ |
2c394315 |
282 | # 6 <0> pushmark s |
283 | # 7 <$> const(PV "warnings") sM |
284 | # 8 <$> const(PV "qw") sM |
285 | # 9 <$> method_named(PV "unimport") |
286 | # a <1> entersub[t1] KS*/TARG,2 |
287 | # b <1> leavesub[1 ref] K/REFC,1 |
288 | EONT_EONT |