Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: TAP test question

by brian_d_foy (Abbot)
on Jun 04, 2008 at 14:52 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://690157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found