Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suppress "...at line..." in _croak if end newline #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Function/Parameters.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use Scalar::Util qw(blessed);

sub _croak {
my (undef, $file, $line) = caller 1;
die @_, " at $file line $line.\n";
push @_, " at $file line $line.\n" unless $_[-1] =~ /\n\z/;
die @_;
}

use XSLoader;
Expand Down
28 changes: 27 additions & 1 deletion t/croak.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings FATAL => 'all';

use Test::More tests => 12;
use Test::More tests => 13;
use Test::Fatal;

use Function::Parameters {
Expand Down Expand Up @@ -56,3 +56,29 @@ is exception { Crabs::worngkw4 }, "In fun takekw: no such named

is exception { Crabs::taket "X" }, "In fun taket: parameter 1 (\$x): A failure (Cool[Story]) of X at ${\__FILE__} line ${\__LINE__}.\n";
is exception { Crabs::worngt1 }, "In fun taket: parameter 1 (\$x): A failure (Cool[Story]) of X at ${\__FILE__} line ${\($marker + 14)}.\n";

use Function::Parameters {
fun => { defaults => 'function_strict', reify_type => \&MyT2::reify_type },
method => 'method_strict',
};

{
package MyT2;

fun reify_type($type) {
bless [$type], __PACKAGE__
}

method check($value) { 0 }

method get_message($value) {
"A failure ($self->[0]) of $value.\n"
}
}

{
package Crabs2;
fun taket(Cool[Story] $x) {}
}

is exception { Crabs2::taket "X" }, "In fun taket: parameter 1 (\$x): A failure (Cool[Story]) of X.\n";