Re: [patch] decrufting OptreeCheck stuff
[p5sagit/p5-mst-13.2.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 checkOptree ( 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
51 # 1        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
52 # 3        <1> require sK/1 ->4
53 # 2           <$> const[PV "warnings.pm"] s/BARE ->3
54 # 4        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
55 # -        <@> lineseq K ->-
56 # 5           <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
57 # a           <1> entersub[t1] KS*/TARG,2 ->b
58 # 6              <0> pushmark s ->7
59 # 7              <$> const[PV "warnings"] sM ->8
60 # 8              <$> const[PV "qw"] sM ->9
61 # 9              <$> method_named[PVIV 1520340202] ->a
62 # BEGIN 2:
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
69 EOT_EOT
70 # BEGIN 1:
71 # b  <1> leavesub[1 ref] K/REFC,1 ->(end)
72 # -     <@> lineseq KP ->b
73 # 1        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
74 # 3        <1> require sK/1 ->4
75 # 2           <$> const(PV "warnings.pm") s/BARE ->3
76 # 4        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
77 # -        <@> lineseq K ->-
78 # 5           <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
79 # a           <1> entersub[t1] KS*/TARG,2 ->b
80 # 6              <0> pushmark s ->7
81 # 7              <$> const(PV "warnings") sM ->8
82 # 8              <$> const(PV "qw") sM ->9
83 # 9              <$> method_named(PVIV 1520340202) ->a
84 # BEGIN 2:
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
91 EONT_EONT
92
93
94 checkOptree ( 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
105 EOT_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
113 EONT_EONT
114
115
116 checkOptree ( 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
127 EOT_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
135 EONT_EONT
136
137
138 checkOptree ( 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
150 EOT_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
158 EONT_EONT
159
160
161 checkOptree ( 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:
167 # 1  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
168 # 2  <$> const[PV "warnings.pm"] s/BARE
169 # 3  <1> require sK/1
170 # 4  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
171 # 5  <;> nextstate(B::Concise -234 Concise.pm:328) /2
172 # 6  <0> pushmark s
173 # 7  <$> const[PV "warnings"] sM
174 # 8  <$> const[PV "qw"] sM
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:
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
183 # END 1:
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
188 # INIT 1:
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
193 # CHECK 1:
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
198 EOT_EOT
199 # BEGIN 1:
200 # 1  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
201 # 2  <$> const(PV "warnings.pm") s/BARE
202 # 3  <1> require sK/1
203 # 4  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
204 # 5  <;> nextstate(B::Concise -234 Concise.pm:328) /2
205 # 6  <0> pushmark s
206 # 7  <$> const(PV "warnings") sM
207 # 8  <$> const(PV "qw") sM
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:
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
216 # END 1:
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
221 # INIT 1:
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
226 # CHECK 1:
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
231 EONT_EONT