use_ok() can report a false-positive #149

rjray opened this Issue Aug 16, 2011 · 1 comment


None yet

2 participants

rjray commented Aug 16, 2011

Recently, I got a false-positive from use_ok() on a module that had been deleted from my distro, but was still being tested for in a test-suite. The reason I got this, is that because I had a previous version of the distro installed, the deprecated module lived under a site_perl somewhere. However, clean tests of my release by people such as CPAN Testers and the Debian team got test failures.

It might be worthwhile to consider having use_ok look at %INC after a successful "use" of the module, and see if it picked it up from lib/blib, or from a system location. Whether this case would warrant a failing test is questionable, but it should at least garner a warning.

schwern commented Aug 24, 2011

Sorry, but use_ok() is intended as a way to test use statements, not specifically to check the modules in the distribution being tested. Putting a special case check in for where the module loaded from would be against that purpose, reduce its utility and break many existing tests.

The use case you propose has merit, and you're free to write a version of use_ok() that adds the additional check. It's pretty straight forward...

sub use_local_ok {
    local $Test::Builder::Level = $Test::Builder::Level + 1;

    my($module, @args) = @_;

    use_ok($module, @args) or return;

    ...whatever else you want to add...

I'm going to close it up, but feel free to keep discussing.

@schwern schwern closed this Aug 24, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment