This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
With shared hash key scalars now accessing the hash via the PVX, you
[perl5.git] / ext / B / t / optree_specials.t
1 #!./perl
2
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
10 BEGIN {
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     }
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     }
23     # require 'test.pl'; # now done by OptreeCheck
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
41 my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }];
42
43
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
51 checkOptree ( name      => 'BEGIN',
52               bcopts    => 'BEGIN',
53               prog      => $src,
54               @warnings_todo,
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
59 # 1        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
60 # 3        <1> require sK/1 ->4
61 # 2           <$> const[PV "warnings.pm"] s/BARE ->3
62 # 4        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
63 # -        <@> lineseq K ->-
64 # 5           <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
65 # a           <1> entersub[t1] KS*/TARG,2 ->b
66 # 6              <0> pushmark s ->7
67 # 7              <$> const[PV "warnings"] sM ->8
68 # 8              <$> const[PV "qw"] sM ->9
69 # 9              <$> method_named[PV "import"] ->a
70 # BEGIN 2:
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
77 EOT_EOT
78 # BEGIN 1:
79 # b  <1> leavesub[1 ref] K/REFC,1 ->(end)
80 # -     <@> lineseq KP ->b
81 # 1        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
82 # 3        <1> require sK/1 ->4
83 # 2           <$> const(PV "warnings.pm") s/BARE ->3
84 # 4        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
85 # -        <@> lineseq K ->-
86 # 5           <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
87 # a           <1> entersub[t1] KS*/TARG,2 ->b
88 # 6              <0> pushmark s ->7
89 # 7              <$> const(PV "warnings") sM ->8
90 # 8              <$> const(PV "qw") sM ->9
91 # 9              <$> method_named(PV "import") ->a
92 # BEGIN 2:
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
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 /],
171               prog      => $src,
172               @warnings_todo,
173               expect    => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
174 # BEGIN 1:
175 # 1  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
176 # 2  <$> const[PV "warnings.pm"] s/BARE
177 # 3  <1> require sK/1
178 # 4  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
179 # 5  <;> nextstate(B::Concise -234 Concise.pm:328) /2
180 # 6  <0> pushmark s
181 # 7  <$> const[PV "warnings"] sM
182 # 8  <$> const[PV "qw"] sM
183 # 9  <$> method_named[PV "unimport"] 
184 # a  <1> entersub[t1] KS*/TARG,2
185 # b  <1> leavesub[1 ref] K/REFC,1
186 # BEGIN 2:
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
191 # END 1:
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
196 # INIT 1:
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
201 # CHECK 1:
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
206 EOT_EOT
207 # BEGIN 1:
208 # 1  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
209 # 2  <$> const(PV "warnings.pm") s/BARE
210 # 3  <1> require sK/1
211 # 4  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
212 # 5  <;> nextstate(B::Concise -234 Concise.pm:328) /2
213 # 6  <0> pushmark s
214 # 7  <$> const(PV "warnings") sM
215 # 8  <$> const(PV "qw") sM
216 # 9  <$> method_named(PV "unimport") 
217 # a  <1> entersub[t1] KS*/TARG,2
218 # b  <1> leavesub[1 ref] K/REFC,1
219 # BEGIN 2:
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
224 # END 1:
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
229 # INIT 1:
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
234 # CHECK 1:
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
239 EONT_EONT