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

Moose error can happen because of order in which roles are consumed #77

Open
zoan01 opened this issue May 9, 2017 · 3 comments
Open

Comments

@zoan01
Copy link

zoan01 commented May 9, 2017

user@host:~/app$ cat t/suite.t
use warnings;
use File::Spec::Functions qw( catdir );
use FindBin qw( $Bin );
use Test::Class::Moose::Load catdir( $Bin, 'lib/' );
use Test::Class::Moose::Runner;
Test::Class::Moose::Runner->new->runtests;

user@host:~/app$ cat t/lib/A.pm
package t::A;
use Test::Class::Moose;
with qw/t::Role/;

BEGIN { print "IN A\n";}

sub test_hey {
    ok 1, "hello";
}

1;

user@host:~/app$ cat t/lib/Role.pm
package t::Role;
use Test::Class::Moose::Role;

BEGIN { print "IN ROLE\n";}

sub test_role {
    ok 1, "from role";
}

1;

user@host:~/app$ prove -v t/suite.t
t/suite.t ..
IN A
You can only consume roles, t::Role is not a Moose role at /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/Moose/Exporter.pm line 419
        Moose::with('t::Role') called at /home/user/app/t/lib/A.pm line 4 
        require A.pm at (eval 7) line 1
        Test::Class::Moose::Load::BEGIN at /home/user/app/t/lib/A.pm line 0 
        eval {...} at /home/user/app/t/lib/A.pm line 0 
        eval 'use A ()' at /usr/local/share/perl/5.20.2/Test/Class/Moose/Load.pm line 54
        Test::Class::Moose::Load::_load('Test::Class::Moose::Load', '/home/user/app/t/lib/A.pm', '/home/user/app/t/lib') called at /usr/local/share/perl/5.20.2/Test/Class/Moose/Load.pm line 68
        Test::Class::Moose::Load::__ANON__ at /usr/share/perl/5.20/File/Find.pm line 796
        File::Find::_find_dir('HASH(0x1e4fb50)', '/home/user/app/t/lib', 3) called at /usr/share/perl/5.20/File/Find.pm line 578
        File::Find::_find_opt('HASH(0x1e4fb50)', '/home/user/app/t/lib') called at /usr/share/perl/5.20/File/Find.pm line 1081
        File::Find::find('HASH(0x1e4fb50)', '/home/user/app/t/lib') called at /usr/local/share/perl/5.20.2/Test/Class/Moose/Load.pm line 73
        Test::Class::Moose::Load::import('Test::Class::Moose::Load', '/home/user/app/t/lib') called at t/suite.t line 6 
        main::BEGIN at /home/user/app/t/lib/A.pm line 0 
        eval {...} at /home/user/app/t/lib/A.pm line 0 
Compilation failed in require at (eval 7) line 1.
BEGIN failed--compilation aborted at (eval 7) line 1.
BEGIN failed--compilation aborted at t/suite.t line 6.
Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run

Test Summary Report
-------------------
t/suite.t (Wstat: 65280 Tests: 0 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
Files=1, Tests=0,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.39 cusr  0.03 csys =  0.45 CPU)
Result: FAIL

user@host:~/app$ mv t/lib/A.pm t/lib/subdir/
user@host:~/app$ prove -v t/suite.t
t/suite.t ..
IN ROLE
IN A
1..1
ok 1 - t::A {
    1..2
    ok 1 - test_hey {
        ok 1 - hello
        1..1
    }
    ok 2 - test_role {
        ok 1 - from role
        1..1
    }
}
ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.66 cusr  0.01 csys =  0.71 CPU)
Result: PASS

There is a similar issue with test class inheritance where the child class must be loaded after the parent by forcing it into a subdirectory (found by adding debug statements in Test::Class::Moose::Load::import).

Regardless, very nice framework.

@autarch
Copy link
Member

autarch commented May 10, 2017

Thanks for reporting this. I'm not really sure why this is happening. If you can turn this into a PR with a failing test case, that'd make it much easier for me to fix it.

@autarch autarch changed the title Include order of Roles or Inherited Objects throws Moose error Moose error can happen because of order in which roles are consumed Dec 10, 2017
@autarch
Copy link
Member

autarch commented Dec 10, 2017

FWIW, I just tried replicating this with the latest Moose & TCM. I used the code you have above and I confirmed that the role was loaded before the class. I did not get the same error.

Can you try with the latest versions of Moose & TCM? I'm inclined to close this bug since it no longer seems to be a thing.

@glauschwuffel
Copy link

Hi,

I add some observations that might help.

When trying to install Test::Class::Moose@0.98 on an Ubuntu with 5.18.2 I noticed that the test program t/tags.t failed with You can only consume roles, TestsFor::Basic::Role is not a Moose role at /usr/lib/perl5/Moose/Util.pm.

This first failure of this kind is introduced with Test::Class::Moose version 0.85. Version 0.84 installs fine on 5.18.2.

I uploaded my test reports with cpanm-reporter, so they should show up in the CPANTesters matrix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants