Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

converted remaining compile-time errors

using the new sig_parsing_error() function
this should polish off the last of GitHub #61
  • Loading branch information...
commit a07834c01e0e3e61cf2f35f525497fcbaa31c955 1 parent 59809ca
@barefootcoder barefootcoder authored
View
12 lib/Method/Signatures.pm
@@ -926,22 +926,22 @@ sub _check_sig {
my($self, $sig, $signature) = @_;
if( $sig->{is_slurpy} ) {
- $self->signature_error("signature can only have one slurpy parameter") if
- $signature->{overall}{num_slurpy} >= 1;
- $self->signature_error("slurpy parameter $sig->{var} cannot be named, use a reference instead") if
- $sig->{named};
+ sig_parsing_error("Signature can only have one slurpy parameter")
+ if $signature->{overall}{num_slurpy} >= 1;
+ sig_parsing_error("Slurpy parameter '$sig->{var}' cannot be named; use a reference instead")
+ if $sig->{named};
}
if( $sig->{named} ) {
if( $signature->{overall}{num_optional_positional} ) {
my $pos_var = $signature->{positional}[-1]{var};
- die("named parameter $sig->{var} mixed with optional positional $pos_var\n");
+ sig_parsing_error("Named parameter '$sig->{var}' mixed with optional positional '$pos_var'");
}
}
else {
if( $signature->{overall}{num_named} ) {
my $named_var = $signature->{named}[-1]{var};
- die("positional parameter $sig->{var} after named param $named_var\n");
+ sig_parsing_error("Positional parameter '$sig->{var}' after named param '$named_var'");
}
}
}
View
4 t/array_param.t
@@ -21,12 +21,12 @@ use Test::More tests => 3;
eval q{
method two_array_params ($a, @b, @c) {}
};
- like($@, qr{signature can only have one slurpy parameter}, "Two array params");
+ like($@, qr{signature can only have one slurpy parameter}i, "Two array params");
eval q{
method two_slurpy_params ($a, %b, $c, @d, $e) {}
};
- like($@, qr{signature can only have one slurpy parameter}, "Two slurpy params");
+ like($@, qr{signature can only have one slurpy parameter}i, "Two slurpy params");
}
is(Bla->new->array_param_at_end(1, 2, 3, 4), "1|2|3 4", "Array parameter at end");
View
29 t/error_reporting.t
@@ -45,6 +45,22 @@ my %compile_time_errors =
],
test_name => 'trailing code after param reports correctly',
},
+ NamedAfterOptPos => {
+ error_gen => 'named_after_optpos_error',
+ error_args => [
+ '$baz',
+ '$bar',
+ ],
+ test_name => 'named param following optional positional reports correctly',
+ },
+ PosAfterNamed => {
+ error_gen => 'pos_after_named_error',
+ error_args => [
+ '$baz',
+ '$bar',
+ ],
+ test_name => 'positional param following named reports correctly',
+ },
MispositionedSlurpy => {
error_gen => 'mispositioned_slurpy_error',
error_args => [
@@ -52,6 +68,19 @@ my %compile_time_errors =
],
test_name => 'mispositioned slurpy param reports correctly',
},
+ MultipleSlurpy => {
+ error_gen => 'multiple_slurpy_error',
+ error_args => [
+ ],
+ test_name => 'multiple slurpy params reports correctly',
+ },
+ NamedSlurpy => {
+ error_gen => 'named_slurpy_error',
+ error_args => [
+ '@bar',
+ ],
+ test_name => 'named slurpy param reports correctly',
+ },
);
my %run_time_errors =
View
40 t/lib/GenErrorRegex.pm
@@ -4,8 +4,12 @@ use strict;
use warnings;
use base qw< Exporter >;
-our @EXPORT_OK = (qw< bad_param_error unexpected_after_error mispositioned_slurpy_error >, # compile-time
- qw< required_error named_param_error badval_error badtype_error >); # run-time
+our @EXPORT_OK =
+(
+ qw< bad_param_error unexpected_after_error named_after_optpos_error pos_after_named_error >, # compile-time
+ qw< mispositioned_slurpy_error multiple_slurpy_error named_slurpy_error >, # compile-time
+ qw< required_error named_param_error badval_error badtype_error >, # run-time
+);
sub _regexify
@@ -61,6 +65,22 @@ sub unexpected_after_error
}
+sub named_after_optpos_error
+{
+ my ($named, $optpos, %extra) = @_;
+
+ return _regexify(COMPILE_TIME => "Named parameter '$named' mixed with optional positional '$optpos'", %extra);
+}
+
+
+sub pos_after_named_error
+{
+ my ($pos, $named, %extra) = @_;
+
+ return _regexify(COMPILE_TIME => "Positional parameter '$pos' after named param '$named'", %extra);
+}
+
+
sub mispositioned_slurpy_error
{
my ($param, %extra) = @_;
@@ -69,6 +89,22 @@ sub mispositioned_slurpy_error
}
+sub multiple_slurpy_error
+{
+ my (%extra) = @_;
+
+ return _regexify(COMPILE_TIME => "Signature can only have one slurpy parameter", %extra);
+}
+
+
+sub named_slurpy_error
+{
+ my ($param, %extra) = @_;
+
+ return _regexify(COMPILE_TIME => "Slurpy parameter '$param' cannot be named; use a reference instead", %extra);
+}
+
+
####################################################################################################
# RUN-TIME ERRORS
# These should know what package and method they're dealing with, so they will all take an $obj
View
15 t/lib/MultipleSlurpy.pm
@@ -0,0 +1,15 @@
+package MultipleSlurpy;
+
+use strict;
+use warnings;
+
+use Method::Signatures;
+
+
+# the #line directive helps us guarantee that we'll always know what line number to expect the error
+# on, regardless of how much this test module changes
+#line 1133
+func foo ( @bar, @baz ) {}
+
+
+1;
View
15 t/lib/NamedAfterOptPos.pm
@@ -0,0 +1,15 @@
+package NamedAfterOptPos;
+
+use strict;
+use warnings;
+
+use Method::Signatures;
+
+
+# the #line directive helps us guarantee that we'll always know what line number to expect the error
+# on, regardless of how much this test module changes
+#line 1133
+func foo ( $bar?, :$baz ) {}
+
+
+1;
View
15 t/lib/NamedSlurpy.pm
@@ -0,0 +1,15 @@
+package NamedSlurpy;
+
+use strict;
+use warnings;
+
+use Method::Signatures;
+
+
+# the #line directive helps us guarantee that we'll always know what line number to expect the error
+# on, regardless of how much this test module changes
+#line 1133
+func foo ( :@bar ) {}
+
+
+1;
View
15 t/lib/PosAfterNamed.pm
@@ -0,0 +1,15 @@
+package PosAfterNamed;
+
+use strict;
+use warnings;
+
+use Method::Signatures;
+
+
+# the #line directive helps us guarantee that we'll always know what line number to expect the error
+# on, regardless of how much this test module changes
+#line 1133
+func foo ( :$bar, $baz ) {}
+
+
+1;
View
8 t/named.t
@@ -39,22 +39,20 @@ use Test::More;
'simple named parameter error okay';
- # Compile time errors need internal refactoring before I can get file, line and method
- # information.
eval q{
method wrong( :$named, $pos ) {}
};
- like $@, qr/positional parameter \$pos after named param \$named/;
+ like $@, qr/positional parameter .* after named param/i;
eval q{
method wrong( $foo, :$named, $bar ) {}
};
- like $@, qr/positional parameter \$bar after named param \$named/;
+ like $@, qr/positional parameter .* after named param/i;
eval q{
method wrong( $foo, $bar?, :$named ) {}
};
- like $@, qr/named parameter \$named mixed with optional positional \$bar/;
+ like $@, qr/named parameter .* mixed with optional positional/i;
}
View
6 t/slurpy.t
@@ -27,7 +27,7 @@ use Test::Exception;
}
ok !eval q[func slurpy_middle($this, @that, $other) { return $this, \@that, $other }];
- like $@, qr{Slurpy parameter '\@that' must come at the end};
+ like $@, qr{slurpy parameter .* must come at the end}i;
TODO: {
local $TODO = "error message incorrect inside an eval";
@@ -36,7 +36,7 @@ use Test::Exception;
}
ok !eval q[func slurpy_positional(:@that) { return \@that; }];
- like $@, qr{slurpy parameter \@that cannot be named, use a reference instead};
+ like $@, qr{slurpy parameter .* cannot be named. use a reference instead}i;
TODO: {
local $TODO = "error message incorrect inside an eval";
@@ -46,7 +46,7 @@ use Test::Exception;
}
ok !eval q[func slurpy_two($this, @that, @other) { return $this, \@that, \@other }];
- like $@, qr{can only have one slurpy parameter at \Q$0\E line @{[__LINE__ - 1]}};
+ like $@, qr{can only have one slurpy parameter};
}
Please sign in to comment.
Something went wrong with that request. Please try again.