Test::Exports - Test that modules export the right symbols
use Test::More; use Test::Exports; require_ok "My::Module" or BAIL_OUT "can't load module"; import_ok "My::Module", , "default import OK"; is_import qw/foo bar/, "My::Module", "imports subs"; new_import_pkg; import_ok "My::Module", ["foo"], "named import OK"; is_import "foo", "My::Module", "imports foo"; cant_ok "bar", "doesn't import bar";
This module provides simple test functions for testing other modules'
import methods. Testing is currently limited to checking which subs have been imported.
In order to keep different calls to
->import separate, Test::Exports performs these calls from a private package. The symbol-testing functions then test whether or not symbols are present in this private package, ensuring none of this interferes with your test script itself.
These are all exported by default, as is usual with testing modules.
Create a new package to perform imports into. This is useful when you want to test
->import with different arguments: otherwise you'd need to find some way of going back and clearing up the imports from the last call.
This returns the name of the new package (which will look like
Test::Exports::TestAAAAB) in case you need it.
$module->import from the current testing package, passing
@args, and check the call succeeded. 'Success' means not throwing an exception:
use doesn't care if
import returns false, so neither do we.
@args defaults to the empty list;
$name defaults to something sensible.
$module->import(@args) and expect it to throw an exception. Defaults as for "import_ok".
For each name in
@subs, check that the current testing package has a sub by that name and that it is the same as the equinominal sub in the
$name are optional.
For each sub in @subs, check that a sub of that name does not exist in the current testing package. If one is found the diagnostic will indicate where it was originally defined, to help track down the stray export.
Currently this just checks that
\&Our::Pkg::sub == \&Your::Pkg::sub, which means
it is impossible to test for exports which have been renamed, and
we can't be sure the sub originally came from Your::Pkg: it may have been exported into both packages from somewhere else.
It would be good to fix at least the former.
Ben Morrow <firstname.lastname@example.org>
Please report any bugs to <bug-Test-Exports@rt.cpan.org>.
Copyright 2010 Ben Morrow.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.