Hi Monks,

Full disclosure: I am new to both Moose and Test::Class::Moose. I'm trying to get Ovid's first example from here working. The example compiles and runs, but attempts to test itself (or at least, one of its internal dependencies) instead of my Person class.

I'm running perl 5.18.2 on a brand-new Fedora Core 20 installation.

The code:

t/lib/Person.pm

use Modern::Perl '2014';

package Person;

use Moose;
use namespace::autoclean;

has  'first_name', 'last+nanme'  => (
    is       => 'ro',
    isa      => 'Str',
    required => 1,
);

sub full_name {
    my $self = shift;
    return join ' ' => $self->first_name, $self->last_name;
}

__PACKAGE__->meta->make_immutable;

1;

t/lib/My/Test/Class.pm

use Modern::Perl '2014';

use Test::Class::Moose;

INIT {
    Test::Class::Moose->new(
        show_timing => 0,
        randomize   => 0,
        statistics  => 1,
    )->runtests;
}

1;

tt/lib/TestsFor/Person.pm

use Modern::Perl '2014';

# Note: I had to include this line to get it to compile.
# "prove -l tt/lib ... didn't cut it.
use lib 'tt/lib';

package TestsFor::Person;
use Test::Class::Moose parent => 'My::Test::Class';

sub test_constructor {
    my $test = shift;

    my $class = $test->class->name;
    ok my $person = Person->new(
        first_name => 'Bob',
        last_name => 'Dobbs',
    ), 'We should have a test person';

    isa_ok $person, $class, '... and object it returns';
    is $person->full_name, 'Bob Dobbs',
        '... and it should report the correct full name';
}

1;

Here's what I get when I run it:

$ prove -lv tt/lib/TestsFor/Person.pm
tt/lib/TestsFor/Person.pm ..
1..1
#
# Running tests for Module::Runtime
#
    # Subtest: Module::Runtime
    1..0 # SKIP Skipping 'Module::Runtime': no test methods found
ok 1 # skip Skipping 'Module::Runtime': no test methods found
# Test classes:    1
# Test methods:    0
# Total tests run: 0
ok
All tests successful.
Files=1, Tests=1,  1 wallclock secs ( 0.03 usr  0.01 sys +  0.61 cusr  0.02 csys =  0.67 CPU)
Result: PASS

What am I doing wrong?

Thanks,

Larry


In reply to Test::Class::Moose ignores my tests by 1arryb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.