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 | |
7253e4e3 | 42 | '/(?{ 1/' => 'Sequence (?{...}) not terminated or not {}-balanced in regex; marked by {#} in m/(?{{#} 1/', |
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 RK |
52 | '/(?;x/' => 'Sequence (?;...) not recognized in regex; marked by {#} in m/(?;{#}x/', |
53 | '/(?<;x/' => 'Sequence (?<;...) not recognized in regex; marked by {#} in m/(?<;{#}x/', | |
b45f050a | 54 | |
cc74c5bd TS |
55 | '/(?\ix/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}ix/', |
56 | '/(?\mx/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}mx/', | |
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/', | |
62 | '/(?\>x/' => 'Sequence (?\...) not recognized in regex; marked by {#} in m/(?\{#}>x/', | |
9de15fec KW |
63 | '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i:foo)/', |
64 | '/(?^-i)foo/' => 'Sequence (?^-...) not recognized in regex; marked by {#} in m/(?^-{#}i)foo/', | |
65 | '/(?^d:foo)/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#}:foo)/', | |
66 | '/(?^d)foo/' => 'Sequence (?^d...) not recognized in regex; marked by {#} in m/(?^d{#})foo/', | |
67 | '/(?^lu:foo)/' => 'Sequence (?^lu...) not recognized in regex; marked by {#} in m/(?^lu{#}:foo)/', | |
68 | '/(?^lu)foo/' => 'Sequence (?^lu...) not recognized in regex; marked by {#} in m/(?^lu{#})foo/', | |
cc74c5bd | 69 | |
7253e4e3 | 70 | '/((x)/' => 'Unmatched ( in regex; marked by {#} in m/({#}(x)/', |
b45f050a | 71 | |
7253e4e3 | 72 | "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 in regex; marked by {#} in m/x{{#}$inf_p1}/", |
b45f050a | 73 | |
7253e4e3 | 74 | '/x{3,1}/' => 'Can\'t do {n,m} with n > m in regex; marked by {#} in m/x{3,1}{#}/', |
b45f050a | 75 | |
7253e4e3 | 76 | '/x**/' => 'Nested quantifiers in regex; marked by {#} in m/x**{#}/', |
b45f050a | 77 | |
7253e4e3 | 78 | '/x[/' => 'Unmatched [ in regex; marked by {#} in m/x[{#}/', |
b45f050a | 79 | |
7253e4e3 | 80 | '/*/', => 'Quantifier follows nothing in regex; marked by {#} in m/*{#}/', |
b45f050a | 81 | |
7253e4e3 | 82 | '/\p{x/' => 'Missing right brace on \p{} in regex; marked by {#} in m/\p{{#}x/', |
b45f050a | 83 | |
169da838 | 84 | '/[\p{x]/' => 'Missing right brace on \p{} in regex; marked by {#} in m/[\p{{#}x]/', |
b45f050a | 85 | |
7253e4e3 | 86 | '/(x)\2/' => 'Reference to nonexistent group in regex; marked by {#} in m/(x)\2{#}/', |
b45f050a | 87 | |
40809656 | 88 | 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/', |
b45f050a | 89 | |
7253e4e3 | 90 | '/\x{1/' => 'Missing right brace on \x{} in regex; marked by {#} in m/\x{{#}1/', |
b45f050a | 91 | |
169da838 | 92 | '/[\x{X]/' => 'Missing right brace on \x{} in regex; marked by {#} in m/[\x{{#}X]/', |
b45f050a | 93 | |
7253e4e3 | 94 | '/[[:barf:]]/' => 'POSIX class [:barf:] unknown in regex; marked by {#} in m/[[:barf:]{#}]/', |
b45f050a | 95 | |
7253e4e3 | 96 | '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions in regex; marked by {#} in m/[[=barf=]{#}]/', |
b45f050a | 97 | |
7253e4e3 | 98 | '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions in regex; marked by {#} in m/[[.barf.]{#}]/', |
b45f050a | 99 | |
7253e4e3 | 100 | '/[z-a]/' => 'Invalid [] range "z-a" in regex; marked by {#} in m/[z-a{#}]/', |
5528c7ba RGS |
101 | |
102 | '/\p/' => 'Empty \p{} in regex; marked by {#} in m/\p{#}/', | |
103 | ||
104 | '/\P{}/' => 'Empty \P{} in regex; marked by {#} in m/\P{{#}}/', | |
b45f050a JF |
105 | ); |
106 | ||
107 | ## | |
108 | ## Key-value pairs of code/error of code that should have non-fatal warnings. | |
109 | ## | |
cb79f740 | 110 | my @warning = ( |
7253e4e3 | 111 | 'm/\b*/' => '\b* matches null string many times in regex; marked by {#} in m/\b*{#}/', |
b45f050a | 112 | |
7253e4e3 | 113 | 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes in regex; marked by {#} in m/[:blank:]{#}/', |
b45f050a | 114 | |
7253e4e3 | 115 | "m'[\\y]'" => 'Unrecognized escape \y in character class passed through in regex; marked by {#} in m/[\y{#}]/', |
b45f050a | 116 | |
7253e4e3 RK |
117 | 'm/[a-\d]/' => 'False [] range "a-\d" in regex; marked by {#} in m/[a-\d{#}]/', |
118 | 'm/[\w-x]/' => 'False [] range "\w-" in regex; marked by {#} in m/[\w-{#}x]/', | |
f81125e2 JP |
119 | 'm/[a-\pM]/' => 'False [] range "a-\pM" in regex; marked by {#} in m/[a-\pM{#}]/', |
120 | 'm/[\pM-x]/' => 'False [] range "\pM-" in regex; marked by {#} in m/[\pM-{#}x]/', | |
7253e4e3 | 121 | "m'\\y'" => 'Unrecognized escape \y passed through in regex; marked by {#} in m/\y{#}/', |
b45f050a JF |
122 | ); |
123 | ||
cb79f740 NC |
124 | while (my ($regex, $expect) = splice @death, 0, 2) { |
125 | my $expect = fixup_expect($expect); | |
40809656 | 126 | # skip the utf8 test on EBCDIC since they do not die |
cb79f740 | 127 | next if $::IS_EBCDIC && $regex =~ /utf8/; |
b45f050a | 128 | |
cb79f740 NC |
129 | warning_is(sub { |
130 | $_ = "x"; | |
131 | eval $regex; | |
132 | like($@, qr/\Q$expect/); | |
133 | }, undef, "$regex died without any other warnings"); | |
b45f050a JF |
134 | } |
135 | ||
cb79f740 NC |
136 | while (my ($regex, $expect) = splice @warning, 0, 2) { |
137 | my $expect = fixup_expect($expect); | |
138 | warning_like(sub { | |
139 | $_ = "x"; | |
140 | eval $regex; | |
141 | is($@, '', "$regex did not die"); | |
142 | }, qr/\Q$expect/); | |
143 | } | |
b45f050a | 144 | |
cb79f740 | 145 | done_testing(); |