Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: TAP test question

by brian_d_foy (Abbot)
on Jun 04, 2008 at 14:52 UTC ( #690157=note: print w/ replies, xml ) Need Help??


in reply to TAP test question

When I want to test that a subroutine is now in my namespace, I check that the subroutine isn't yet defined, do the import, then check that the subroutine is defined:

BEGIN { ok( ! defined( &some_func, "some_func not defined yet" ); use_ok( 'MyModule::Common', ':all' ); ok( defined( &some_func, "some_func was imported" ); }

or if I care about testing the import method because I'm doing something tricky:

BEGIN { my $class = 'MyModule::Common'; ok( ! defined( &some_func, "some_func not defined yet" ); require_ok( $class ); ok( $class->import, "import returns true" ); ok( defined( &some_func, "some_func was imported" ); }

If you're relying on %EXPORT_TAGS and what to make sure it exports everything it is supposed to (meaning, most likely, that you told it to export the right things, you can look in %EXPORT_TAGS and see if each of those things are now defined in your current namespace. That can be a bit messy though.

Generally, I like to give each function its own test file, where I do extensive testing on it. If it should be in the :all tag, I'll test that it is exported just like I did in my code example. I don't worry about testing the the :all tag in a single test. I let the individual subroutine tests figure that out.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review


Comment on Re: TAP test question
Select or Download Code
Re^2: TAP test question
by knbknb (Acolyte) on Jun 04, 2008 at 16:57 UTC
    Thanks for answering. Please see my reply to the first answer on what I intended to do. my second post was submitted a bit late.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://690157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-08-31 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls