diff --git a/MANIFEST b/MANIFEST index 2ecec777eba2..94e6fa008203 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6120,6 +6120,7 @@ t/lib/croak/pp_ctl Test croak calls from pp_ctl.c t/lib/croak/pp_hot Test croak calls from pp_hot.c t/lib/croak/pp_sys Test croak calls from pp_sys.c t/lib/croak/regcomp Test croak calls from regcomp.c +t/lib/croak/signatures Test croak calls from compiling subroutine signatures t/lib/croak/toke Test croak calls from toke.c t/lib/croak/toke_l1 Test croak calls from toke.c; file is not UTF-8 encoded t/lib/cygwin.t Builtin cygwin function tests diff --git a/t/lib/croak/signatures b/t/lib/croak/signatures new file mode 100644 index 000000000000..2dda2d55d802 --- /dev/null +++ b/t/lib/croak/signatures @@ -0,0 +1,221 @@ +# PREAMBLE use feature 'signatures'; +__END__ +# NAME optional without default expression +sub t024 ($a =) { } +EXPECT +Optional parameter lacks default expression at - line 2, near "=) " +######## +# NAME mandatory follows optional +sub t030 ($a = 222, $b) { } +EXPECT +Mandatory parameter follows optional parameter at - line 2, near "$b) " +######## +# NAME mandatory follows optional twice +sub t031 ($a = 222, $b = 333, $c, $d) { } +EXPECT +Mandatory parameter follows optional parameter at - line 2, near "$c," +Mandatory parameter follows optional parameter at - line 2, near "$d) " +######## +# NAME slurpy array with default +sub t136 (@abc = 222) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "222) " +######## +# NAME slurpy array with empty default +sub t137 (@abc =) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "=) " +######## +# NAME anonymous slurpy array with default +sub t138 (@ = 222) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "222) " +######## +# NAME anonymous slurpy array with empty default +sub t139 (@ =) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "=) " +######## +# NAME slurpy hash with default +sub t140 (%abc = 222) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "222) " +######## +# NAME slurpy hash with empty default +sub t141 (%abc =) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "=) " +######## +# NAME anonymous slurpy hash with default +sub t142 (% = 222) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "222) " +######## +# NAME anonymous slurpy hash with empty default +sub t143 (% =) { } +EXPECT +A slurpy parameter may not have a default value at - line 2, near "=) " +######## +sub t059 (@a, $b) { } +EXPECT +Slurpy parameter not last at - line 2, near "$b) " +######## +sub t060 (@a, $b = 222) { } +EXPECT +Slurpy parameter not last at - line 2, near "222) " +######## +sub t061 (@a, @b) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "@b) " +######## +sub t062 (@a, %b) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "%b) " +######## +sub t063 (@, $b) { } +EXPECT +Slurpy parameter not last at - line 2, near "$b) " +######## +sub t064 (@, $b = 222) { } +EXPECT +Slurpy parameter not last at - line 2, near "222) " +######## +sub t065 (@, @b) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "@b) " +######## +sub t066 (@, %b) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "%b) " +######## +sub t067 (@a, $) { } +EXPECT +Slurpy parameter not last at - line 2, near "$) " +######## +sub t068 (@a, $ = 222) { } +EXPECT +Slurpy parameter not last at - line 2, near "222) " +######## +sub t069 (@a, @) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "@) " +######## +sub t070 (@a, %) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "%) " +######## +sub t071 (@, $) { } +EXPECT +Slurpy parameter not last at - line 2, near "$) " +######## +sub t072 (@, $ = 222) { } +EXPECT +Slurpy parameter not last at - line 2, near "222) " +######## +sub t073 (@, @) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "@) " +######## +sub t074 (@, %) { } +EXPECT +Multiple slurpy parameters not allowed at - line 2, near "%) " +######## +sub t075 (%a, $b) { } +EXPECT +Slurpy parameter not last at - line 2, near "$b) " +######## +sub t076 (%, $b) { } +EXPECT +Slurpy parameter not last at - line 2, near "$b) " +######## +sub t077 ($a, @b, $c) { } +EXPECT +Slurpy parameter not last at - line 2, near "$c) " +######## +sub t078 ($a, %b, $c) { } +EXPECT +Slurpy parameter not last at - line 2, near "$c) " +######## +sub t079 ($a, @b, $c, $d) { } +EXPECT +Slurpy parameter not last at - line 2, near "$c," +Slurpy parameter not last at - line 2, near "$d) " +######## +sub t082 (, $a) { } +EXPECT +syntax error at - line 2, near "(," +######## +sub t083 (,) { } +EXPECT +syntax error at - line 2, near "(," +######## +# NAME comment in signature is OK +sub t088 ($ #foo +a) { } + +sub t090 (@ #foo +a) { } + +sub t092 (% #foo +a) { } +EXPECT +OPTIONS nonfatal +######## +sub t089 ($#foo +a) { } +EXPECT +'#' not allowed immediately following a sigil in a subroutine signature at - line 2, near "($" +syntax error at - line 3, near "a" +######## +sub t091 (@#foo +a) { } +EXPECT +'#' not allowed immediately following a sigil in a subroutine signature at - line 2, near "(@" +syntax error at - line 3, near "a" +######## +sub t093 (%#foo +a) { } +EXPECT +'#' not allowed immediately following a sigil in a subroutine signature at - line 2, near "(%" +syntax error at - line 3, near "a" +######## +sub t094 (123) { } +EXPECT +A signature parameter must start with '$', '@' or '%' at - line 2, near "(1" +syntax error at - line 2, near "(123" +######## +sub t095 ($a, 123) { } +EXPECT +A signature parameter must start with '$', '@' or '%' at - line 2, near ", 1" +syntax error at - line 2, near ", 123" +######## +no warnings; sub t096 ($a 123) { } +EXPECT +Illegal operator following parameter in a subroutine signature at - line 2, near "($a 123" +syntax error at - line 2, near "($a 123" +######## +sub t097 ($a { }) { } +EXPECT +Illegal operator following parameter in a subroutine signature at - line 2, near "($a { }" +syntax error at - line 2, near "($a { }" +######## +sub t098 ($a; $b) { } +EXPECT +Illegal operator following parameter in a subroutine signature at - line 2, near "($a; " +syntax error at - line 2, near "($a; " +######## +sub t099 ($$) { } +EXPECT +Illegal character following sigil in a subroutine signature at - line 2, near "($" +syntax error at - line 2, near "$$) " +######## +# NAME global @_ in signature +sub t101 (@_) { } +EXPECT +Can't use global @_ in subroutine signature at - line 2, near "(@_" +######## +# NAME global %_ in signature +sub t102 (%_) { } +EXPECT +Can't use global %_ in subroutine signature at - line 2, near "(%_" + diff --git a/t/op/signatures.t b/t/op/signatures.t index 6edb4066d4d2..7860c2a6ca06 100644 --- a/t/op/signatures.t +++ b/t/op/signatures.t @@ -20,6 +20,7 @@ our $z; is $a, 123; } +# easier not to put these tests in t/lib/croak/signatures eval "#line 8 foo\nsub t004 :method (\$a) { }"; like $@, qr{syntax error at foo line 8}, "error when not enabled 1"; @@ -446,10 +447,6 @@ is eval("t131(456, 789, 987)"), undef; like $@, _create_flexible_mismatch_regexp('main::t131', 3, 2); is $a, 123; -eval "#line 8 foo\nsub t024 (\$a =) { }"; -is $@, - qq{Optional parameter lacks default expression at foo line 8, near "=) "\n}; - sub t025 ($ = undef) { $a // "z" } is prototype(\&t025), undef; is eval("t025()"), 123; @@ -589,15 +586,6 @@ is eval("t038(456, 789, 987)"), undef; like $@, _create_flexible_mismatch_regexp('main::t038', 3, 2); is $a, 123; -eval "#line 8 foo\nsub t030 (\$a = 222, \$b) { }"; -is $@, qq{Mandatory parameter follows optional parameter at foo line 8, near "\$b) "\n}; - -eval "#line 8 foo\nsub t031 (\$a = 222, \$b = 333, \$c, \$d) { }"; -is $@, <()"), undef; diff --git a/t/test.pl b/t/test.pl index d246b043edee..af208c5de97b 100644 --- a/t/test.pl +++ b/t/test.pl @@ -1327,11 +1327,15 @@ sub setup_multiple_progs { open my $fh, '<', $file or die "Cannot open $file: $!\n" ; my $found; + my $preamble = ""; while (<$fh>) { if (/^__END__/) { $found = $found + 1; # don't use ++ last; } + if (/^#\s+PREAMBLE\s+(.*)$/) { + $preamble .= "$1\n"; + } } # This is an internal error, and should never happen. All bar one of # the files had an __END__ marker to signal the end of their preamble, @@ -1346,6 +1350,12 @@ sub setup_multiple_progs { unless $found; my ($t, @p) = _setup_one_file($fh, $file); + if (length $preamble) { + # @p consists of ($linenumber, $source) pairs, so we only want + # to prepend the preamble to the odd numbered elements. + # Additionally, the first two elements are (0, $filename). + $_ = $preamble . $_ for @p[ grep { $_ % 2 } 2 .. $#p ]; + } $tests += $t; push @prgs, @p;