Commit | Line | Data |
---|---|---|
b45f050a JF |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
20822f61 | 5 | @INC = '../lib'; |
b45f050a JF |
6 | } |
7 | ||
8 | my $debug = 1; | |
9 | ||
10 | ## | |
11 | ## If the markers used are changed (search for "MARKER1" in regcomp.c), | |
12 | ## update only these two variables, and leave the {#} in the @death/@warning | |
13 | ## arrays below. The {#} is a meta-marker -- it marks where the marker should | |
14 | ## go. | |
15 | ||
7253e4e3 RK |
16 | my $marker1 = "<-- HERE"; |
17 | my $marker2 = " <-- HERE "; | |
b45f050a JF |
18 | |
19 | ## | |
20 | ## Key-value pairs of code/error of code that should have fatal errors. | |
21 | ## | |
69f2e79d MG |
22 | |
23 | eval 'use Config'; # assume defaults if fail | |
24 | our %Config; | |
25 | my $inf_m1 = ($Config{reg_infty} || 32767) - 1; | |
26 | my $inf_p1 = $inf_m1 + 2; | |
b45f050a JF |
27 | my @death = |
28 | ( | |
7253e4e3 | 29 | '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=foo=]{#}]/', |
b45f050a | 30 | |
58e23c8d | 31 | '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/', |
b45f050a | 32 | |
58e23c8d | 33 | '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/', |
b45f050a | 34 | |
7253e4e3 | 35 | '/(?@)/' => 'Sequence (?@...) not implemented in regex; marked by {#} in m/(?@{#})/', |
b45f050a | 36 | |
7253e4e3 | 37 | '/(?{ 1/' => 'Sequence (?{...}) not terminated or not {}-balanced in regex; marked by {#} in m/(?{{#} 1/', |
b45f050a | 38 | |
7253e4e3 | 39 | '/(?(1x))/' => 'Switch condition not recognized in regex; marked by {#} in m/(?(1x{#}))/', |
b45f050a | 40 | |
7253e4e3 | 41 | '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches in regex; marked by {#} in m/(?(1)x|y|{#}z)/', |
b45f050a | 42 | |
7253e4e3 | 43 | '/(?(x)y|x)/' => 'Unknown switch condition (?(x) in regex; marked by {#} in m/(?({#}x)y|x)/', |
b45f050a | 44 | |
7253e4e3 | 45 | '/(?/' => 'Sequence (? incomplete in regex; marked by {#} in m/(?{#}/', |
b45f050a | 46 | |
7253e4e3 RK |
47 | '/(?;x/' => 'Sequence (?;...) not recognized in regex; marked by {#} in m/(?;{#}x/', |
48 | '/(?<;x/' => 'Sequence (?<;...) not recognized in regex; marked by {#} in m/(?<;{#}x/', | |
b45f050a | 49 | |
cc74c5bd TS |
50 | '/(?\ix/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}ix/', |
51 | '/(?\mx/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}mx/', | |
52 | '/(?\:x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}:x/', | |
53 | '/(?\=x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}=x/', | |
54 | '/(?\!x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}!x/', | |
55 | '/(?\<=x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}<=x/', | |
56 | '/(?\<!x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}<!x/', | |
57 | '/(?\>x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}>x/', | |
9de15fec KW |
58 | '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i:foo)/', |
59 | '/(?^-i)foo/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i)foo/', | |
60 | '/(?^d:foo)/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#}:foo)/', | |
61 | '/(?^d)foo/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#})foo/', | |
62 | '/(?^lu:foo)/' => 'Sequence (?^lu...) not recognized in regex; marked by {#} in m/(?^lu{#}:foo)/', | |
63 | '/(?^lu)foo/' => 'Sequence (?^lu...) not recognized in regex; marked by {#} in m/(?^lu{#})foo/', | |
cc74c5bd | 64 | |
7253e4e3 | 65 | '/((x)/' => 'Unmatched ( in regex; marked by {#} in m/({#}(x)/', |
b45f050a | 66 | |
7253e4e3 | 67 | "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 in regex; marked by {#} in m/x{{#}$inf_p1}/", |
b45f050a | 68 | |
7253e4e3 | 69 | '/x{3,1}/' => 'Can\'t do {n,m} with n > m in regex; marked by {#} in m/x{3,1}{#}/', |
b45f050a | 70 | |
7253e4e3 | 71 | '/x**/' => 'Nested quantifiers in regex; marked by {#} in m/x**{#}/', |
b45f050a | 72 | |
7253e4e3 | 73 | '/x[/' => 'Unmatched [ in regex; marked by {#} in m/x[{#}/', |
b45f050a | 74 | |
7253e4e3 | 75 | '/*/', => 'Quantifier follows nothing in regex; marked by {#} in m/*{#}/', |
b45f050a | 76 | |
7253e4e3 | 77 | '/\p{x/' => 'Missing right brace on \p{} in regex; marked by {#} in m/\p{{#}x/', |
b45f050a | 78 | |
169da838 | 79 | '/[\p{x]/' => 'Missing right brace on \p{} in regex; marked by {#} in m/[\p{{#}x]/', |
b45f050a | 80 | |
7253e4e3 | 81 | '/(x)\2/' => 'Reference to nonexistent group in regex; marked by {#} in m/(x)\2{#}/', |
b45f050a | 82 | |
40809656 | 83 | 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/', |
b45f050a | 84 | |
7253e4e3 | 85 | '/\x{1/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{{#}1/', |
b45f050a | 86 | |
169da838 | 87 | '/[\x{X]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{{#}X]/', |
b45f050a | 88 | |
7253e4e3 | 89 | '/[[:barf:]]/' => 'POSIX class [:barf:] unknown in regex; marked by {#} in m/[[:barf:]{#}]/', |
b45f050a | 90 | |
7253e4e3 | 91 | '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=barf=]{#}]/', |
b45f050a | 92 | |
7253e4e3 | 93 | '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions in regex; marked by {#} in m/[[.barf.]{#}]/', |
b45f050a | 94 | |
7253e4e3 | 95 | '/[z-a]/' => 'Invalid [] range "z-a" in regex; marked by {#} in m/[z-a{#}]/', |
5528c7ba RGS |
96 | |
97 | '/\p/' => 'Empty \p{} in regex; marked by {#} in m/\p{#}/', | |
98 | ||
99 | '/\P{}/' => 'Empty \P{} in regex; marked by {#} in m/\P{{#}}/', | |
b45f050a JF |
100 | ); |
101 | ||
102 | ## | |
103 | ## Key-value pairs of code/error of code that should have non-fatal warnings. | |
104 | ## | |
105 | @warning = ( | |
7253e4e3 | 106 | 'm/\b*/' => '\b* matches null string many times in regex; marked by {#} in m/\b*{#}/', |
b45f050a | 107 | |
7253e4e3 | 108 | 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:blank:]{#}/', |
b45f050a | 109 | |
7253e4e3 | 110 | "m'[\\y]'" => 'Unrecognized escape \y in character class passed through in regex; marked by {#} in m/[\y{#}]/', |
b45f050a | 111 | |
7253e4e3 RK |
112 | 'm/[a-\d]/' => 'False [] range "a-\d" in regex; marked by {#} in m/[a-\d{#}]/', |
113 | 'm/[\w-x]/' => 'False [] range "\w-" in regex; marked by {#} in m/[\w-{#}x]/', | |
f81125e2 JP |
114 | 'm/[a-\pM]/' => 'False [] range "a-\pM" in regex; marked by {#} in m/[a-\pM{#}]/', |
115 | 'm/[\pM-x]/' => 'False [] range "\pM-" in regex; marked by {#} in m/[\pM-{#}x]/', | |
7253e4e3 | 116 | "m'\\y'" => 'Unrecognized escape \y passed through in regex; marked by {#} in m/\y{#}/', |
b45f050a JF |
117 | ); |
118 | ||
119 | my $total = (@death + @warning)/2; | |
120 | ||
40809656 PP |
121 | # utf8 is a noop on EBCDIC platforms, it is not fatal |
122 | my $Is_EBCDIC = (ord('A') == 193); | |
123 | if ($Is_EBCDIC) { | |
124 | my @utf8_death = grep(/utf8/, @death); | |
7387eed8 | 125 | $total = $total - @utf8_death; |
40809656 PP |
126 | } |
127 | ||
b45f050a JF |
128 | print "1..$total\n"; |
129 | ||
130 | my $count = 0; | |
131 | ||
132 | while (@death) | |
133 | { | |
b45f050a JF |
134 | my $regex = shift @death; |
135 | my $result = shift @death; | |
40809656 PP |
136 | # skip the utf8 test on EBCDIC since they do not die |
137 | next if ($Is_EBCDIC && $regex =~ /utf8/); | |
138 | $count++; | |
b45f050a | 139 | |
b45f050a JF |
140 | $_ = "x"; |
141 | eval $regex; | |
142 | if (not $@) { | |
69f2e79d | 143 | print "# oops, $regex didn't die\nnot ok $count\n"; |
b45f050a JF |
144 | next; |
145 | } | |
146 | chomp $@; | |
b45f050a JF |
147 | $result =~ s/{\#}/$marker1/; |
148 | $result =~ s/{\#}/$marker2/; | |
197cf9b9 | 149 | $result .= " at "; |
69f2e79d MG |
150 | if ($@ !~ /^\Q$result/) { |
151 | print "# For $regex, expected:\n# $result\n# Got:\n# $@\n#\nnot "; | |
b45f050a | 152 | } |
d8176a88 | 153 | print "ok $count - $regex\n"; |
b45f050a JF |
154 | } |
155 | ||
156 | ||
157 | our $warning; | |
158 | $SIG{__WARN__} = sub { $warning = shift }; | |
159 | ||
160 | while (@warning) | |
161 | { | |
162 | $count++; | |
163 | my $regex = shift @warning; | |
164 | my $result = shift @warning; | |
165 | ||
166 | undef $warning; | |
167 | $_ = "x"; | |
168 | eval $regex; | |
169 | ||
170 | if ($@) | |
171 | { | |
69f2e79d | 172 | print "# oops, $regex died with:\n#\t$@#\nnot ok $count\n"; |
b45f050a JF |
173 | next; |
174 | } | |
175 | ||
176 | if (not $warning) | |
177 | { | |
69f2e79d | 178 | print "# oops, $regex didn't generate a warning\nnot ok $count\n"; |
b45f050a JF |
179 | next; |
180 | } | |
b45f050a JF |
181 | $result =~ s/{\#}/$marker1/; |
182 | $result =~ s/{\#}/$marker2/; | |
197cf9b9 | 183 | $result .= " at "; |
69f2e79d | 184 | if ($warning !~ /^\Q$result/) |
b45f050a | 185 | { |
69f2e79d MG |
186 | print <<"EOM"; |
187 | # For $regex, expected: | |
188 | # $result | |
189 | # Got: | |
190 | # $warning | |
191 | # | |
192 | not ok $count | |
193 | EOM | |
b45f050a JF |
194 | next; |
195 | } | |
d8176a88 | 196 | print "ok $count - $regex\n"; |
b45f050a JF |
197 | } |
198 | ||
199 | ||
200 |