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 | } |
8dd2f9d4 |
23 | if ($Config::Config{'extensions'} !~ /\bData\/Dumper\b/) { |
2799c206 |
24 | print |
25 | "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n"; |
26 | exit 0; |
2799c206 |
27 | } |
5638aaac |
28 | require 'test.pl'; |
cc02ea56 |
29 | } |
30 | |
31 | # import checkOptree(), and %gOpts (containing test state) |
32 | use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!! |
33 | use Config; |
34 | |
35 | plan tests => 6; |
36 | |
37 | require_ok("B::Concise"); |
38 | |
39 | my $out = runperl( |
40 | switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"], |
41 | prog => q{$a=$b && print q/foo/}, |
42 | stderr => 1 ); |
43 | |
44 | #print "out:$out\n"; |
45 | |
bc2a472e |
46 | my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }]; |
cc02ea56 |
47 | |
48 | |
cc02ea56 |
49 | checkOptree ( name => 'BEGIN', |
50 | bcopts => 'BEGIN', |
51 | prog => $src, |
52 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
53 | # BEGIN 1: |
54 | # b <1> leavesub[1 ref] K/REFC,1 ->(end) |
55 | # - <@> lineseq KP ->b |
09e96b99 |
56 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2 |
cc02ea56 |
57 | # 3 <1> require sK/1 ->4 |
09e96b99 |
58 | # 2 <$> const[PV "warnings.pm"] s/BARE ->3 |
59 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5 |
cc02ea56 |
60 | # - <@> lineseq K ->- |
09e96b99 |
61 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6 |
cc02ea56 |
62 | # a <1> entersub[t1] KS*/TARG,2 ->b |
63 | # 6 <0> pushmark s ->7 |
09e96b99 |
64 | # 7 <$> const[PV "warnings"] sM ->8 |
65 | # 8 <$> const[PV "qw"] sM ->9 |
cc02ea56 |
66 | # 9 <$> method_named[PVIV 1520340202] ->a |
67 | # BEGIN 2: |
09e96b99 |
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 |
cc02ea56 |
74 | EOT_EOT |
75 | # BEGIN 1: |
76 | # b <1> leavesub[1 ref] K/REFC,1 ->(end) |
77 | # - <@> lineseq KP ->b |
09e96b99 |
78 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2 |
cc02ea56 |
79 | # 3 <1> require sK/1 ->4 |
09e96b99 |
80 | # 2 <$> const(PV "warnings.pm") s/BARE ->3 |
81 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5 |
cc02ea56 |
82 | # - <@> lineseq K ->- |
09e96b99 |
83 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6 |
cc02ea56 |
84 | # a <1> entersub[t1] KS*/TARG,2 ->b |
85 | # 6 <0> pushmark s ->7 |
09e96b99 |
86 | # 7 <$> const(PV "warnings") sM ->8 |
87 | # 8 <$> const(PV "qw") sM ->9 |
cc02ea56 |
88 | # 9 <$> method_named(PVIV 1520340202) ->a |
89 | # BEGIN 2: |
09e96b99 |
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 |
cc02ea56 |
96 | EONT_EONT |
97 | |
98 | |
99 | checkOptree ( name => 'END', |
100 | bcopts => 'END', |
101 | prog => $src, |
102 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
103 | # END 1: |
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 |
110 | EOT_EOT |
111 | # END 1: |
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 |
118 | EONT_EONT |
119 | |
120 | |
121 | checkOptree ( name => 'CHECK', |
122 | bcopts => 'CHECK', |
123 | prog => $src, |
124 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
125 | # CHECK 1: |
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 |
132 | EOT_EOT |
133 | # CHECK 1: |
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 |
140 | EONT_EONT |
141 | |
142 | |
143 | checkOptree ( name => 'INIT', |
144 | bcopts => 'INIT', |
145 | #todo => 'get working', |
146 | prog => $src, |
147 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
148 | # INIT 1: |
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 |
155 | EOT_EOT |
156 | # INIT 1: |
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 |
163 | EONT_EONT |
164 | |
165 | |
166 | checkOptree ( name => 'all of BEGIN END INIT CHECK -exec', |
167 | bcopts => [qw/ BEGIN END INIT CHECK -exec /], |
168 | #todo => 'get working', |
169 | prog => $src, |
170 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
171 | # BEGIN 1: |
09e96b99 |
172 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
173 | # 2 <$> const[PV "warnings.pm"] s/BARE |
cc02ea56 |
174 | # 3 <1> require sK/1 |
09e96b99 |
175 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
176 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 |
cc02ea56 |
177 | # 6 <0> pushmark s |
09e96b99 |
178 | # 7 <$> const[PV "warnings"] sM |
179 | # 8 <$> const[PV "qw"] sM |
cc02ea56 |
180 | # 9 <$> method_named[PVIV 1520340202] |
181 | # a <1> entersub[t1] KS*/TARG,2 |
182 | # b <1> leavesub[1 ref] K/REFC,1 |
183 | # BEGIN 2: |
09e96b99 |
184 | # c <;> nextstate(main 2 -e:1) v |
185 | # d <#> gvsv[*beg] s |
186 | # e <1> postinc[t3] sK/1 |
187 | # f <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
188 | # END 1: |
09e96b99 |
189 | # g <;> nextstate(main 5 -e:1) v |
190 | # h <#> gvsv[*end] s |
191 | # i <1> postinc[t3] sK/1 |
192 | # j <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
193 | # INIT 1: |
09e96b99 |
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 |
cc02ea56 |
198 | # CHECK 1: |
09e96b99 |
199 | # o <;> nextstate(main 3 -e:1) v |
200 | # p <#> gvsv[*chk] s |
201 | # q <1> postinc[t3] sK/1 |
202 | # r <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
203 | EOT_EOT |
204 | # BEGIN 1: |
09e96b99 |
205 | # 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
206 | # 2 <$> const(PV "warnings.pm") s/BARE |
cc02ea56 |
207 | # 3 <1> require sK/1 |
09e96b99 |
208 | # 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 |
209 | # 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 |
cc02ea56 |
210 | # 6 <0> pushmark s |
09e96b99 |
211 | # 7 <$> const(PV "warnings") sM |
212 | # 8 <$> const(PV "qw") sM |
cc02ea56 |
213 | # 9 <$> method_named(PVIV 1520340202) |
214 | # a <1> entersub[t1] KS*/TARG,2 |
215 | # b <1> leavesub[1 ref] K/REFC,1 |
216 | # BEGIN 2: |
09e96b99 |
217 | # c <;> nextstate(main 2 -e:1) v |
218 | # d <$> gvsv(*beg) s |
219 | # e <1> postinc[t2] sK/1 |
220 | # f <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
221 | # END 1: |
09e96b99 |
222 | # g <;> nextstate(main 5 -e:1) v |
223 | # h <$> gvsv(*end) s |
224 | # i <1> postinc[t2] sK/1 |
225 | # j <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
226 | # INIT 1: |
09e96b99 |
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 |
cc02ea56 |
231 | # CHECK 1: |
09e96b99 |
232 | # o <;> nextstate(main 3 -e:1) v |
233 | # p <$> gvsv(*chk) s |
234 | # q <1> postinc[t2] sK/1 |
235 | # r <1> leavesub[1 ref] K/REFC,1 |
cc02ea56 |
236 | EONT_EONT |