5 @INC = ('../lib', '../ext/B/t');
7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
16 =head1 OptreeCheck selftest harness
18 This file is primarily to test services of OptreeCheck itself, ie
19 checkOptree(). %gOpts provides test-state info, it is 'exported' into
22 doing use OptreeCheck runs import(), which processes @ARGV to process
23 cmdline args in 'standard' way across all clients of OptreeCheck.
28 plan tests => 5 + 18 + 14 * $gOpts{selftest}; # fudged
31 skip "no perlio in this build", 5 + 18 + 14 * $gOpts{selftest}
32 unless $Config::Config{useperlio};
35 pass("REGEX TEST HARNESS SELFTEST");
37 checkOptree ( name => "bare minimum opcode search",
40 noanchors => 1, # unanchored match
42 expect_nt => 'leavesub');
44 checkOptree ( name => "found print opcode",
46 code => sub {print 1},
47 noanchors => 1, # unanchored match
49 expect_nt => 'leavesub');
51 checkOptree ( name => 'test skip itself',
54 code => sub {print 1},
55 expect => 'dont-care, skipping',
56 expect_nt => 'this insures failure');
58 # This test 'unexpectedly succeeds', but that is "expected". Theres
59 # no good way to expect a successful todo, and inducing a failure
60 # causes the harness to print verbose errors, which is NOT helpful.
62 checkOptree ( name => 'test todo itself. suppressed, remove skip to test',
63 todo => "suppress todo test for now",
66 code => sub {print 1},
67 noanchors => 1, # unanchored match
69 expect_nt => 'print');
71 checkOptree ( name => 'impossible match, remove skip to see failure',
72 todo => "see! it breaks!",
73 skip => 1, # but skip it 1st
74 code => sub {print 1},
75 expect => 'look out ! Boy Wonder',
76 expect_nt => 'holy near earth asteroid Batman !');
78 pass ("TEST FATAL ERRS");
81 # test for fatal errors. Im unsettled on fail vs die.
82 # calling fail isnt good enough by itself.
85 checkOptree ( name => 'empty code or prog',
86 todo => "your excuse here ;-)",
91 like($@, 'code or prog is required', 'empty code or prog prevented');
95 checkOptree ( name => 'test against empty expectations',
97 code => sub {print 1},
101 like($@, 'no reftext found for', "empty expectations prevented");
105 checkOptree ( name => 'prevent whitespace only expectations',
112 like($@, 'no reftext found for', "just whitespace expectations prevented");
115 pass ("TEST -e \$srcCode");
118 ( name => '-w errors seen',
119 prog => 'sort our @a',
120 errs => 'Useless use of sort in void context at -e line 1.',
124 ( name => "self strict, catch err",
125 prog => 'use strict; bogus',
126 errs => 'Bareword "bogus" not allowed while "strict subs" in use at -e line 1.',
129 checkOptree ( name => "sort vK - flag specific search",
130 prog => 'sort our @a',
132 expect => '<@> sort vK ',
133 expect_nt => '<@> sort vK ');
135 checkOptree ( name => "'prog' => 'sort our \@a'",
136 prog => 'sort our @a',
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 ( name => 'canonical example w -exec',
210 code => sub{$a=$b+42},
215 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
216 # 1 <;> nextstate(main 61 optree_concise.t:139) v
218 # 3 <$> const[IV 42] s
221 # 6 <2> sassign sKS/2
222 # 7 <1> leavesub[1 ref] K/REFC,1
224 # 1 <;> nextstate(main 61 optree_concise.t:139) v
226 # 3 <$> const(IV 42) s
229 # 6 <2> sassign sKS/2
230 # 7 <1> leavesub[1 ref] K/REFC,1
233 checkOptree ( name => 'tree reftext is messy cut-paste',