Commit | Line | Data |
---|---|---|
b45f050a JF |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
20822f61 | 5 | @INC = '../lib'; |
cb79f740 NC |
6 | require './test.pl'; |
7 | eval 'require Config'; # assume defaults if this fails | |
b45f050a JF |
8 | } |
9 | ||
cb79f740 | 10 | use strict; |
b45f050a JF |
11 | |
12 | ## | |
13 | ## If the markers used are changed (search for "MARKER1" in regcomp.c), | |
cb79f740 | 14 | ## update only these two regexs, and leave the {#} in the @death/@warning |
b45f050a JF |
15 | ## arrays below. The {#} is a meta-marker -- it marks where the marker should |
16 | ## go. | |
cb79f740 NC |
17 | ## |
18 | sub fixup_expect { | |
19 | my $expect = shift; | |
20 | $expect =~ s/{\#}/<-- HERE/; | |
21 | $expect =~ s/{\#}/ <-- HERE /; | |
22 | $expect .= " at "; | |
23 | return $expect; | |
24 | } | |
b45f050a | 25 | |
cb79f740 NC |
26 | my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1; |
27 | my $inf_p1 = $inf_m1 + 2; | |
b45f050a JF |
28 | |
29 | ## | |
30 | ## Key-value pairs of code/error of code that should have fatal errors. | |
31 | ## | |
32 | my @death = | |
33 | ( | |
7253e4e3 | 34 | '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=foo=]{#}]/', |
b45f050a | 35 | |
58e23c8d | 36 | '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/', |
b45f050a | 37 | |
58e23c8d | 38 | '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/', |
b45f050a | 39 | |
7253e4e3 | 40 | '/(?@)/' => 'Sequence (?@...) not implemented in regex; marked by {#} in m/(?@{#})/', |
b45f050a | 41 | |
9da1dd8f | 42 | '/(?{ 1/' => 'Missing right curly or square bracket', |
b45f050a | 43 | |
7253e4e3 | 44 | '/(?(1x))/' => 'Switch condition not recognized in regex; marked by {#} in m/(?(1x{#}))/', |
b45f050a | 45 | |
7253e4e3 | 46 | '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches in regex; marked by {#} in m/(?(1)x|y|{#}z)/', |
b45f050a | 47 | |
7253e4e3 | 48 | '/(?(x)y|x)/' => 'Unknown switch condition (?(x) in regex; marked by {#} in m/(?({#}x)y|x)/', |
b45f050a | 49 | |
7253e4e3 | 50 | '/(?/' => 'Sequence (? incomplete in regex; marked by {#} in m/(?{#}/', |
b45f050a | 51 | |
7253e4e3 | 52 | '/(?;x/' => 'Sequence (?;...) not recognized in regex; marked by {#} in m/(?;{#}x/', |
1f4f6bf1 | 53 | '/(?<;x/' => 'Group name must start with a non-digit word character in regex; marked by {#} in m/(?<;{#}x/', |
cc74c5bd TS |
54 | '/(?\ix/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}ix/', |
55 | '/(?\mx/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}mx/', | |
56 | '/(?\:x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}:x/', | |
57 | '/(?\=x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}=x/', | |
58 | '/(?\!x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}!x/', | |
59 | '/(?\<=x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}<=x/', | |
60 | '/(?\<!x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}<!x/', | |
61 | '/(?\>x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}>x/', | |
9de15fec KW |
62 | '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i:foo)/', |
63 | '/(?^-i)foo/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i)foo/', | |
64 | '/(?^d:foo)/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#}:foo)/', | |
65 | '/(?^d)foo/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#})foo/', | |
0c96c706 KW |
66 | '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive in regex; marked by {#} in m/(?^lu{#}:foo)/', |
67 | '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive in regex; marked by {#} in m/(?^lu{#})foo/', | |
68 | '/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive in regex; marked by {#} in m/(?da{#}:foo)/', | |
69 | '/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice in regex; marked by {#} in m/(?lil{#}:foo)/', | |
70 | '/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice in regex; marked by {#} in m/(?aaia{#}:foo)/', | |
9442e3b8 | 71 | '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" in regex; marked by {#} in m/(?i-l{#}:foo)/', |
cc74c5bd | 72 | |
7253e4e3 | 73 | '/((x)/' => 'Unmatched ( in regex; marked by {#} in m/({#}(x)/', |
b45f050a | 74 | |
7253e4e3 | 75 | "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 in regex; marked by {#} in m/x{{#}$inf_p1}/", |
b45f050a | 76 | |
b45f050a | 77 | |
7253e4e3 | 78 | '/x**/' => 'Nested quantifiers in regex; marked by {#} in m/x**{#}/', |
b45f050a | 79 | |
7253e4e3 | 80 | '/x[/' => 'Unmatched [ in regex; marked by {#} in m/x[{#}/', |
b45f050a | 81 | |
7253e4e3 | 82 | '/*/', => 'Quantifier follows nothing in regex; marked by {#} in m/*{#}/', |
b45f050a | 83 | |
7253e4e3 | 84 | '/\p{x/' => 'Missing right brace on \p{} in regex; marked by {#} in m/\p{{#}x/', |
b45f050a | 85 | |
169da838 | 86 | '/[\p{x]/' => 'Missing right brace on \p{} in regex; marked by {#} in m/[\p{{#}x]/', |
b45f050a | 87 | |
7253e4e3 | 88 | '/(x)\2/' => 'Reference to nonexistent group in regex; marked by {#} in m/(x)\2{#}/', |
b45f050a | 89 | |
40809656 | 90 | 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/', |
b45f050a | 91 | |
b8de99ca KW |
92 | '/\x{1/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{1{#}/', |
93 | '/\x{X/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{{#}X/', | |
b45f050a | 94 | |
169da838 | 95 | '/[\x{X]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{{#}X]/', |
b8de99ca | 96 | '/[\x{A]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{A{#}]/', |
b45f050a | 97 | |
b8de99ca KW |
98 | '/\o{1/' => 'Missing right brace on \o{ in regex; marked by {#} in m/\o{1{#}/', |
99 | '/\o{X/' => 'Missing right brace on \o{ in regex; marked by {#} in m/\o{{#}X/', | |
9ffc7554 KW |
100 | |
101 | '/[\o{X]/' => 'Missing right brace on \o{ in regex; marked by {#} in m/[\o{{#}X]/', | |
b8de99ca | 102 | '/[\o{7]/' => 'Missing right brace on \o{ in regex; marked by {#} in m/[\o{7{#}]/', |
9ffc7554 | 103 | |
7253e4e3 | 104 | '/[[:barf:]]/' => 'POSIX class [:barf:] unknown in regex; marked by {#} in m/[[:barf:]{#}]/', |
b45f050a | 105 | |
7253e4e3 | 106 | '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=barf=]{#}]/', |
b45f050a | 107 | |
7253e4e3 | 108 | '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions in regex; marked by {#} in m/[[.barf.]{#}]/', |
b45f050a | 109 | |
7253e4e3 | 110 | '/[z-a]/' => 'Invalid [] range "z-a" in regex; marked by {#} in m/[z-a{#}]/', |
5528c7ba RGS |
111 | |
112 | '/\p/' => 'Empty \p{} in regex; marked by {#} in m/\p{#}/', | |
113 | ||
114 | '/\P{}/' => 'Empty \P{} in regex; marked by {#} in m/\P{{#}}/', | |
b45f050a JF |
115 | ); |
116 | ||
117 | ## | |
118 | ## Key-value pairs of code/error of code that should have non-fatal warnings. | |
119 | ## | |
cb79f740 | 120 | my @warning = ( |
7253e4e3 | 121 | 'm/\b*/' => '\b* matches null string many times in regex; marked by {#} in m/\b*{#}/', |
b45f050a | 122 | |
7253e4e3 | 123 | 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:blank:]{#}/', |
b45f050a | 124 | |
7253e4e3 | 125 | "m'[\\y]'" => 'Unrecognized escape \y in character class passed through in regex; marked by {#} in m/[\y{#}]/', |
b45f050a | 126 | |
7253e4e3 RK |
127 | 'm/[a-\d]/' => 'False [] range "a-\d" in regex; marked by {#} in m/[a-\d{#}]/', |
128 | 'm/[\w-x]/' => 'False [] range "\w-" in regex; marked by {#} in m/[\w-{#}x]/', | |
f81125e2 JP |
129 | 'm/[a-\pM]/' => 'False [] range "a-\pM" in regex; marked by {#} in m/[a-\pM{#}]/', |
130 | 'm/[\pM-x]/' => 'False [] range "\pM-" in regex; marked by {#} in m/[\pM-{#}x]/', | |
7253e4e3 | 131 | "m'\\y'" => 'Unrecognized escape \y passed through in regex; marked by {#} in m/\y{#}/', |
31c15ce5 | 132 | '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match in regex; marked by {#} in m/x{3,1}{#}/', |
b45f050a JF |
133 | ); |
134 | ||
cb79f740 NC |
135 | while (my ($regex, $expect) = splice @death, 0, 2) { |
136 | my $expect = fixup_expect($expect); | |
40809656 | 137 | # skip the utf8 test on EBCDIC since they do not die |
cb79f740 | 138 | next if $::IS_EBCDIC && $regex =~ /utf8/; |
b45f050a | 139 | |
cb79f740 NC |
140 | warning_is(sub { |
141 | $_ = "x"; | |
142 | eval $regex; | |
143 | like($@, qr/\Q$expect/); | |
144 | }, undef, "$regex died without any other warnings"); | |
b45f050a JF |
145 | } |
146 | ||
cb79f740 NC |
147 | while (my ($regex, $expect) = splice @warning, 0, 2) { |
148 | my $expect = fixup_expect($expect); | |
149 | warning_like(sub { | |
150 | $_ = "x"; | |
151 | eval $regex; | |
152 | is($@, '', "$regex did not die"); | |
153 | }, qr/\Q$expect/); | |
154 | } | |
b45f050a | 155 | |
cb79f740 | 156 | done_testing(); |