Skip to content

Commit be966e2

Browse files
committed
Better skipping for regexp optimization tests
Say why we're skipping; skip min/max tests for substrings if we didn't get the substring; skip checking test for substrings if we didn't get the substring we expect to be checked.
1 parent bb39471 commit be966e2

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

t/re/opt.t

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ while (<DATA>) {
6666
my $o = re::optimization(eval "qr{$pat}");
6767
ok($o, "$comment compiled ok");
6868

69-
my $skip = !$o;
69+
my $skip = $o ? undef : "could not get info for qr{$pat}";
7070
my $test = 0;
7171

7272
my($got, $expect) = ($o->{minlen}, $minlen);
@@ -114,11 +114,18 @@ while (<DATA>) {
114114
++$test;
115115
$skip || is($o->{anchored_utf8}, undef, "$comment no anchored utf8");
116116
}
117+
# skip offset checks if we failed to find a string
118+
my $local_skip = (
119+
!$skip && !defined($o->{anchored} // $o->{anchored_utf8})
120+
) ? 'no anchored string' : undef;
117121
if (length $aoff) {
118122
++$test;
119-
local $TODO = 1 if exists $todo{'anchored min offset'};
120-
$skip || is($o->{'anchored min offset'}, $aoff,
121-
"$comment anchored min offset");
123+
SKIP: {
124+
skip($local_skip) if $local_skip;
125+
local $TODO = 1 if exists $todo{'anchored min offset'};
126+
$skip || is($o->{'anchored min offset'}, $aoff,
127+
"$comment anchored min offset");
128+
}
122129
# we don't care about anchored max: it may be set same as min or 0
123130
}
124131

@@ -143,27 +150,48 @@ while (<DATA>) {
143150
++$test;
144151
$skip || is($o->{floating_utf8}, undef, "$comment no floating utf8");
145152
}
153+
# skip offset checks if we failed to find a string
154+
$local_skip = (
155+
!$skip && !defined($o->{floating} // $o->{floating_utf8})
156+
) ? 'no floating string' : undef;
146157
if (length $fmin) {
147158
++$test;
148-
local $TODO = 1 if exists $todo{'floating min offset'};
149-
$skip || is($o->{'floating min offset'}, $fmin,
150-
"$comment floating min offset");
159+
SKIP: {
160+
skip($local_skip) if $local_skip;
161+
local $TODO = 1 if exists $todo{'floating min offset'};
162+
$skip || is($o->{'floating min offset'}, $fmin,
163+
"$comment floating min offset");
164+
}
151165
}
152166
if (defined $fmax) {
153167
++$test;
154-
local $TODO = 1 if exists $todo{'floating max offset'};
155-
$skip || is($o->{'floating max offset'}, $fmax,
156-
"$comment floating min offset");
168+
SKIP: {
169+
skip($local_skip) if $local_skip;
170+
local $TODO = 1 if exists $todo{'floating max offset'};
171+
$skip || is($o->{'floating max offset'}, $fmax,
172+
"$comment floating max offset");
173+
}
157174
}
158175

159176
my $check = ($acheck eq '+') ? 'anchored'
160177
: ($fcheck eq '+') ? 'floating'
161178
: ($acheck eq '-') ? undef
162179
: 'none';
180+
$local_skip = (
181+
!$skip && $check && (
182+
($check eq 'anchored'
183+
&& !defined($o->{anchored} // $o->{anchored_utf8}))
184+
|| ($check eq 'floating'
185+
&& !defined($o->{floating} // $o->{floating_utf8}))
186+
)
187+
) ? "$check not found" : undef;
163188
if (defined $check) {
164189
++$test;
165-
local $TODO = 1 if exists $todo{checking};
166-
$skip || is($o->{checking}, $check, "$comment checking $check");
190+
SKIP: {
191+
skip($local_skip) if $local_skip;
192+
local $TODO = 1 if exists $todo{checking};
193+
$skip || is($o->{checking}, $check, "$comment checking $check");
194+
}
167195
}
168196

169197
# booleans
@@ -199,7 +227,7 @@ while (<DATA>) {
199227
);
200228
}
201229

202-
skip($test) if $skip;
230+
skip($skip, $test) if $skip;
203231
}
204232
done_testing();
205233
__END__

0 commit comments

Comments
 (0)