1N/A#!./perl -w
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Amy $debug = 1;
1N/A
1N/A##
1N/A## If the markers used are changed (search for "MARKER1" in regcomp.c),
1N/A## update only these two variables, and leave the {#} in the @death/@warning
1N/A## arrays below. The {#} is a meta-marker -- it marks where the marker should
1N/A## go.
1N/A
1N/Amy $marker1 = "<-- HERE";
1N/Amy $marker2 = " <-- HERE ";
1N/A
1N/A##
1N/A## Key-value pairs of code/error of code that should have fatal errors.
1N/A##
1N/A
1N/Aeval 'use Config'; # assume defaults if fail
1N/Aour %Config;
1N/Amy $inf_m1 = ($Config{reg_infty} || 32767) - 1;
1N/Amy $inf_p1 = $inf_m1 + 2;
1N/Amy @death =
1N/A(
1N/A '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=foo=]{#}]/',
1N/A
1N/A '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex; marked by {#} in m/(?<= .*){#}/',
1N/A
1N/A '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex; marked by {#} in m/(?<= x{1000}){#}/',
1N/A
1N/A '/(?@)/' => 'Sequence (?@...) not implemented in regex; marked by {#} in m/(?@{#})/',
1N/A
1N/A '/(?{ 1/' => 'Sequence (?{...}) not terminated or not {}-balanced in regex; marked by {#} in m/(?{{#} 1/',
1N/A
1N/A '/(?(1x))/' => 'Switch condition not recognized in regex; marked by {#} in m/(?(1x{#}))/',
1N/A
1N/A '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches in regex; marked by {#} in m/(?(1)x|y|{#}z)/',
1N/A
1N/A '/(?(x)y|x)/' => 'Unknown switch condition (?(x) in regex; marked by {#} in m/(?({#}x)y|x)/',
1N/A
1N/A '/(?/' => 'Sequence (? incomplete in regex; marked by {#} in m/(?{#}/',
1N/A
1N/A '/(?;x/' => 'Sequence (?;...) not recognized in regex; marked by {#} in m/(?;{#}x/',
1N/A '/(?<;x/' => 'Sequence (?<;...) not recognized in regex; marked by {#} in m/(?<;{#}x/',
1N/A
1N/A '/((x)/' => 'Unmatched ( in regex; marked by {#} in m/({#}(x)/',
1N/A
1N/A "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 in regex; marked by {#} in m/x{{#}$inf_p1}/",
1N/A
1N/A '/x{3,1}/' => 'Can\'t do {n,m} with n > m in regex; marked by {#} in m/x{3,1}{#}/',
1N/A
1N/A '/x**/' => 'Nested quantifiers in regex; marked by {#} in m/x**{#}/',
1N/A
1N/A '/x[/' => 'Unmatched [ in regex; marked by {#} in m/x[{#}/',
1N/A
1N/A '/*/', => 'Quantifier follows nothing in regex; marked by {#} in m/*{#}/',
1N/A
1N/A '/\p{x/' => 'Missing right brace on \p{} in regex; marked by {#} in m/\p{{#}x/',
1N/A
1N/A '/[\p{x]/' => 'Missing right brace on \p{} in regex; marked by {#} in m/[\p{{#}x]/',
1N/A
1N/A '/(x)\2/' => 'Reference to nonexistent group in regex; marked by {#} in m/(x)\2{#}/',
1N/A
1N/A 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/',
1N/A
1N/A '/\x{1/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{{#}1/',
1N/A
1N/A '/[\x{X]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{{#}X]/',
1N/A
1N/A '/[[:barf:]]/' => 'POSIX class [:barf:] unknown in regex; marked by {#} in m/[[:barf:]{#}]/',
1N/A
1N/A '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=barf=]{#}]/',
1N/A
1N/A '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions in regex; marked by {#} in m/[[.barf.]{#}]/',
1N/A
1N/A '/[z-a]/' => 'Invalid [] range "z-a" in regex; marked by {#} in m/[z-a{#}]/',
1N/A
1N/A '/\p/' => 'Empty \p{} in regex; marked by {#} in m/\p{#}/',
1N/A
1N/A '/\P{}/' => 'Empty \P{} in regex; marked by {#} in m/\P{{#}}/',
1N/A);
1N/A
1N/A##
1N/A## Key-value pairs of code/error of code that should have non-fatal warnings.
1N/A##
1N/A@warning = (
1N/A "m/(?p{ 'a' })/" => "(?p{}) is deprecated - use (??{}) in regex; marked by {#} in m/(?p{#}{ 'a' })/",
1N/A
1N/A 'm/\b*/' => '\b* matches null string many times in regex; marked by {#} in m/\b*{#}/',
1N/A
1N/A 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:blank:]{#}/',
1N/A
1N/A "m'[\\y]'" => 'Unrecognized escape \y in character class passed through in regex; marked by {#} in m/[\y{#}]/',
1N/A
1N/A 'm/[a-\d]/' => 'False [] range "a-\d" in regex; marked by {#} in m/[a-\d{#}]/',
1N/A 'm/[\w-x]/' => 'False [] range "\w-" in regex; marked by {#} in m/[\w-{#}x]/',
1N/A "m'\\y'" => 'Unrecognized escape \y passed through in regex; marked by {#} in m/\y{#}/',
1N/A);
1N/A
1N/Amy $total = (@death + @warning)/2;
1N/A
1N/A# utf8 is a noop on EBCDIC platforms, it is not fatal
1N/Amy $Is_EBCDIC = (ord('A') == 193);
1N/Aif ($Is_EBCDIC) {
1N/A my @utf8_death = grep(/utf8/, @death);
1N/A $total = $total - @utf8_death;
1N/A}
1N/A
1N/Aprint "1..$total\n";
1N/A
1N/Amy $count = 0;
1N/A
1N/Awhile (@death)
1N/A{
1N/A my $regex = shift @death;
1N/A my $result = shift @death;
1N/A # skip the utf8 test on EBCDIC since they do not die
1N/A next if ($Is_EBCDIC && $regex =~ /utf8/);
1N/A $count++;
1N/A
1N/A $_ = "x";
1N/A eval $regex;
1N/A if (not $@) {
1N/A print "# oops, $regex didn't die\nnot ok $count\n";
1N/A next;
1N/A }
1N/A chomp $@;
1N/A $result =~ s/{\#}/$marker1/;
1N/A $result =~ s/{\#}/$marker2/;
1N/A $result .= " at ";
1N/A if ($@ !~ /^\Q$result/) {
1N/A print "# For $regex, expected:\n# $result\n# Got:\n# $@\n#\nnot ";
1N/A }
1N/A print "ok $count - $regex\n";
1N/A}
1N/A
1N/A
1N/Aour $warning;
1N/A$SIG{__WARN__} = sub { $warning = shift };
1N/A
1N/Awhile (@warning)
1N/A{
1N/A $count++;
1N/A my $regex = shift @warning;
1N/A my $result = shift @warning;
1N/A
1N/A undef $warning;
1N/A $_ = "x";
1N/A eval $regex;
1N/A
1N/A if ($@)
1N/A {
1N/A print "# oops, $regex died with:\n#\t$@#\nnot ok $count\n";
1N/A next;
1N/A }
1N/A
1N/A if (not $warning)
1N/A {
1N/A print "# oops, $regex didn't generate a warning\nnot ok $count\n";
1N/A next;
1N/A }
1N/A $result =~ s/{\#}/$marker1/;
1N/A $result =~ s/{\#}/$marker2/;
1N/A $result .= " at ";
1N/A if ($warning !~ /^\Q$result/)
1N/A {
1N/A print <<"EOM";
1N/A# For $regex, expected:
1N/A# $result
1N/A# Got:
1N/A# $warning
1N/A#
1N/Anot ok $count
1N/AEOM
1N/A next;
1N/A }
1N/A print "ok $count - $regex\n";
1N/A}
1N/A
1N/A
1N/A