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
CommitLineData
cc02ea56
JC
1#!./perl
2
09e96b99
JC
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 10BEGIN {
5638aaac
SM
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
NC
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
JC
24}
25
26# import checkOptree(), and %gOpts (containing test state)
27use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!!
28use Config;
29
30plan tests => 6;
31
32require_ok("B::Concise");
33
34my $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 41my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }];
cc02ea56
JC
42
43
b8443148
NC
44my @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
JC
51checkOptree ( name => 'BEGIN',
52 bcopts => 'BEGIN',
53 prog => $src,
b8443148 54 @warnings_todo,
cc02ea56
JC
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
JC
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
JC
65# a <1> entersub[t1] KS*/TARG,2 ->b
66# 6 <0> pushmark s ->7
09e96b99
JC
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
JC
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
JC
77EOT_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
JC
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
JC
87# a <1> entersub[t1] KS*/TARG,2 ->b
88# 6 <0> pushmark s ->7
09e96b99
JC
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
JC
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
JC
99EONT_EONT
100
101
102checkOptree ( 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
113EOT_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
121EONT_EONT
122
123
124checkOptree ( 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
135EOT_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
143EONT_EONT
144
145
146checkOptree ( 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
158EOT_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
166EONT_EONT
167
168
169checkOptree ( 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
JC
173 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
174# BEGIN 1:
09e96b99
JC
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
JC
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
JC
181# 7 <$> const[PV "warnings"] sM
182# 8 <$> const[PV "qw"] sM
427d62a4 183# 9 <$> method_named[PV "unimport"]
cc02ea56
JC
184# a <1> entersub[t1] KS*/TARG,2
185# b <1> leavesub[1 ref] K/REFC,1
186# BEGIN 2:
09e96b99
JC
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
JC
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
JC
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
JC
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
JC
206EOT_EOT
207# BEGIN 1:
09e96b99
JC
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
JC
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
JC
214# 7 <$> const(PV "warnings") sM
215# 8 <$> const(PV "qw") sM
427d62a4 216# 9 <$> method_named(PV "unimport")
cc02ea56
JC
217# a <1> entersub[t1] KS*/TARG,2
218# b <1> leavesub[1 ref] K/REFC,1
219# BEGIN 2:
09e96b99
JC
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
JC
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
JC
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
JC
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 239EONT_EONT