mauke / Function-Parameters

Function::Parameters - define functions and methods with parameter lists ("subroutine signatures")
https://metacpan.org/pod/Function::Parameters
18 stars 19 forks source link

2.001003: self test failure #33

Closed 0-wiz-0 closed 6 years ago

0-wiz-0 commented 6 years ago

On NetBSD with perl-5.26.1, Package-DeprecationManager-0.17, and Moose-2.2006, one self test fails:

t/foreign/Fun/name.t .................................... 1/?
#   Failed test at t/foreign/Fun/name.t line 25.
#                   'abc 123 at t/foreign/Fun/name.t line 15.
#       Foo::foo("\"abc\"", 123) called at t/foreign/Fun/name.t line 19
#       eval {...} called at t/foreign/Fun/name.t line 18
# '
#     doesn't match '(?^:^abc 123 at t\/foreign\/Fun\/name\.t line 15\.?\n\tFoo::foo\((["'])abc\1, 123\) called at t\/foreign\/Fun\/name\.t line 19)'
# Looks like you failed 1 test of 2.
t/foreign/Fun/name.t .................................... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests
mauke commented 6 years ago

That looks more like Carp is broken. confess shouldn't add two sets of quotation marks around strings ("\"abc\""). Which version of Carp is this?

0-wiz-0 commented 6 years ago

Carp is the version coming with perl-5.26.1, which is 1.42 according to corelist -a Carp.

mauke commented 6 years ago

What output do you get with this modified test?

#!perl
use strict;
use warnings FATAL => 'all';
use Test::More;

use Carp;

my $file = __FILE__;
my $line = __LINE__;

{
    package Foo;
    #use Function::Parameters;
    sub foo { my ($x, $y) = @_;
        Carp::confess "$x $y";
    }

    eval {
        foo("abc", "123");
    };

    my $line_confess = $line + 6;
    my $line_foo = $line + 10;

    ::like($@, qr/^abc 123 at \Q$file\E line $line_confess\.?\n\tFoo::foo\((["'])abc\1, 123\) called at \Q$file\E line $line_foo/);
}

SKIP: { skip "Sub::Name required", 1 unless eval { require Sub::Name };

{
    package Bar;
    #use Function::Parameters;
    *bar = Sub::Name::subname(bar => sub { my ($a, $b) = @_; Carp::confess($a + $b) });

    eval {
        bar(4, 5);
    };

    my $line_confess = $line + 24;
    my $line_bar = $line + 27;

    ::like($@, qr/^9 at \Q$file\E line $line_confess\.?\n\tBar::bar\(4, 5\) called at \Q$file\E line $line_bar/);
}

}

done_testing;
0-wiz-0 commented 6 years ago

When I put that in a file test in the scratch environment where I build Function-Parameters and run perl on it, I see:

# perl test
not ok 1
#   Failed test at test line 25.
#                   'abc 123 at test line 15.
#       Foo::foo("\"abc\"", 123) called at test line 19
#       eval {...} called at test line 18
# '
#     doesn't match '(?^:^abc 123 at test line 15\.?\n\tFoo::foo\((["'])abc\1, 123\) called at test line 19)'
ok 2
1..2
# Looks like you failed 1 test of 2.
mauke commented 6 years ago

OK, that means something in your environment is broken because this new file doesn't even use Function::Parameters anymore.

0-wiz-0 commented 6 years ago

So what is the proper module to report this problem too, Carp?

mauke commented 6 years ago

I think so, yes. The only thing in there is normal function calls and eval {} to catch the exception. It looks like some kind of bug in the way Carp generates the stack trace.

0-wiz-0 commented 6 years ago

Since Carp is part of perl base (the separate Carp module on CPAN is older), I've filed a perlbug: https://rt.perl.org/Ticket/Display.html?id=132448

0-wiz-0 commented 6 years ago

The problem was with a patch for perl in pkgsrc. The patch has now been removed. Thanks for the help!