Integrate:
[p5sagit/p5-mst-13.2.git] / ext / B / t / optree_check.t
CommitLineData
724aa791 1#!perl
2
3BEGIN {
4 chdir 't';
5 @INC = ('../lib', '../ext/B/t');
9cd8f857 6 require Config;
7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
9 exit 0;
10 }
724aa791 11 require './test.pl';
12}
13
14use OptreeCheck;
15
16=head1 OptreeCheck selftest harness
17
18This file is primarily to test services of OptreeCheck itself, ie
19checkOptree(). %gOpts provides test-state info, it is 'exported' into
20main::
21
22doing use OptreeCheck runs import(), which processes @ARGV to process
23cmdline args in 'standard' way across all clients of OptreeCheck.
24
25=cut
26
2ce64696 27use Config;
cc02ea56 28plan tests => 5 + 18 + 14 * $gOpts{selftest}; # fudged
724aa791 29
2ce64696 30SKIP: {
e77e2f14 31 skip "no perlio in this build", 5 + 18 + 14 * $gOpts{selftest}
2ce64696 32 unless $Config::Config{useperlio};
33
34
724aa791 35pass("REGEX TEST HARNESS SELFTEST");
36
37checkOptree ( name => "bare minimum opcode search",
38 bcopts => '-exec',
39 code => sub {my $a},
cc02ea56 40 noanchors => 1, # unanchored match
724aa791 41 expect => 'leavesub',
42 expect_nt => 'leavesub');
43
44checkOptree ( name => "found print opcode",
45 bcopts => '-exec',
46 code => sub {print 1},
cc02ea56 47 noanchors => 1, # unanchored match
724aa791 48 expect => 'print',
49 expect_nt => 'leavesub');
50
51checkOptree ( name => 'test skip itself',
52 skip => 1,
53 bcopts => '-exec',
54 code => sub {print 1},
55 expect => 'dont-care, skipping',
56 expect_nt => 'this insures failure');
57
58checkOptree ( name => 'test todo itself',
59 todo => "your excuse here ;-)",
60 bcopts => '-exec',
61 code => sub {print 1},
cc02ea56 62 noanchors => 1, # unanchored match
724aa791 63 expect => 'print',
64 expect_nt => 'print');
65
66checkOptree ( name => 'impossible match, remove skip to see failure',
67 todo => "see! it breaks!",
68 skip => 1, # but skip it 1st
69 code => sub {print 1},
70 expect => 'look out ! Boy Wonder',
71 expect_nt => 'holy near earth asteroid Batman !');
72
73pass ("TEST FATAL ERRS");
74
75if (1) {
76 # test for fatal errors. Im unsettled on fail vs die.
77 # calling fail isnt good enough by itself.
78 eval {
79
80 checkOptree ( name => 'empty code or prog',
81 todo => "your excuse here ;-)",
82 code => '',
83 prog => '',
84 );
85 };
86 like($@, 'code or prog is required', 'empty code or prog prevented');
87
88 $@='';
89 eval {
90 checkOptree ( name => 'test against empty expectations',
91 bcopts => '-exec',
92 code => sub {print 1},
93 expect => '',
94 expect_nt => '');
95 };
96 like($@, 'no reftext found for', "empty expectations prevented");
97
98 $@='';
99 eval {
100 checkOptree ( name => 'prevent whitespace only expectations',
101 bcopts => '-exec',
102 code => sub {my $a},
103 #skip => 1,
104 expect_nt => "\n",
105 expect => "\n");
106 };
107 like($@, 'no reftext found for', "just whitespace expectations prevented");
108}
109
110pass ("TEST -e \$srcCode");
111
112checkOptree ( name => '-w errors seen',
113 prog => 'sort our @a',
cc02ea56 114 noanchors => 1, # unanchored match
724aa791 115 expect => 'Useless use of sort in void context',
116 expect_nt => 'Useless use of sort in void context');
117
118checkOptree ( name => "self strict, catch err",
119 prog => 'use strict; bogus',
cc02ea56 120 noanchors => 1,
724aa791 121 expect => 'strict subs',
122 expect_nt => 'strict subs');
123
124checkOptree ( name => "sort vK - flag specific search",
125 prog => 'sort our @a',
cc02ea56 126 noanchors => 1,
724aa791 127 expect => '<@> sort vK ',
128 expect_nt => '<@> sort vK ');
129
130checkOptree ( name => "'prog' => 'sort our \@a'",
131 prog => 'sort our @a',
cc02ea56 132 noanchors => 1,
724aa791 133 expect => '<@> sort vK',
134 expect_nt => '<@> sort vK');
135
136checkOptree ( name => "'code' => 'sort our \@a'",
137 code => 'sort our @a',
cc02ea56 138 noanchors => 1,
724aa791 139 expect => '<@> sort K',
140 expect_nt => '<@> sort K');
141
142pass ("REFTEXT FIXUP TESTS");
143
144checkOptree ( name => 'fixup nextstate (in reftext)',
145 bcopts => '-exec',
146 code => sub {my $a},
147 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
724aa791 148# 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v
149# 2 <0> padsv[$a:54,55] M/LVINTRO
150# 3 <1> leavesub[1 ref] K/REFC,1
151EOT_EOT
724aa791 152# 1 <;> nextstate(main 54 optree_concise.t:84) v
153# 2 <0> padsv[$a:54,55] M/LVINTRO
154# 3 <1> leavesub[1 ref] K/REFC,1
155EONT_EONT
156
157checkOptree ( name => 'fixup square-bracket args',
158 bcopts => '-exec',
159 todo => 'not done in rexpedant mode',
160 code => sub {my $a},
161 #skip => 1,
162 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
724aa791 163# 1 <;> nextstate(main 56 optree_concise.t:96) v
164# 2 <0> padsv[$a:56,57] M/LVINTRO
165# 3 <1> leavesub[1 ref] K/REFC,1
166EOT_EOT
724aa791 167# 1 <;> nextstate(main 56 optree_concise.t:96) v
168# 2 <0> padsv[$a:56,57] M/LVINTRO
169# 3 <1> leavesub[1 ref] K/REFC,1
170EONT_EONT
171
724aa791 172#################################
173pass("CANONICAL B::Concise EXAMPLE");
174
175checkOptree ( name => 'canonical example w -basic',
176 bcopts => '-basic',
177 code => sub{$a=$b+42},
178 crossfail => 1,
179 debug => 1,
180 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
181# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
182# - <@> lineseq KP ->7
183# 1 <;> nextstate(main 380 optree_selftest.t:139) v ->2
184# 6 <2> sassign sKS/2 ->7
185# 4 <2> add[t3] sK/2 ->5
186# - <1> ex-rv2sv sK/1 ->3
187# 2 <#> gvsv[*b] s ->3
188# 3 <$> const[IV 42] s ->4
189# - <1> ex-rv2sv sKRM*/1 ->6
190# 5 <#> gvsv[*a] s ->6
191EOT_EOT
192# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
193# - <@> lineseq KP ->7
194# 1 <;> nextstate(main 60 optree_concise.t:122) v ->2
195# 6 <2> sassign sKS/2 ->7
196# 4 <2> add[t1] sK/2 ->5
197# - <1> ex-rv2sv sK/1 ->3
198# 2 <$> gvsv(*b) s ->3
199# 3 <$> const(IV 42) s ->4
200# - <1> ex-rv2sv sKRM*/1 ->6
201# 5 <$> gvsv(*a) s ->6
202EONT_EONT
203
204checkOptree ( name => 'canonical example w -exec',
205 bcopts => '-exec',
206 code => sub{$a=$b+42},
207 crossfail => 1,
208 retry => 1,
209 debug => 1,
210 xtestfail => 1,
211 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
724aa791 212# 1 <;> nextstate(main 61 optree_concise.t:139) v
213# 2 <#> gvsv[*b] s
214# 3 <$> const[IV 42] s
215# 4 <2> add[t3] sK/2
216# 5 <#> gvsv[*a] s
217# 6 <2> sassign sKS/2
218# 7 <1> leavesub[1 ref] K/REFC,1
219EOT_EOT
724aa791 220# 1 <;> nextstate(main 61 optree_concise.t:139) v
221# 2 <$> gvsv(*b) s
222# 3 <$> const(IV 42) s
223# 4 <2> add[t1] sK/2
224# 5 <$> gvsv(*a) s
225# 6 <2> sassign sKS/2
226# 7 <1> leavesub[1 ref] K/REFC,1
227EONT_EONT
228
229checkOptree ( name => 'tree reftext is messy cut-paste',
230 skip => 1);
231
2ce64696 232} # skip
724aa791 233
234__END__
235