Skip to content

Commit ef56cbf

Browse files
committed
Move signatures compilation failure tests to t/lib/croak/signatures
It's better to reuse the standard croak test infrastructure, than put lots of ad-hoc uses of `eval` and assertions on the value of `$@` afterwards in the regular signatures.t file.
1 parent 153ee16 commit ef56cbf

File tree

3 files changed

+223
-172
lines changed

3 files changed

+223
-172
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6120,6 +6120,7 @@ t/lib/croak/pp_ctl Test croak calls from pp_ctl.c
61206120
t/lib/croak/pp_hot Test croak calls from pp_hot.c
61216121
t/lib/croak/pp_sys Test croak calls from pp_sys.c
61226122
t/lib/croak/regcomp Test croak calls from regcomp.c
6123+
t/lib/croak/signatures Test croak calls from compiling subroutine signatures
61236124
t/lib/croak/toke Test croak calls from toke.c
61246125
t/lib/croak/toke_l1 Test croak calls from toke.c; file is not UTF-8 encoded
61256126
t/lib/cygwin.t Builtin cygwin function tests

t/lib/croak/signatures

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# PREAMBLE use feature 'signatures';
2+
__END__
3+
# NAME optional without default expression
4+
sub t024 ($a =) { }
5+
EXPECT
6+
Optional parameter lacks default expression at - line 2, near "=) "
7+
########
8+
# NAME mandatory follows optional
9+
sub t030 ($a = 222, $b) { }
10+
EXPECT
11+
Mandatory parameter follows optional parameter at - line 2, near "$b) "
12+
########
13+
# NAME mandatory follows optional twice
14+
sub t031 ($a = 222, $b = 333, $c, $d) { }
15+
EXPECT
16+
Mandatory parameter follows optional parameter at - line 2, near "$c,"
17+
Mandatory parameter follows optional parameter at - line 2, near "$d) "
18+
########
19+
# NAME slurpy array with default
20+
sub t136 (@abc = 222) { }
21+
EXPECT
22+
A slurpy parameter may not have a default value at - line 2, near "222) "
23+
########
24+
# NAME slurpy array with empty default
25+
sub t137 (@abc =) { }
26+
EXPECT
27+
A slurpy parameter may not have a default value at - line 2, near "=) "
28+
########
29+
# NAME anonymous slurpy array with default
30+
sub t138 (@ = 222) { }
31+
EXPECT
32+
A slurpy parameter may not have a default value at - line 2, near "222) "
33+
########
34+
# NAME anonymous slurpy array with empty default
35+
sub t139 (@ =) { }
36+
EXPECT
37+
A slurpy parameter may not have a default value at - line 2, near "=) "
38+
########
39+
# NAME slurpy hash with default
40+
sub t140 (%abc = 222) { }
41+
EXPECT
42+
A slurpy parameter may not have a default value at - line 2, near "222) "
43+
########
44+
# NAME slurpy hash with empty default
45+
sub t141 (%abc =) { }
46+
EXPECT
47+
A slurpy parameter may not have a default value at - line 2, near "=) "
48+
########
49+
# NAME anonymous slurpy hash with default
50+
sub t142 (% = 222) { }
51+
EXPECT
52+
A slurpy parameter may not have a default value at - line 2, near "222) "
53+
########
54+
# NAME anonymous slurpy hash with empty default
55+
sub t143 (% =) { }
56+
EXPECT
57+
A slurpy parameter may not have a default value at - line 2, near "=) "
58+
########
59+
sub t059 (@a, $b) { }
60+
EXPECT
61+
Slurpy parameter not last at - line 2, near "$b) "
62+
########
63+
sub t060 (@a, $b = 222) { }
64+
EXPECT
65+
Slurpy parameter not last at - line 2, near "222) "
66+
########
67+
sub t061 (@a, @b) { }
68+
EXPECT
69+
Multiple slurpy parameters not allowed at - line 2, near "@b) "
70+
########
71+
sub t062 (@a, %b) { }
72+
EXPECT
73+
Multiple slurpy parameters not allowed at - line 2, near "%b) "
74+
########
75+
sub t063 (@, $b) { }
76+
EXPECT
77+
Slurpy parameter not last at - line 2, near "$b) "
78+
########
79+
sub t064 (@, $b = 222) { }
80+
EXPECT
81+
Slurpy parameter not last at - line 2, near "222) "
82+
########
83+
sub t065 (@, @b) { }
84+
EXPECT
85+
Multiple slurpy parameters not allowed at - line 2, near "@b) "
86+
########
87+
sub t066 (@, %b) { }
88+
EXPECT
89+
Multiple slurpy parameters not allowed at - line 2, near "%b) "
90+
########
91+
sub t067 (@a, $) { }
92+
EXPECT
93+
Slurpy parameter not last at - line 2, near "$) "
94+
########
95+
sub t068 (@a, $ = 222) { }
96+
EXPECT
97+
Slurpy parameter not last at - line 2, near "222) "
98+
########
99+
sub t069 (@a, @) { }
100+
EXPECT
101+
Multiple slurpy parameters not allowed at - line 2, near "@) "
102+
########
103+
sub t070 (@a, %) { }
104+
EXPECT
105+
Multiple slurpy parameters not allowed at - line 2, near "%) "
106+
########
107+
sub t071 (@, $) { }
108+
EXPECT
109+
Slurpy parameter not last at - line 2, near "$) "
110+
########
111+
sub t072 (@, $ = 222) { }
112+
EXPECT
113+
Slurpy parameter not last at - line 2, near "222) "
114+
########
115+
sub t073 (@, @) { }
116+
EXPECT
117+
Multiple slurpy parameters not allowed at - line 2, near "@) "
118+
########
119+
sub t074 (@, %) { }
120+
EXPECT
121+
Multiple slurpy parameters not allowed at - line 2, near "%) "
122+
########
123+
sub t075 (%a, $b) { }
124+
EXPECT
125+
Slurpy parameter not last at - line 2, near "$b) "
126+
########
127+
sub t076 (%, $b) { }
128+
EXPECT
129+
Slurpy parameter not last at - line 2, near "$b) "
130+
########
131+
sub t077 ($a, @b, $c) { }
132+
EXPECT
133+
Slurpy parameter not last at - line 2, near "$c) "
134+
########
135+
sub t078 ($a, %b, $c) { }
136+
EXPECT
137+
Slurpy parameter not last at - line 2, near "$c) "
138+
########
139+
sub t079 ($a, @b, $c, $d) { }
140+
EXPECT
141+
Slurpy parameter not last at - line 2, near "$c,"
142+
Slurpy parameter not last at - line 2, near "$d) "
143+
########
144+
sub t082 (, $a) { }
145+
EXPECT
146+
syntax error at - line 2, near "(,"
147+
########
148+
sub t083 (,) { }
149+
EXPECT
150+
syntax error at - line 2, near "(,"
151+
########
152+
# NAME comment in signature is OK
153+
sub t088 ($ #foo
154+
a) { }
155+
156+
sub t090 (@ #foo
157+
a) { }
158+
159+
sub t092 (% #foo
160+
a) { }
161+
EXPECT
162+
OPTIONS nonfatal
163+
########
164+
sub t089 ($#foo
165+
a) { }
166+
EXPECT
167+
'#' not allowed immediately following a sigil in a subroutine signature at - line 2, near "($"
168+
syntax error at - line 3, near "a"
169+
########
170+
sub t091 (@#foo
171+
a) { }
172+
EXPECT
173+
'#' not allowed immediately following a sigil in a subroutine signature at - line 2, near "(@"
174+
syntax error at - line 3, near "a"
175+
########
176+
sub t093 (%#foo
177+
a) { }
178+
EXPECT
179+
'#' not allowed immediately following a sigil in a subroutine signature at - line 2, near "(%"
180+
syntax error at - line 3, near "a"
181+
########
182+
sub t094 (123) { }
183+
EXPECT
184+
A signature parameter must start with '$', '@' or '%' at - line 2, near "(1"
185+
syntax error at - line 2, near "(123"
186+
########
187+
sub t095 ($a, 123) { }
188+
EXPECT
189+
A signature parameter must start with '$', '@' or '%' at - line 2, near ", 1"
190+
syntax error at - line 2, near ", 123"
191+
########
192+
no warnings; sub t096 ($a 123) { }
193+
EXPECT
194+
Illegal operator following parameter in a subroutine signature at - line 2, near "($a 123"
195+
syntax error at - line 2, near "($a 123"
196+
########
197+
sub t097 ($a { }) { }
198+
EXPECT
199+
Illegal operator following parameter in a subroutine signature at - line 2, near "($a { }"
200+
syntax error at - line 2, near "($a { }"
201+
########
202+
sub t098 ($a; $b) { }
203+
EXPECT
204+
Illegal operator following parameter in a subroutine signature at - line 2, near "($a; "
205+
syntax error at - line 2, near "($a; "
206+
########
207+
sub t099 ($$) { }
208+
EXPECT
209+
Illegal character following sigil in a subroutine signature at - line 2, near "($"
210+
syntax error at - line 2, near "$$) "
211+
########
212+
# NAME global @_ in signature
213+
sub t101 (@_) { }
214+
EXPECT
215+
Can't use global @_ in subroutine signature at - line 2, near "(@_"
216+
########
217+
# NAME global %_ in signature
218+
sub t102 (%_) { }
219+
EXPECT
220+
Can't use global %_ in subroutine signature at - line 2, near "(%_"
221+

0 commit comments

Comments
 (0)