Hi nysus,
I know the feeling exactly :-) I think the only good answer is "it depends", so I'd suggest you try to get a broad spectrum of input of how others do it, and gain your own experience.
Here's some of my thoughts about whether parameters should be validated and whether to test that:
- What kind of failure can be expected if the user passes a wrong parameter? E.g. parameters that cause files to be edited or even deleted should probably be checked in detail, but if e.g. it's a value that would cause Perl to issue a warning message or make an incorrect calculation, maybe the user of your code needs to track that issue down on their own.
- Who is the intended audience? How user friendly do you want the code to be?
- How user friendly does the code need to be? Also: after gaining some experience with the API, which parameters do the users get wrong most often?
- What metric are you testing by? For example, even 90-100% code coverage doesn't necessarily require you to fiddle with every argument.
- Personally, I rarely check the content of error messages my code generates. Sometimes, when my code generates a custom warning for example, will I check that it does get generated.
- Consider what you're testing for: If you use e.g. Params::Validate, and that module is well-tested, are your tests just double-checking that it works?
Hope this helps,
-- Hauke D
Update: Minor rewording & reorg. and added the last item to the list.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.