Commit | Line | Data |
724aa791 |
1 | #!perl |
2 | |
3 | BEGIN { |
4 | chdir 't'; |
5 | @INC = ('../lib', '../ext/B/t'); |
9cd8f857 |
6 | require Config; |
7 | if (($Config::Config{'extensions'} !~ /\bB\b/) ){ |
8 | print "1..0 # Skip -- Perl configured without B module\n"; |
9 | exit 0; |
10 | } |
8dd2f9d4 |
11 | if ($Config::Config{'extensions'} !~ /\bData\/Dumper\b/) { |
2799c206 |
12 | print |
13 | "1..0 # Skip: Data::Dumper was not built, needed by OptreeCheck\n"; |
14 | exit 0; |
2799c206 |
15 | } |
724aa791 |
16 | require './test.pl'; |
17 | } |
18 | |
19 | use OptreeCheck; |
20 | |
21 | =head1 OptreeCheck selftest harness |
22 | |
23 | This file is primarily to test services of OptreeCheck itself, ie |
24 | checkOptree(). %gOpts provides test-state info, it is 'exported' into |
25 | main:: |
26 | |
27 | doing use OptreeCheck runs import(), which processes @ARGV to process |
28 | cmdline args in 'standard' way across all clients of OptreeCheck. |
29 | |
30 | =cut |
31 | |
2ce64696 |
32 | use Config; |
cc02ea56 |
33 | plan tests => 5 + 18 + 14 * $gOpts{selftest}; # fudged |
724aa791 |
34 | |
2ce64696 |
35 | SKIP: { |
e77e2f14 |
36 | skip "no perlio in this build", 5 + 18 + 14 * $gOpts{selftest} |
2ce64696 |
37 | unless $Config::Config{useperlio}; |
38 | |
39 | |
724aa791 |
40 | pass("REGEX TEST HARNESS SELFTEST"); |
41 | |
42 | checkOptree ( name => "bare minimum opcode search", |
43 | bcopts => '-exec', |
44 | code => sub {my $a}, |
cc02ea56 |
45 | noanchors => 1, # unanchored match |
724aa791 |
46 | expect => 'leavesub', |
47 | expect_nt => 'leavesub'); |
48 | |
49 | checkOptree ( name => "found print opcode", |
50 | bcopts => '-exec', |
51 | code => sub {print 1}, |
cc02ea56 |
52 | noanchors => 1, # unanchored match |
724aa791 |
53 | expect => 'print', |
54 | expect_nt => 'leavesub'); |
55 | |
56 | checkOptree ( name => 'test skip itself', |
57 | skip => 1, |
58 | bcopts => '-exec', |
59 | code => sub {print 1}, |
60 | expect => 'dont-care, skipping', |
61 | expect_nt => 'this insures failure'); |
62 | |
181f6ff5 |
63 | # This test 'unexpectedly succeeds', but that is "expected". Theres |
64 | # no good way to expect a successful todo, and inducing a failure |
65 | # causes the harness to print verbose errors, which is NOT helpful. |
66 | |
724aa791 |
67 | checkOptree ( name => 'test todo itself', |
68 | todo => "your excuse here ;-)", |
69 | bcopts => '-exec', |
70 | code => sub {print 1}, |
cc02ea56 |
71 | noanchors => 1, # unanchored match |
724aa791 |
72 | expect => 'print', |
73 | expect_nt => 'print'); |
74 | |
75 | checkOptree ( name => 'impossible match, remove skip to see failure', |
76 | todo => "see! it breaks!", |
77 | skip => 1, # but skip it 1st |
78 | code => sub {print 1}, |
79 | expect => 'look out ! Boy Wonder', |
80 | expect_nt => 'holy near earth asteroid Batman !'); |
81 | |
82 | pass ("TEST FATAL ERRS"); |
83 | |
84 | if (1) { |
85 | # test for fatal errors. Im unsettled on fail vs die. |
86 | # calling fail isnt good enough by itself. |
87 | eval { |
88 | |
89 | checkOptree ( name => 'empty code or prog', |
90 | todo => "your excuse here ;-)", |
91 | code => '', |
92 | prog => '', |
93 | ); |
94 | }; |
95 | like($@, 'code or prog is required', 'empty code or prog prevented'); |
96 | |
97 | $@=''; |
98 | eval { |
99 | checkOptree ( name => 'test against empty expectations', |
100 | bcopts => '-exec', |
101 | code => sub {print 1}, |
102 | expect => '', |
103 | expect_nt => ''); |
104 | }; |
105 | like($@, 'no reftext found for', "empty expectations prevented"); |
106 | |
107 | $@=''; |
108 | eval { |
109 | checkOptree ( name => 'prevent whitespace only expectations', |
110 | bcopts => '-exec', |
111 | code => sub {my $a}, |
112 | #skip => 1, |
113 | expect_nt => "\n", |
114 | expect => "\n"); |
115 | }; |
116 | like($@, 'no reftext found for', "just whitespace expectations prevented"); |
117 | } |
118 | |
119 | pass ("TEST -e \$srcCode"); |
120 | |
5e251bf1 |
121 | checkOptree |
122 | ( name => '-w errors seen', |
123 | prog => 'sort our @a', |
124 | errs => 'Useless use of sort in void context at -e line 1.', |
125 | ); |
126 | |
127 | checkOptree |
128 | ( name => "self strict, catch err", |
129 | prog => 'use strict; bogus', |
130 | errs => 'Bareword "bogus" not allowed while "strict subs" in use at -e line 1.', |
131 | ); |
132 | |
724aa791 |
133 | checkOptree ( name => "sort vK - flag specific search", |
134 | prog => 'sort our @a', |
cc02ea56 |
135 | noanchors => 1, |
724aa791 |
136 | expect => '<@> sort vK ', |
137 | expect_nt => '<@> sort vK '); |
138 | |
139 | checkOptree ( name => "'prog' => 'sort our \@a'", |
140 | prog => 'sort our @a', |
cc02ea56 |
141 | noanchors => 1, |
724aa791 |
142 | expect => '<@> sort vK', |
143 | expect_nt => '<@> sort vK'); |
144 | |
145 | checkOptree ( name => "'code' => 'sort our \@a'", |
146 | code => 'sort our @a', |
cc02ea56 |
147 | noanchors => 1, |
724aa791 |
148 | expect => '<@> sort K', |
149 | expect_nt => '<@> sort K'); |
150 | |
151 | pass ("REFTEXT FIXUP TESTS"); |
152 | |
153 | checkOptree ( name => 'fixup nextstate (in reftext)', |
154 | bcopts => '-exec', |
155 | code => sub {my $a}, |
156 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
724aa791 |
157 | # 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v |
158 | # 2 <0> padsv[$a:54,55] M/LVINTRO |
159 | # 3 <1> leavesub[1 ref] K/REFC,1 |
160 | EOT_EOT |
724aa791 |
161 | # 1 <;> nextstate(main 54 optree_concise.t:84) v |
162 | # 2 <0> padsv[$a:54,55] M/LVINTRO |
163 | # 3 <1> leavesub[1 ref] K/REFC,1 |
164 | EONT_EONT |
165 | |
181f6ff5 |
166 | checkOptree ( name => 'fixup opcode args', |
724aa791 |
167 | bcopts => '-exec', |
181f6ff5 |
168 | #fail => 1, # uncomment to see real padsv args: [$a:491,492] |
724aa791 |
169 | code => sub {my $a}, |
724aa791 |
170 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
724aa791 |
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 |
174 | EOT_EOT |
724aa791 |
175 | # 1 <;> nextstate(main 56 optree_concise.t:96) v |
176 | # 2 <0> padsv[$a:56,57] M/LVINTRO |
177 | # 3 <1> leavesub[1 ref] K/REFC,1 |
178 | EONT_EONT |
179 | |
724aa791 |
180 | ################################# |
181 | pass("CANONICAL B::Concise EXAMPLE"); |
182 | |
183 | checkOptree ( name => 'canonical example w -basic', |
184 | bcopts => '-basic', |
185 | code => sub{$a=$b+42}, |
186 | crossfail => 1, |
187 | debug => 1, |
188 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
189 | # 7 <1> leavesub[1 ref] K/REFC,1 ->(end) |
190 | # - <@> lineseq KP ->7 |
191 | # 1 <;> nextstate(main 380 optree_selftest.t:139) v ->2 |
192 | # 6 <2> sassign sKS/2 ->7 |
193 | # 4 <2> add[t3] sK/2 ->5 |
194 | # - <1> ex-rv2sv sK/1 ->3 |
195 | # 2 <#> gvsv[*b] s ->3 |
196 | # 3 <$> const[IV 42] s ->4 |
197 | # - <1> ex-rv2sv sKRM*/1 ->6 |
198 | # 5 <#> gvsv[*a] s ->6 |
199 | EOT_EOT |
200 | # 7 <1> leavesub[1 ref] K/REFC,1 ->(end) |
201 | # - <@> lineseq KP ->7 |
202 | # 1 <;> nextstate(main 60 optree_concise.t:122) v ->2 |
203 | # 6 <2> sassign sKS/2 ->7 |
204 | # 4 <2> add[t1] sK/2 ->5 |
205 | # - <1> ex-rv2sv sK/1 ->3 |
206 | # 2 <$> gvsv(*b) s ->3 |
207 | # 3 <$> const(IV 42) s ->4 |
208 | # - <1> ex-rv2sv sKRM*/1 ->6 |
209 | # 5 <$> gvsv(*a) s ->6 |
210 | EONT_EONT |
211 | |
212 | checkOptree ( name => 'canonical example w -exec', |
213 | bcopts => '-exec', |
214 | code => sub{$a=$b+42}, |
215 | crossfail => 1, |
216 | retry => 1, |
217 | debug => 1, |
218 | xtestfail => 1, |
219 | expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); |
724aa791 |
220 | # 1 <;> nextstate(main 61 optree_concise.t:139) v |
221 | # 2 <#> gvsv[*b] s |
222 | # 3 <$> const[IV 42] s |
223 | # 4 <2> add[t3] sK/2 |
224 | # 5 <#> gvsv[*a] s |
225 | # 6 <2> sassign sKS/2 |
226 | # 7 <1> leavesub[1 ref] K/REFC,1 |
227 | EOT_EOT |
724aa791 |
228 | # 1 <;> nextstate(main 61 optree_concise.t:139) v |
229 | # 2 <$> gvsv(*b) s |
230 | # 3 <$> const(IV 42) s |
231 | # 4 <2> add[t1] sK/2 |
232 | # 5 <$> gvsv(*a) s |
233 | # 6 <2> sassign sKS/2 |
234 | # 7 <1> leavesub[1 ref] K/REFC,1 |
235 | EONT_EONT |
236 | |
237 | checkOptree ( name => 'tree reftext is messy cut-paste', |
238 | skip => 1); |
239 | |
2ce64696 |
240 | } # skip |
724aa791 |
241 | |
242 | __END__ |
243 | |