Re: [PATCH] Remove Carp from warnings.pm
[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     if ($Config::Config{'extensions'} !~ /\bData\/Dumper\b/) {
24         print
25             "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n";
26         exit 0;
27     }
28     require 'test.pl';
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
46 my $src = q[our ($beg, $chk, $init, $end) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ }];
47
48
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
56 # 1        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
57 # 3        <1> require sK/1 ->4
58 # 2           <$> const[PV "warnings.pm"] s/BARE ->3
59 # 4        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
60 # -        <@> lineseq K ->-
61 # 5           <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
62 # a           <1> entersub[t1] KS*/TARG,2 ->b
63 # 6              <0> pushmark s ->7
64 # 7              <$> const[PV "warnings"] sM ->8
65 # 8              <$> const[PV "qw"] sM ->9
66 # 9              <$> method_named[PVIV 1520340202] ->a
67 # BEGIN 2:
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
74 EOT_EOT
75 # BEGIN 1:
76 # b  <1> leavesub[1 ref] K/REFC,1 ->(end)
77 # -     <@> lineseq KP ->b
78 # 1        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->2
79 # 3        <1> require sK/1 ->4
80 # 2           <$> const(PV "warnings.pm") s/BARE ->3
81 # 4        <;> nextstate(B::Concise -234 Concise.pm:328) v/2 ->5
82 # -        <@> lineseq K ->-
83 # 5           <;> nextstate(B::Concise -234 Concise.pm:328) /2 ->6
84 # a           <1> entersub[t1] KS*/TARG,2 ->b
85 # 6              <0> pushmark s ->7
86 # 7              <$> const(PV "warnings") sM ->8
87 # 8              <$> const(PV "qw") sM ->9
88 # 9              <$> method_named(PVIV 1520340202) ->a
89 # BEGIN 2:
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
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:
172 # 1  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
173 # 2  <$> const[PV "warnings.pm"] s/BARE
174 # 3  <1> require sK/1
175 # 4  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
176 # 5  <;> nextstate(B::Concise -234 Concise.pm:328) /2
177 # 6  <0> pushmark s
178 # 7  <$> const[PV "warnings"] sM
179 # 8  <$> const[PV "qw"] sM
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:
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
188 # END 1:
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
193 # INIT 1:
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
198 # CHECK 1:
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
203 EOT_EOT
204 # BEGIN 1:
205 # 1  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
206 # 2  <$> const(PV "warnings.pm") s/BARE
207 # 3  <1> require sK/1
208 # 4  <;> nextstate(B::Concise -234 Concise.pm:328) v/2
209 # 5  <;> nextstate(B::Concise -234 Concise.pm:328) /2
210 # 6  <0> pushmark s
211 # 7  <$> const(PV "warnings") sM
212 # 8  <$> const(PV "qw") sM
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:
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
221 # END 1:
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
226 # INIT 1:
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
231 # CHECK 1:
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
236 EONT_EONT