6 @INC = ('.', '../lib', '../ext/B/t');
12 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
13 print "1..0 # Skip -- Perl configured without B module\n";
16 # require 'test.pl'; # now done by OptreeCheck
21 =head1 OptreeCheck selftest harness
23 This file is primarily to test services of OptreeCheck itself, ie
24 checkOptree(). %gOpts provides test-state info, it is 'exported' into
27 doing use OptreeCheck runs import(), which processes @ARGV to process
28 cmdline args in 'standard' way across all clients of OptreeCheck.
32 my $tests = 5 + 15 + 16 * $gOpts{selftest}; # pass()s + $#tests
36 skip "no perlio in this build", $tests
37 unless $Config::Config{useperlio};
41 if (((caller 0)[10]||{})->{open}) {
42 @open_todo = (skip => "\$^OPEN is set");
47 pass("REGEX TEST HARNESS SELFTEST");
49 checkOptree ( name => "bare minimum opcode search",
52 noanchors => 1, # unanchored match
54 expect_nt => 'leavesub');
56 checkOptree ( name => "found print opcode",
58 code => sub {print 1},
59 noanchors => 1, # unanchored match
61 expect_nt => 'leavesub');
63 checkOptree ( name => 'test skip itself',
64 skip => 'this is skip-reason',
66 code => sub {print 1},
67 expect => 'dont-care, skipping',
68 expect_nt => 'this insures failure');
70 # This test 'unexpectedly succeeds', but that is "expected". Theres
71 # no good way to expect a successful todo, and inducing a failure
72 # causes the harness to print verbose errors, which is NOT helpful.
74 checkOptree ( name => 'test todo itself',
75 todo => "your excuse here ;-)",
77 code => sub {print 1},
78 noanchors => 1, # unanchored match
80 expect_nt => 'print') if 0;
82 checkOptree ( name => 'impossible match, remove skip to see failure',
83 todo => "see! it breaks!",
84 skip => 'skip the failure',
85 code => sub {print 1},
86 expect => 'look out ! Boy Wonder',
87 expect_nt => 'holy near earth asteroid Batman !');
89 pass ("TEST FATAL ERRS");
92 # test for fatal errors. Im unsettled on fail vs die.
93 # calling fail isnt good enough by itself.
97 checkOptree ( name => 'test against empty expectations',
99 code => sub {print 1},
103 like($@, /no '\w+' golden-sample found/, "empty expectations prevented");
107 checkOptree ( name => 'prevent whitespace only expectations',
114 like($@, /no '\w+' golden-sample found/,
115 "just whitespace expectations prevented");
118 pass ("TEST -e \$srcCode");
120 checkOptree ( name => 'empty code or prog',
122 todo => "your excuse here ;-)",
128 ( name => "self strict, catch err",
129 prog => 'use strict; bogus',
130 errs => 'Bareword "bogus" not allowed while "strict subs" in use at -e line 1.',
131 expect => "nextstate", # simple expectations
132 expect_nt => "nextstate",
133 noanchors => 1, # allow them to work
136 checkOptree ( name => "sort lK - flag specific search",
137 prog => 'our (@a,@b); @b = sort @a',
139 expect => '<@> sort lK ',
140 expect_nt => '<@> sort lK ');
142 checkOptree ( name => "sort vK - flag specific search",
143 prog => 'sort our @a',
144 errs => 'Useless use of sort in void context at -e line 1.',
146 expect => '<@> sort vK',
147 expect_nt => '<@> sort vK');
149 checkOptree ( name => "'code' => 'sort our \@a'",
150 code => 'sort our @a',
152 expect => '<@> sort K',
153 expect_nt => '<@> sort K');
155 pass ("REFTEXT FIXUP TESTS");
157 checkOptree ( name => 'fixup nextstate (in reftext)',
161 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
162 # 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v
163 # 2 <0> padsv[$a:54,55] M/LVINTRO
164 # 3 <1> leavesub[1 ref] K/REFC,1
166 # 1 <;> nextstate(main 54 optree_concise.t:84) v
167 # 2 <0> padsv[$a:54,55] M/LVINTRO
168 # 3 <1> leavesub[1 ref] K/REFC,1
171 checkOptree ( name => 'fixup opcode args',
173 #fail => 1, # uncomment to see real padsv args: [$a:491,492]
176 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
177 # 1 <;> nextstate(main 56 optree_concise.t:96) v
178 # 2 <0> padsv[$a:56,57] M/LVINTRO
179 # 3 <1> leavesub[1 ref] K/REFC,1
181 # 1 <;> nextstate(main 56 optree_concise.t:96) v
182 # 2 <0> padsv[$a:56,57] M/LVINTRO
183 # 3 <1> leavesub[1 ref] K/REFC,1
186 #################################
187 pass("CANONICAL B::Concise EXAMPLE");
189 checkOptree ( name => 'canonical example w -basic',
191 code => sub{$a=$b+42},
195 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
196 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
197 # - <@> lineseq KP ->7
198 # 1 <;> nextstate(main 380 optree_selftest.t:139) v:{ ->2
199 # 6 <2> sassign sKS/2 ->7
200 # 4 <2> add[t3] sK/2 ->5
201 # - <1> ex-rv2sv sK/1 ->3
202 # 2 <#> gvsv[*b] s ->3
203 # 3 <$> const[IV 42] s ->4
204 # - <1> ex-rv2sv sKRM*/1 ->6
205 # 5 <#> gvsv[*a] s ->6
207 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
208 # - <@> lineseq KP ->7
209 # 1 <;> nextstate(main 60 optree_concise.t:122) v:{ ->2
210 # 6 <2> sassign sKS/2 ->7
211 # 4 <2> add[t1] sK/2 ->5
212 # - <1> ex-rv2sv sK/1 ->3
213 # 2 <$> gvsv(*b) s ->3
214 # 3 <$> const(IV 42) s ->4
215 # - <1> ex-rv2sv sKRM*/1 ->6
216 # 5 <$> gvsv(*a) s ->6
219 checkOptree ( code => '$a=$b+42',
221 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
222 # 1 <;> nextstate(main 61 optree_concise.t:139) v:{
224 # 3 <$> const[IV 42] s
227 # 6 <2> sassign sKS/2
228 # 7 <1> leavesub[1 ref] K/REFC,1
230 # 1 <;> nextstate(main 61 optree_concise.t:139) v:{
232 # 3 <$> const(IV 42) s
235 # 6 <2> sassign sKS/2
236 # 7 <1> leavesub[1 ref] K/REFC,1