Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 <>
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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-04-23 08:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found