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 + 19 + 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 checkOptree ( name => 'test todo itself',
59 todo => "your excuse here ;-)",
61 code => sub {print 1},
62 noanchors => 1, # unanchored match
64 expect_nt => 'print');
66 checkOptree ( 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 !');
73 pass ("TEST FATAL ERRS");
76 # test for fatal errors. Im unsettled on fail vs die.
77 # calling fail isnt good enough by itself.
80 checkOptree ( name => 'empty code or prog',
81 todo => "your excuse here ;-)",
86 like($@, 'code or prog is required', 'empty code or prog prevented');
90 checkOptree ( name => 'test against empty expectations',
92 code => sub {print 1},
96 like($@, 'no reftext found for', "empty expectations prevented");
100 checkOptree ( name => 'prevent whitespace only expectations',
107 like($@, 'no reftext found for', "just whitespace expectations prevented");
110 pass ("TEST -e \$srcCode");
112 checkOptree ( name => '-w errors seen',
113 prog => 'sort our @a',
114 noanchors => 1, # unanchored match
115 expect => 'Useless use of sort in void context',
116 expect_nt => 'Useless use of sort in void context');
118 checkOptree ( name => "self strict, catch err",
119 prog => 'use strict; bogus',
121 expect => 'strict subs',
122 expect_nt => 'strict subs');
124 checkOptree ( name => "sort vK - flag specific search",
125 prog => 'sort our @a',
127 expect => '<@> sort vK ',
128 expect_nt => '<@> sort vK ');
130 checkOptree ( name => "'prog' => 'sort our \@a'",
131 prog => 'sort our @a',
133 expect => '<@> sort vK',
134 expect_nt => '<@> sort vK');
136 checkOptree ( name => "'code' => 'sort our \@a'",
137 code => 'sort our @a',
139 expect => '<@> sort K',
140 expect_nt => '<@> sort K');
142 pass ("REFTEXT FIXUP TESTS");
144 checkOptree ( name => 'fixup nextstate (in reftext)',
147 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
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
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
157 checkOptree ( name => 'fixup square-bracket args',
159 todo => 'not done in rexpedant mode',
162 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
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
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
172 #################################
173 pass("CANONICAL B::Concise EXAMPLE");
175 checkOptree ( name => 'canonical example w -basic',
177 code => sub{$a=$b+42},
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
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
204 checkOptree ( name => 'canonical example w -exec',
206 code => sub{$a=$b+42},
211 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
212 # 1 <;> nextstate(main 61 optree_concise.t:139) v
214 # 3 <$> const[IV 42] s
217 # 6 <2> sassign sKS/2
218 # 7 <1> leavesub[1 ref] K/REFC,1
220 # 1 <;> nextstate(main 61 optree_concise.t:139) v
222 # 3 <$> const(IV 42) s
225 # 6 <2> sassign sKS/2
226 # 7 <1> leavesub[1 ref] K/REFC,1
229 checkOptree ( name => 'tree reftext is messy cut-paste',