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 => 5 + 15 + 12 + 16 * $gOpts{selftest}; # pass()s + $#tests
31 pass("REGEX TEST HARNESS SELFTEST");
33 checkOptree ( name => "bare minimum opcode search",
36 noanchors => 1, # unanchored match
38 expect_nt => 'leavesub');
40 checkOptree ( name => "found print opcode",
42 code => sub {print 1},
43 noanchors => 1, # unanchored match
45 expect_nt => 'leavesub');
47 checkOptree ( name => 'test skip itself',
48 skip => 'this is skip-reason',
50 code => sub {print 1},
51 expect => 'dont-care, skipping',
52 expect_nt => 'this insures failure');
54 # This test 'unexpectedly succeeds', but that is "expected". Theres
55 # no good way to expect a successful todo, and inducing a failure
56 # causes the harness to print verbose errors, which is NOT helpful.
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') if 0;
66 checkOptree ( name => 'impossible match, remove skip to see failure',
67 todo => "see! it breaks!",
68 skip => 'skip the failure',
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.
81 checkOptree ( name => 'test against empty expectations',
83 code => sub {print 1},
87 like($@, qr/no '\w+' golden-sample found/, "empty expectations prevented");
91 checkOptree ( name => 'prevent whitespace only expectations',
98 like($@, qr/whitespace only reftext found for '\w+'/,
99 "just whitespace expectations prevented");
102 pass ("TEST -e \$srcCode");
104 checkOptree ( name => 'empty code or prog',
106 todo => "your excuse here ;-)",
112 ( name => "self strict, catch err",
113 prog => 'use strict; bogus',
114 errs => 'Bareword "bogus" not allowed while "strict subs" in use at -e line 1.',
115 expect => "nextstate", # simple expectations
116 expect_nt => "nextstate",
117 noanchors => 1, # allow them to work
120 checkOptree ( name => "sort lK - flag specific search",
121 prog => 'our (@a,@b); @b = sort @a',
123 expect => '<@> sort lK ',
124 expect_nt => '<@> sort lK ');
126 checkOptree ( name => "sort vK - flag specific search",
127 prog => 'sort our @a',
128 errs => 'Useless use of sort in void context at -e line 1.',
130 expect => '<@> sort vK',
131 expect_nt => '<@> sort vK');
133 checkOptree ( name => "'code' => 'sort our \@a'",
134 code => 'sort our @a',
136 expect => '<@> sort K',
137 expect_nt => '<@> sort K');
139 pass ("REFTEXT FIXUP TESTS");
141 checkOptree ( name => 'fixup nextstate (in reftext)',
144 strip_open_hints => 1,
145 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
146 # 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v:>,<,%
147 # 2 <0> padsv[$a:54,55] M/LVINTRO
148 # 3 <1> leavesub[1 ref] K/REFC,1
150 # 1 <;> nextstate(main 54 optree_concise.t:84) v:>,<,%
151 # 2 <0> padsv[$a:54,55] M/LVINTRO
152 # 3 <1> leavesub[1 ref] K/REFC,1
155 checkOptree ( name => 'fixup opcode args',
157 #fail => 1, # uncomment to see real padsv args: [$a:491,492]
159 strip_open_hints => 1,
160 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
161 # 1 <;> nextstate(main 56 optree_concise.t:96) v:>,<,%
162 # 2 <0> padsv[$a:56,57] M/LVINTRO
163 # 3 <1> leavesub[1 ref] K/REFC,1
165 # 1 <;> nextstate(main 56 optree_concise.t:96) v:>,<,%
166 # 2 <0> padsv[$a:56,57] M/LVINTRO
167 # 3 <1> leavesub[1 ref] K/REFC,1
170 #################################
171 pass("CANONICAL B::Concise EXAMPLE");
173 checkOptree ( name => 'canonical example w -basic',
175 code => sub{$a=$b+42},
177 strip_open_hints => 1,
178 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
179 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
180 # - <@> lineseq KP ->7
181 # 1 <;> nextstate(main 380 optree_selftest.t:139) v:>,<,%,{ ->2
182 # 6 <2> sassign sKS/2 ->7
183 # 4 <2> add[t3] sK/2 ->5
184 # - <1> ex-rv2sv sK/1 ->3
185 # 2 <#> gvsv[*b] s ->3
186 # 3 <$> const[IV 42] s ->4
187 # - <1> ex-rv2sv sKRM*/1 ->6
188 # 5 <#> gvsv[*a] s ->6
190 # 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
191 # - <@> lineseq KP ->7
192 # 1 <;> nextstate(main 60 optree_concise.t:122) v:>,<,%,{ ->2
193 # 6 <2> sassign sKS/2 ->7
194 # 4 <2> add[t1] sK/2 ->5
195 # - <1> ex-rv2sv sK/1 ->3
196 # 2 <$> gvsv(*b) s ->3
197 # 3 <$> const(IV 42) s ->4
198 # - <1> ex-rv2sv sKRM*/1 ->6
199 # 5 <$> gvsv(*a) s ->6
202 checkOptree ( code => '$a=$b+42',
204 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
205 # 1 <;> nextstate(main 837 (eval 24):1) v:{
207 # 3 <$> const[IV 42] s
210 # 6 <2> sassign sKS/2
211 # 7 <1> leavesub[1 ref] K/REFC,1
213 # 1 <;> nextstate(main 837 (eval 24):1) v:{
215 # 3 <$> const(IV 42) s
218 # 6 <2> sassign sKS/2
219 # 7 <1> leavesub[1 ref] K/REFC,1