Hi perl-qa'er's,
I am puzzled as to how to get D::C to report that I ran a test over a sub. Lets start with some background.


I am using Test::More to write 't-files' for a module, and I am writing one t-file per subroutine. The subroutine is fully exercised in that t-file, all branches that are possible to reach.

I am also using the excellent Test::MockObject, to avoid setting up complex externalities. This mainly consists of replacing helper subs in the package (which go off and talk to an LDAP server) with their expected results.

Even though Test::More is reporting (via make test) that every test ran and I had a 100% pass, some subs (such as ldap_groups that I expand upon here) are marked by D::C as never being run - even though there is a whole t-file dedicated to just that sub that did indeed run.

The module has a sub 'ldap_groups()', that is in the @EXPORT_OK for the module.

   The t file is basically
<code>
#!/usr/bin/perl -w
# tests specific to the ldap_groups function
use strict;
use Test::More qw(no_plan);
use Test::MockObject;
use_ok( 'Monash::LDAP', qw( ldap_groups ) );
can_ok( 'Monash::LDAP', qw( ldap_groups ) );

my $mock = Test::MockObject->new();

# we work through the code, passing or failing code at each cond (if/unless)
# bad parameters first
is(ldap_groups(), 'Error: no filter supplied.');
# failing search
$mock->fake_module('Monash::LDAP',
                  ldap_do_search => sub($$) { },
                 );
is_deeply([ldap_groups(filter => 'filter')], []);

blah blah blah

</code>

Now, in order to get around the fact that use_ok('Monash::LDAP', ...) seems to stop D::C instrumenting Monash::LDAP, I call the test harness as

HARNESS_PERL_SWITCHES=-MDevel::Cover=-select,Monash/LDAP make test

However, I still get a report from cover that ldap_groups() is untested, even though Test::More says it passed 100%

From blib-lib-Monash-LDAP-pm--subroutine.html

<tr><td class="h"><a id="L793">793</a></td><td class="c0"><div class="s">ldap_groups</div></td></tr>

so the class="c0" means untested I imagine.

Is there some interaction with Test::More::use_ok that is stopping D::C instrumenting the module correctly ?

Is there some other switch in D::C I need to use ?

Leif Eriksen

Reply via email to