houseabsolute / p5-Test-Vars

Detects unused variables in unit tests
https://metacpan.org/pod/Test::Vars
Other
6 stars 10 forks source link

Can't locate object method "ARRAYelt" via package "B::NULL" #15

Closed andyjack closed 9 years ago

andyjack commented 9 years ago

In a Moose role with a stub sub declaration, test_vars dies with the above error

package Bar;

use Moose::Role;

sub xyz;

has xyz => (
    is      => 'ro',
    isa     => 'Str',
    default => 'Bar',
);

no Moose::Role;
1;
$ perl -MTest::Vars -le 'use strict; use warnings; test_vars("lib/Bar.pm")'
Can't locate object method "ARRAYelt" via package "B::NULL" at /opt/perl5.20.2/lib/site_perl/5.20.2/Test/Vars.pm line 275.
Magic number checking on storable string failed at /opt/perl5.20.2/lib/5.20.2/x86_64-linux/Storable.pm line 418, at /opt/perl5.20.2/lib/site_perl/5.20.2/Test/Vars.pm line 86.

$ perl -MTest::Vars -le 'print $Test::Vars::VERSION'
0.007
andyjack commented 9 years ago

Some more information, moving sub xyz after the has doesn't cause the error anymore, vars_ok works, but test_vars has a different error:

package Baz;

use Moose::Role;

has xyzzy => (
    is      => 'ro',
    isa     => 'Str',
    default => 'Baz',
);

sub xyzzy;

no Moose::Role;
1;
$ perl -MTest::Vars -le 'use strict; use warnings; test_vars("lib/Baz.pm")'
Can't use an undefined value as a subroutine reference at /opt/perl5.20.2/lib/site_perl/5.20.2/Test/Vars.pm line 89, <GEN0> line 4.

$ perl -MTest::Vars -le 'use strict; use warnings; vars_ok("lib/Baz.pm")'
ok 1 - lib/Baz.pm
# checking Baz in Baz.pm ...
# Tests were run but no plan was declared and done_testing() was not seen.
autarch commented 9 years ago

test_vars requires a coderef as its second argument.

autarch commented 9 years ago

Fixed in 0.008.