5 @INC = ('../lib', '../ext/B/t');
11 =head1 OptreeCheck selftest harness
13 This file is primarily to test services of OptreeCheck itself, ie
14 checkOptree(). %gOpts provides test-state info, it is 'exported' into
17 doing use OptreeCheck runs import(), which processes @ARGV to process
18 cmdline args in 'standard' way across all clients of OptreeCheck.
23 plan tests => 5 + 18 + 14 * $gOpts{selftest}; # fudged
26 skip "no perlio in this build", 5 + 19 + 14 * $gOpts{selftest}
27 unless $Config::Config{useperlio};
30 pass("REGEX TEST HARNESS SELFTEST");
32 checkOptree ( name => "bare minimum opcode search",
35 noanchors => 1, # unanchored match
37 expect_nt => 'leavesub');
39 checkOptree ( name => "found print opcode",
41 code => sub {print 1},
42 noanchors => 1, # unanchored match
44 expect_nt => 'leavesub');
46 checkOptree ( name => 'test skip itself',
49 code => sub {print 1},
50 expect => 'dont-care, skipping',
51 expect_nt => 'this insures failure');
53 checkOptree ( name => 'test todo itself',
54 todo => "your excuse here ;-)",
56 code => sub {print 1},
57 noanchors => 1, # unanchored match
59 expect_nt => 'print');
61 checkOptree ( name => 'impossible match, remove skip to see failure',
62 todo => "see! it breaks!",
63 skip => 1, # but skip it 1st
64 code => sub {print 1},
65 expect => 'look out ! Boy Wonder',
66 expect_nt => 'holy near earth asteroid Batman !');
68 pass ("TEST FATAL ERRS");
71 # test for fatal errors. Im unsettled on fail vs die.
72 # calling fail isnt good enough by itself.
75 checkOptree ( name => 'empty code or prog',
76 todo => "your excuse here ;-)",
81 like($@, 'code or prog is required', 'empty code or prog prevented');
85 checkOptree ( name => 'test against empty expectations',
87 code => sub {print 1},
91 like($@, 'no reftext found for', "empty expectations prevented");
95 checkOptree ( name => 'prevent whitespace only expectations',
102 like($@, 'no reftext found for', "just whitespace expectations prevented");
105 pass ("TEST -e \$srcCode");
107 checkOptree ( name => '-w errors seen',
108 prog => 'sort our @a',
109 noanchors => 1, # unanchored match
110 expect => 'Useless use of sort in void context',
111 expect_nt => 'Useless use of sort in void context');
113 checkOptree ( name => "self strict, catch err",
114 prog => 'use strict; bogus',
116 expect => 'strict subs',
117 expect_nt => 'strict subs');
119 checkOptree ( name => "sort vK - flag specific search",
120 prog => 'sort our @a',
122 expect => '<@> sort vK ',
123 expect_nt => '<@> sort vK ');
125 checkOptree ( name => "'prog' => 'sort our \@a'",
126 prog => 'sort our @a',
128 expect => '<@> sort vK',
129 expect_nt => '<@> sort vK');
131 checkOptree ( name => "'code' => 'sort our \@a'",
132 code => 'sort our @a',
134 expect => '<@> sort K',
135 expect_nt => '<@> sort K');
137 pass ("REFTEXT FIXUP TESTS");
139 checkOptree ( name => 'fixup nextstate (in reftext)',
142 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
143 # 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v
144 # 2 <0> padsv[$a:54,55] M/LVINTRO
145 # 3 <1> leavesub[1 ref] K/REFC,1
147 # 1 <;> nextstate(main 54 optree_concise.t:84) v
148 # 2 <0> padsv[$a:54,55] M/LVINTRO
149 # 3 <1> leavesub[1 ref] K/REFC,1
152 checkOptree ( name => 'fixup square-bracket args',
154 todo => 'not done in rexpedant mode',
157 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
158 # 1 <;> nextstate(main 56 optree_concise.t:96) v
159 # 2 <0> padsv[$a:56,57] M/LVINTRO
160 # 3 <1> leavesub[1 ref] K/REFC,1
162 # 1 <;> nextstate(main 56 optree_concise.t:96) v
163 # 2 <0> padsv[$a:56,57] M/LVINTRO
164 # 3 <1> leavesub[1 ref] K/REFC,1
167 #################################
168 pass("CANONICAL B::Concise EXAMPLE");
170 checkOptree ( name => 'canonical example w -basic',
172 code => sub{$a=$b+42},
175 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
176 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
177 # - <@> lineseq KP ->7
178 # 1 <;> nextstate(main 380 optree_selftest.t:139) v ->2
179 # 6 <2> sassign sKS/2 ->7
180 # 4 <2> add[t3] sK/2 ->5
181 # - <1> ex-rv2sv sK/1 ->3
182 # 2 <#> gvsv[*b] s ->3
183 # 3 <$> const[IV 42] s ->4
184 # - <1> ex-rv2sv sKRM*/1 ->6
185 # 5 <#> gvsv[*a] s ->6
187 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
188 # - <@> lineseq KP ->7
189 # 1 <;> nextstate(main 60 optree_concise.t:122) v ->2
190 # 6 <2> sassign sKS/2 ->7
191 # 4 <2> add[t1] sK/2 ->5
192 # - <1> ex-rv2sv sK/1 ->3
193 # 2 <$> gvsv(*b) s ->3
194 # 3 <$> const(IV 42) s ->4
195 # - <1> ex-rv2sv sKRM*/1 ->6
196 # 5 <$> gvsv(*a) s ->6
199 checkOptree ( name => 'canonical example w -exec',
201 code => sub{$a=$b+42},
206 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
207 # 1 <;> nextstate(main 61 optree_concise.t:139) v
209 # 3 <$> const[IV 42] s
212 # 6 <2> sassign sKS/2
213 # 7 <1> leavesub[1 ref] K/REFC,1
215 # 1 <;> nextstate(main 61 optree_concise.t:139) v
217 # 3 <$> const(IV 42) s
220 # 6 <2> sassign sKS/2
221 # 7 <1> leavesub[1 ref] K/REFC,1
224 checkOptree ( name => 'tree reftext is messy cut-paste',