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 | |
30 | plan tests => 6; |
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 | |
50 | |
cc02ea56 |
51 | checkOptree ( name => 'BEGIN', |
52 | bcopts => 'BEGIN', |
53 | prog => $src, |
b8443148 |
54 | @warnings_todo, |
cc02ea56 |
55 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
56 | # BEGIN 1: |
57 | # b <1> leavesub[1 ref] K/REFC,1 ->(end) |
58 | # - <@> lineseq KP ->b |
09e96b99 |
59 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2 |
cc02ea56 |
60 | # 3 <1> require sK/1 ->4 |
09e96b99 |
61 | # 2 <$> const[PV "warnings.pm"] s/BARE ->3 |
62 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5 |
cc02ea56 |
63 | # - <@> lineseq K ->- |
09e96b99 |
64 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6 |
cc02ea56 |
65 | # a <1> entersub[t1] KS*/TARG,2 ->b |
66 | # 6 <0> pushmark s ->7 |
09e96b99 |
67 | # 7 <$> const[PV "warnings"] sM ->8 |
68 | # 8 <$> const[PV "qw"] sM ->9 |
427d62a4 |
69 | # 9 <$> method_named[PV "import"] ->a |
cc02ea56 |
70 | # BEGIN 2: |
09e96b99 |
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 |
cc02ea56 |
77 | EOT_EOT |
78 | # BEGIN 1: |
79 | # b <1> leavesub[1 ref] K/REFC,1 ->(end) |
80 | # - <@> lineseq KP ->b |
09e96b99 |
81 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2 |
cc02ea56 |
82 | # 3 <1> require sK/1 ->4 |
09e96b99 |
83 | # 2 <$> const(PV "warnings.pm") s/BARE ->3 |
84 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5 |
cc02ea56 |
85 | # - <@> lineseq K ->- |
09e96b99 |
86 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6 |
cc02ea56 |
87 | # a <1> entersub[t1] KS*/TARG,2 ->b |
88 | # 6 <0> pushmark s ->7 |
09e96b99 |
89 | # 7 <$> const(PV "warnings") sM ->8 |
90 | # 8 <$> const(PV "qw") sM ->9 |
427d62a4 |
91 | # 9 <$> method_named(PV "import") ->a |
cc02ea56 |
92 | # BEGIN 2: |
09e96b99 |
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 |
cc02ea56 |
99 | EONT_EONT |
100 | |
101 | |
102 | checkOptree ( name => 'END', |
103 | bcopts => 'END', |
104 | prog => $src, |
105 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
106 | # END 1: |
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 |
113 | EOT_EOT |
114 | # END 1: |
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 |
121 | EONT_EONT |
122 | |
123 | |
124 | checkOptree ( name => 'CHECK', |
125 | bcopts => 'CHECK', |
126 | prog => $src, |
127 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
128 | # CHECK 1: |
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 |
135 | EOT_EOT |
136 | # CHECK 1: |
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 |
143 | EONT_EONT |
144 | |
145 | |
146 | checkOptree ( name => 'INIT', |
147 | bcopts => 'INIT', |
148 | #todo => 'get working', |
149 | prog => $src, |
150 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
151 | # INIT 1: |
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 |
158 | EOT_EOT |
159 | # INIT 1: |
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 |
166 | EONT_EONT |
167 | |
168 | |
169 | checkOptree ( name => 'all of BEGIN END INIT CHECK -exec', |
170 | bcopts => [qw/ BEGIN END INIT CHECK -exec /], |
cc02ea56 |
171 | prog => $src, |
b8443148 |
172 | @warnings_todo, |
cc02ea56 |
173 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
174 | # BEGIN 1: |
09e96b99 |
175 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
176 | # 2 <$> const[PV "warnings.pm"] s/BARE |
cc02ea56 |
177 | # 3 <1> require sK/1 |
09e96b99 |
178 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
179 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 |
cc02ea56 |
180 | # 6 <0> pushmark s |
09e96b99 |
181 | # 7 <$> const[PV "warnings"] sM |
182 | # 8 <$> const[PV "qw"] sM |
427d62a4 |
183 | # 9 <$> method_named[PV "unimport"] |
cc02ea56 |
184 | # a <1> entersub[t1] KS*/TARG,2 |
185 | # b <1> leavesub[1 ref] K/REFC,1 |
186 | # BEGIN 2: |
09e96b99 |
187 | # c <;> nextstate(main 2 -e:1) v |
188 | # d <#> gvsv[*beg] s |
189 | # e <1> postinc[t3] sK/1 |
190 | # f <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
191 | # END 1: |
09e96b99 |
192 | # g <;> nextstate(main 5 -e:1) v |
193 | # h <#> gvsv[*end] s |
194 | # i <1> postinc[t3] sK/1 |
195 | # j <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
196 | # INIT 1: |
09e96b99 |
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 |
cc02ea56 |
201 | # CHECK 1: |
09e96b99 |
202 | # o <;> nextstate(main 3 -e:1) v |
203 | # p <#> gvsv[*chk] s |
204 | # q <1> postinc[t3] sK/1 |
205 | # r <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
206 | EOT_EOT |
207 | # BEGIN 1: |
09e96b99 |
208 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
209 | # 2 <$> const(PV "warnings.pm") s/BARE |
cc02ea56 |
210 | # 3 <1> require sK/1 |
09e96b99 |
211 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
212 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 |
cc02ea56 |
213 | # 6 <0> pushmark s |
09e96b99 |
214 | # 7 <$> const(PV "warnings") sM |
215 | # 8 <$> const(PV "qw") sM |
427d62a4 |
216 | # 9 <$> method_named(PV "unimport") |
cc02ea56 |
217 | # a <1> entersub[t1] KS*/TARG,2 |
218 | # b <1> leavesub[1 ref] K/REFC,1 |
219 | # BEGIN 2: |
09e96b99 |
220 | # c <;> nextstate(main 2 -e:1) v |
221 | # d <$> gvsv(*beg) s |
222 | # e <1> postinc[t2] sK/1 |
223 | # f <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
224 | # END 1: |
09e96b99 |
225 | # g <;> nextstate(main 5 -e:1) v |
226 | # h <$> gvsv(*end) s |
227 | # i <1> postinc[t2] sK/1 |
228 | # j <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
229 | # INIT 1: |
09e96b99 |
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 |
cc02ea56 |
234 | # CHECK 1: |
09e96b99 |
235 | # o <;> nextstate(main 3 -e:1) v |
236 | # p <$> gvsv(*chk) s |
237 | # q <1> postinc[t2] sK/1 |
238 | # r <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
239 | EONT_EONT |