XP is just a number | |
PerlMonks |
Re^8: Developing a module, how do you do it ?by tobyink (Canon) |
on Mar 04, 2012 at 07:53 UTC ( [id://957738]=note: print w/replies, xml ) | Need Help?? |
As I have already said, Test::Simple/Test::More, etc give you the file and line number out of the box, without needing to name the test. But consider:
If you ever provide an argument for die, you've just provided a name for a test. Is that "asinine make-work"? Besides which, if the line in question is in a loop, a file name and line number might not be enough - a name can be very useful to figure out what's gone wrong.
A failure on line 8 doesn't give you a clue what test has failed. A failure on line 8 named "Factorial of 5" does. $ perl factorial.t 1..7 ok 1 - Factorial of 0 ok 2 - Factorial of 1 ok 3 - Factorial of 2 ok 4 - Factorial of 3 ok 5 - Factorial of 4 not ok 6 - Factorial of 5 # Failed test 'Factorial of 5' # at factorial.t line 8. # got: '120' # expected: '100' ok 7 - Factorial of 6 # Looks like you failed 1 test of 7. In this case, looking at the output, it's clear where the failure is, and checking the factorial of 5 on a calculator, it's the expected result which is in fact incorrect - my ultra-useful Maths package appears to be bug-free. Though an improvement might be to die if called with a negative number.
ok 1 - Factorial of 0 ok 2 - Factorial of 1 ok 3 - Factorial of 2 ok 4 - Factorial of 3 ok 5 - Factorial of 4 ok 6 - Factorial of 5 ok 7 - Factorial of 6 ok 8 - Factorial of negative number 1..8
In Section
Seekers of Perl Wisdom
|
|