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

Testing a module that writes logs to a file

by Hue-Bond (Priest)
on Jun 09, 2008 at 13:55 UTC ( [id://691033]=perlquestion: print w/replies, xml ) Need Help??

Hue-Bond has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm writing a module that, among other things, writes logs to a file. Logs are kept in a subdirectory of /var/log, so the program can run as user (the subdirectory has the proper permissions). In the development environment all was good, since at the beginning I manually created the directory and set its permissions. Nevertheless, when installing the module in another machine, I found that the tests failed because when the module was going to write something to the logs, the directory didn't exist. Creating it manually wasn't an option, since that's make install responsibility. I needed make install /before/ make test...

A quick search through the monastery led me to testing log messages, and I decided to follow that route. I hadn't any problem and now the tests pass even when no logs are actually created.

However, I'd be surprised if I'd found the best solution in a 15 minute search ;^). Does a better option exist? (for any meaning of "better").

--
David Serrano

Replies are listed 'Best First'.
Re: Testing a module that writes logs to a file
by Corion (Patriarch) on Jun 09, 2008 at 14:02 UTC

    Make your logging directory configurable and for testing use (for example) t/var/log instead of /var/log. That way you can also test for graceful (or draconic) handling of exceptions like the logging directory not existing etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://691033]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found