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 plan tests => 5 + 15 + 16 * $gOpts{selftest}; # pass()s + $#tests
35 skip "no perlio in this build", 5 + 17 + 14 * $gOpts{selftest}
36 unless $Config::Config{useperlio};
39 pass("REGEX TEST HARNESS SELFTEST");
41 checkOptree ( name => "bare minimum opcode search",
44 noanchors => 1, # unanchored match
46 expect_nt => 'leavesub');
48 checkOptree ( name => "found print opcode",
50 code => sub {print 1},
51 noanchors => 1, # unanchored match
53 expect_nt => 'leavesub');
55 checkOptree ( name => 'test skip itself',
56 skip => 'this is skip-reason',
58 code => sub {print 1},
59 expect => 'dont-care, skipping',
60 expect_nt => 'this insures failure');
62 # This test 'unexpectedly succeeds', but that is "expected". Theres
63 # no good way to expect a successful todo, and inducing a failure
64 # causes the harness to print verbose errors, which is NOT helpful.
66 checkOptree ( name => 'test todo itself',
67 todo => "your excuse here ;-)",
69 code => sub {print 1},
70 noanchors => 1, # unanchored match
72 expect_nt => 'print') if 0;
74 checkOptree ( name => 'impossible match, remove skip to see failure',
75 todo => "see! it breaks!",
76 skip => 'skip the failure',
77 code => sub {print 1},
78 expect => 'look out ! Boy Wonder',
79 expect_nt => 'holy near earth asteroid Batman !');
81 pass ("TEST FATAL ERRS");
84 # test for fatal errors. Im unsettled on fail vs die.
85 # calling fail isnt good enough by itself.
89 checkOptree ( name => 'test against empty expectations',
91 code => sub {print 1},
95 like($@, /no '\w+' golden-sample found/, "empty expectations prevented");
99 checkOptree ( name => 'prevent whitespace only expectations',
106 like($@, /no '\w+' golden-sample found/,
107 "just whitespace expectations prevented");
110 pass ("TEST -e \$srcCode");
112 checkOptree ( name => 'empty code or prog',
114 todo => "your excuse here ;-)",
120 ( name => "self strict, catch err",
121 prog => 'use strict; bogus',
122 errs => 'Bareword "bogus" not allowed while "strict subs" in use at -e line 1.',
123 expect => "nextstate", # simple expectations
124 expect_nt => "nextstate",
125 noanchors => 1, # allow them to work
128 checkOptree ( name => "sort lK - flag specific search",
129 prog => 'our (@a,@b); @b = sort @a',
131 expect => '<@> sort lK ',
132 expect_nt => '<@> sort lK ');
134 checkOptree ( name => "sort vK - flag specific search",
135 prog => 'sort our @a',
136 errs => 'Useless use of sort in void context at -e line 1.',
138 expect => '<@> sort vK',
139 expect_nt => '<@> sort vK');
141 checkOptree ( name => "'code' => 'sort our \@a'",
142 code => 'sort our @a',
144 expect => '<@> sort K',
145 expect_nt => '<@> sort K');
147 pass ("REFTEXT FIXUP TESTS");
149 checkOptree ( name => 'fixup nextstate (in reftext)',
152 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
153 # 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v
154 # 2 <0> padsv[$a:54,55] M/LVINTRO
155 # 3 <1> leavesub[1 ref] K/REFC,1
157 # 1 <;> nextstate(main 54 optree_concise.t:84) v
158 # 2 <0> padsv[$a:54,55] M/LVINTRO
159 # 3 <1> leavesub[1 ref] K/REFC,1
162 checkOptree ( name => 'fixup opcode args',
164 #fail => 1, # uncomment to see real padsv args: [$a:491,492]
166 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
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
171 # 1 <;> nextstate(main 56 optree_concise.t:96) v
172 # 2 <0> padsv[$a:56,57] M/LVINTRO
173 # 3 <1> leavesub[1 ref] K/REFC,1
176 #################################
177 pass("CANONICAL B::Concise EXAMPLE");
179 checkOptree ( name => 'canonical example w -basic',
181 code => sub{$a=$b+42},
184 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
185 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
186 # - <@> lineseq KP ->7
187 # 1 <;> nextstate(main 380 optree_selftest.t:139) v ->2
188 # 6 <2> sassign sKS/2 ->7
189 # 4 <2> add[t3] sK/2 ->5
190 # - <1> ex-rv2sv sK/1 ->3
191 # 2 <#> gvsv[*b] s ->3
192 # 3 <$> const[IV 42] s ->4
193 # - <1> ex-rv2sv sKRM*/1 ->6
194 # 5 <#> gvsv[*a] s ->6
196 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
197 # - <@> lineseq KP ->7
198 # 1 <;> nextstate(main 60 optree_concise.t:122) v ->2
199 # 6 <2> sassign sKS/2 ->7
200 # 4 <2> add[t1] 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
208 checkOptree ( code => '$a=$b+42',
210 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
211 # 1 <;> nextstate(main 61 optree_concise.t:139) v
213 # 3 <$> const[IV 42] s
216 # 6 <2> sassign sKS/2
217 # 7 <1> leavesub[1 ref] K/REFC,1
219 # 1 <;> nextstate(main 61 optree_concise.t:139) v
221 # 3 <$> const(IV 42) s
224 # 6 <2> sassign sKS/2
225 # 7 <1> leavesub[1 ref] K/REFC,1