6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
10 if (!$Config::Config{useperlio}) {
11 print "1..0 # Skip -- need perlio to walk the optree\n";
18 =head1 OptreeCheck selftest harness
20 This file is primarily to test services of OptreeCheck itself, ie
21 checkOptree(). %gOpts provides test-state info, it is 'exported' into
24 doing use OptreeCheck runs import(), which processes @ARGV to process
25 cmdline args in 'standard' way across all clients of OptreeCheck.
29 plan tests => 11 # REGEX TEST HARNESS SELFTEST
31 + 11 # TEST -e \$srcCode
32 + 5 # REFTEXT FIXUP TESTS
33 + 5 # CANONICAL B::Concise EXAMPLE
34 + 16 * $gOpts{selftest}; # XXX I don't understand this - DAPM
36 pass("REGEX TEST HARNESS SELFTEST");
38 checkOptree ( name => "bare minimum opcode search",
41 noanchors => 1, # unanchored match
43 expect_nt => 'leavesub');
45 checkOptree ( name => "found print opcode",
47 code => sub {print 1},
48 noanchors => 1, # unanchored match
50 expect_nt => 'leavesub');
52 checkOptree ( name => 'test skip itself',
53 skip => 'this is skip-reason',
55 code => sub {print 1},
56 expect => 'dont-care, skipping',
57 expect_nt => 'this insures failure');
59 # This test 'unexpectedly succeeds', but that is "expected". Theres
60 # no good way to expect a successful todo, and inducing a failure
61 # causes the harness to print verbose errors, which is NOT helpful.
63 checkOptree ( name => 'test todo itself',
64 todo => "your excuse here ;-)",
66 code => sub {print 1},
67 noanchors => 1, # unanchored match
69 expect_nt => 'print') if 0;
71 checkOptree ( name => 'impossible match, remove skip to see failure',
72 todo => "see! it breaks!",
73 skip => 'skip the failure',
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.
86 checkOptree ( name => 'test against empty expectations',
88 code => sub {print 1},
92 like($@, qr/no '\w+' golden-sample found/, "empty expectations prevented");
96 checkOptree ( name => 'prevent whitespace only expectations',
103 like($@, qr/whitespace only reftext found for '\w+'/,
104 "just whitespace expectations prevented");
107 pass ("TEST -e \$srcCode");
109 checkOptree ( name => 'empty code or prog',
111 todo => "your excuse here ;-)",
117 ( name => "self strict, catch err",
118 prog => 'use strict; bogus',
119 errs => 'Bareword "bogus" not allowed while "strict subs" in use at -e line 1.',
120 expect => "nextstate", # simple expectations
121 expect_nt => "nextstate",
122 noanchors => 1, # allow them to work
125 checkOptree ( name => "sort lK - flag specific search",
126 prog => 'our (@a,@b); @b = sort @a',
128 expect => '<@> sort lK ',
129 expect_nt => '<@> sort lK ');
131 checkOptree ( name => "sort vK - flag specific search",
132 prog => 'sort our @a',
133 errs => 'Useless use of sort in void context at -e line 1.',
135 expect => '<@> sort vK',
136 expect_nt => '<@> sort vK');
138 checkOptree ( name => "'code' => 'sort our \@a'",
139 code => 'sort our @a',
141 expect => '<@> sort K',
142 expect_nt => '<@> sort K');
144 pass ("REFTEXT FIXUP TESTS");
146 checkOptree ( name => 'fixup nextstate (in reftext)',
149 strip_open_hints => 1,
150 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
151 # 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v:>,<,%
152 # 2 <0> padsv[$a:54,55] M/LVINTRO
153 # 3 <1> leavesub[1 ref] K/REFC,1
155 # 1 <;> nextstate(main 54 optree_concise.t:84) v:>,<,%
156 # 2 <0> padsv[$a:54,55] M/LVINTRO
157 # 3 <1> leavesub[1 ref] K/REFC,1
160 checkOptree ( name => 'fixup opcode args',
162 #fail => 1, # uncomment to see real padsv args: [$a:491,492]
164 strip_open_hints => 1,
165 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
166 # 1 <;> nextstate(main 56 optree_concise.t:96) v:>,<,%
167 # 2 <0> padsv[$a:56,57] M/LVINTRO
168 # 3 <1> leavesub[1 ref] K/REFC,1
170 # 1 <;> nextstate(main 56 optree_concise.t:96) v:>,<,%
171 # 2 <0> padsv[$a:56,57] M/LVINTRO
172 # 3 <1> leavesub[1 ref] K/REFC,1
175 #################################
176 pass("CANONICAL B::Concise EXAMPLE");
178 checkOptree ( name => 'canonical example w -basic',
180 code => sub{$a=$b+42},
182 strip_open_hints => 1,
183 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
184 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
185 # - <@> lineseq KP ->7
186 # 1 <;> nextstate(main 380 optree_selftest.t:139) v:>,<,%,{ ->2
187 # 6 <2> sassign sKS/2 ->7
188 # 4 <2> add[t3] sK/2 ->5
189 # - <1> ex-rv2sv sK/1 ->3
190 # 2 <#> gvsv[*b] s ->3
191 # 3 <$> const[IV 42] s ->4
192 # - <1> ex-rv2sv sKRM*/1 ->6
193 # 5 <#> gvsv[*a] s ->6
195 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
196 # - <@> lineseq KP ->7
197 # 1 <;> nextstate(main 60 optree_concise.t:122) v:>,<,%,{ ->2
198 # 6 <2> sassign sKS/2 ->7
199 # 4 <2> add[t1] sK/2 ->5
200 # - <1> ex-rv2sv sK/1 ->3
201 # 2 <$> gvsv(*b) s ->3
202 # 3 <$> const(IV 42) s ->4
203 # - <1> ex-rv2sv sKRM*/1 ->6
204 # 5 <$> gvsv(*a) s ->6
207 checkOptree ( code => '$a=$b+42',
209 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
210 # 1 <;> nextstate(main 837 (eval 24):1) v:{
212 # 3 <$> const[IV 42] s
215 # 6 <2> sassign sKS/2
216 # 7 <1> leavesub[1 ref] K/REFC,1
218 # 1 <;> nextstate(main 837 (eval 24):1) v:{
220 # 3 <$> const(IV 42) s
223 # 6 <2> sassign sKS/2
224 # 7 <1> leavesub[1 ref] K/REFC,1