Skip to content

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

@zoan01

Description

@zoan01
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions