Skip to content
This repository

use_ok() can report a false-positive #149

Closed
rjray opened this Issue August 16, 2011 · 1 comment

2 participants

Randy J. Ray Michael G. Schwern
Randy J. Ray

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.

Michael G. Schwern
Owner

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.

Michael G. Schwern schwern closed this August 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.