Re: [patch] decrufting OptreeCheck stuff
[p5sagit/p5-mst-13.2.git] / ext / B / t / optree_specials.t
CommitLineData
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 10BEGIN {
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)
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 42
43
cc02ea56 44checkOptree ( name => 'BEGIN',
45 bcopts => 'BEGIN',
46 prog => $src,
47 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
48# BEGIN 1:
49# b <1> leavesub[1 ref] K/REFC,1 ->(end)
50# - <@> lineseq KP ->b
09e96b99 51# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
cc02ea56 52# 3 <1> require sK/1 ->4
09e96b99 53# 2 <$> const[PV "warnings.pm"] s/BARE ->3
54# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
cc02ea56 55# - <@> lineseq K ->-
09e96b99 56# 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
cc02ea56 57# a <1> entersub[t1] KS*/TARG,2 ->b
58# 6 <0> pushmark s ->7
09e96b99 59# 7 <$> const[PV "warnings"] sM ->8
60# 8 <$> const[PV "qw"] sM ->9
cc02ea56 61# 9 <$> method_named[PVIV 1520340202] ->a
62# BEGIN 2:
09e96b99 63# f <1> leavesub[1 ref] K/REFC,1 ->(end)
64# - <@> lineseq KP ->f
65# c <;> nextstate(main 2 -e:1) v ->d
66# e <1> postinc[t3] sK/1 ->f
67# - <1> ex-rv2sv sKRM/1 ->e
68# d <#> gvsv[*beg] s ->e
cc02ea56 69EOT_EOT
70# BEGIN 1:
71# b <1> leavesub[1 ref] K/REFC,1 ->(end)
72# - <@> lineseq KP ->b
09e96b99 73# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
cc02ea56 74# 3 <1> require sK/1 ->4
09e96b99 75# 2 <$> const(PV "warnings.pm") s/BARE ->3
76# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
cc02ea56 77# - <@> lineseq K ->-
09e96b99 78# 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
cc02ea56 79# a <1> entersub[t1] KS*/TARG,2 ->b
80# 6 <0> pushmark s ->7
09e96b99 81# 7 <$> const(PV "warnings") sM ->8
82# 8 <$> const(PV "qw") sM ->9
cc02ea56 83# 9 <$> method_named(PVIV 1520340202) ->a
84# BEGIN 2:
09e96b99 85# f <1> leavesub[1 ref] K/REFC,1 ->(end)
86# - <@> lineseq KP ->f
87# c <;> nextstate(main 2 -e:1) v ->d
88# e <1> postinc[t2] sK/1 ->f
89# - <1> ex-rv2sv sKRM/1 ->e
90# d <$> gvsv(*beg) s ->e
cc02ea56 91EONT_EONT
92
93
94checkOptree ( name => 'END',
95 bcopts => 'END',
96 prog => $src,
97 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
98# END 1:
99# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
100# - <@> lineseq KP ->4
101# 1 <;> nextstate(main 5 -e:6) v ->2
102# 3 <1> postinc[t3] sK/1 ->4
103# - <1> ex-rv2sv sKRM/1 ->3
104# 2 <#> gvsv[*end] s ->3
105EOT_EOT
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[t2] sK/1 ->4
111# - <1> ex-rv2sv sKRM/1 ->3
112# 2 <$> gvsv(*end) s ->3
113EONT_EONT
114
115
116checkOptree ( name => 'CHECK',
117 bcopts => 'CHECK',
118 prog => $src,
119 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
120# CHECK 1:
121# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
122# - <@> lineseq KP ->4
123# 1 <;> nextstate(main 3 -e:4) v ->2
124# 3 <1> postinc[t3] sK/1 ->4
125# - <1> ex-rv2sv sKRM/1 ->3
126# 2 <#> gvsv[*chk] s ->3
127EOT_EOT
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[t2] sK/1 ->4
133# - <1> ex-rv2sv sKRM/1 ->3
134# 2 <$> gvsv(*chk) s ->3
135EONT_EONT
136
137
138checkOptree ( name => 'INIT',
139 bcopts => 'INIT',
140 #todo => 'get working',
141 prog => $src,
142 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
143# INIT 1:
144# 4 <1> leavesub[1 ref] K/REFC,1 ->(end)
145# - <@> lineseq KP ->4
146# 1 <;> nextstate(main 4 -e:5) v ->2
147# 3 <1> postinc[t3] sK/1 ->4
148# - <1> ex-rv2sv sKRM/1 ->3
149# 2 <#> gvsv[*init] s ->3
150EOT_EOT
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[t2] sK/1 ->4
156# - <1> ex-rv2sv sKRM/1 ->3
157# 2 <$> gvsv(*init) s ->3
158EONT_EONT
159
160
161checkOptree ( name => 'all of BEGIN END INIT CHECK -exec',
162 bcopts => [qw/ BEGIN END INIT CHECK -exec /],
163 #todo => 'get working',
164 prog => $src,
165 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
166# BEGIN 1:
09e96b99 167# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
168# 2 <$> const[PV "warnings.pm"] s/BARE
cc02ea56 169# 3 <1> require sK/1
09e96b99 170# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
171# 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2
cc02ea56 172# 6 <0> pushmark s
09e96b99 173# 7 <$> const[PV "warnings"] sM
174# 8 <$> const[PV "qw"] sM
cc02ea56 175# 9 <$> method_named[PVIV 1520340202]
176# a <1> entersub[t1] KS*/TARG,2
177# b <1> leavesub[1 ref] K/REFC,1
178# BEGIN 2:
09e96b99 179# c <;> nextstate(main 2 -e:1) v
180# d <#> gvsv[*beg] s
181# e <1> postinc[t3] sK/1
182# f <1> leavesub[1 ref] K/REFC,1
cc02ea56 183# END 1:
09e96b99 184# g <;> nextstate(main 5 -e:1) v
185# h <#> gvsv[*end] s
186# i <1> postinc[t3] sK/1
187# j <1> leavesub[1 ref] K/REFC,1
cc02ea56 188# INIT 1:
09e96b99 189# k <;> nextstate(main 4 -e:1) v
190# l <#> gvsv[*init] s
191# m <1> postinc[t3] sK/1
192# n <1> leavesub[1 ref] K/REFC,1
cc02ea56 193# CHECK 1:
09e96b99 194# o <;> nextstate(main 3 -e:1) v
195# p <#> gvsv[*chk] s
196# q <1> postinc[t3] sK/1
197# r <1> leavesub[1 ref] K/REFC,1
cc02ea56 198EOT_EOT
199# BEGIN 1:
09e96b99 200# 1 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
201# 2 <$> const(PV "warnings.pm") s/BARE
cc02ea56 202# 3 <1> require sK/1
09e96b99 203# 4 <;> nextstate(B::Concise -234 Concise.pm:328) v/2
204# 5 <;> nextstate(B::Concise -234 Concise.pm:328) /2
cc02ea56 205# 6 <0> pushmark s
09e96b99 206# 7 <$> const(PV "warnings") sM
207# 8 <$> const(PV "qw") sM
cc02ea56 208# 9 <$> method_named(PVIV 1520340202)
209# a <1> entersub[t1] KS*/TARG,2
210# b <1> leavesub[1 ref] K/REFC,1
211# BEGIN 2:
09e96b99 212# c <;> nextstate(main 2 -e:1) v
213# d <$> gvsv(*beg) s
214# e <1> postinc[t2] sK/1
215# f <1> leavesub[1 ref] K/REFC,1
cc02ea56 216# END 1:
09e96b99 217# g <;> nextstate(main 5 -e:1) v
218# h <$> gvsv(*end) s
219# i <1> postinc[t2] sK/1
220# j <1> leavesub[1 ref] K/REFC,1
cc02ea56 221# INIT 1:
09e96b99 222# k <;> nextstate(main 4 -e:1) v
223# l <$> gvsv(*init) s
224# m <1> postinc[t2] sK/1
225# n <1> leavesub[1 ref] K/REFC,1
cc02ea56 226# CHECK 1:
09e96b99 227# o <;> nextstate(main 3 -e:1) v
228# p <$> gvsv(*chk) s
229# q <1> postinc[t2] sK/1
230# r <1> leavesub[1 ref] K/REFC,1
cc02ea56 231EONT_EONT