What scenario are you envisioning that a print failing will be the sole indicator of a failure state?
You can have a print fail due to, for example, lack of space on the device and then have the close succeed later on.
There's also the argument that it's better to FailFast.
| [reply] |
If you're printing to a filehandle, then use a IO::File-derived class that will encapsulate that die for you, and test that. I'm not quite sure how STDOUT or STDERR runs out of space, though.
- In general, if you think something isn't in Perl, try it out, because it usually is. :-)
- "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
| [reply] |
I'm not quite sure how STDOUT or STDERR runs out of space
$ script.pl orig.txt 2> /var/log/errors.log > new.txt && rm new.txt
| [reply] [d/l] |
I'm helping a workmate write his first ever tests for
a new function he added to an existing module.
Seeing that his new function had:
open ... or die ...
print ... or die ...
I suggested it is good form to write tests for exceptional conditions ... then realized I had no idea how to do it. :-)
BTW, Devel::Cover
also nags you if you don't test the or die
branches.
| [reply] [d/l] [select] |
use Fatal qw( print );
As for Devel::Cover ... I shoot for 90%+ coverage. There are several good conversations on D::C and why attempting to achieve 100% is ... well ... dumb. :-)
- In general, if you think something isn't in Perl, try it out, because it usually is. :-)
- "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
| [reply] [d/l] |
adding "or die" to print is kinda ... dumb.
That entirely depends on the application being developed. I've come across several apps where not checking for the result of print has caused some nasty and expensive intermittent bugs.
(Which is why I wish that print, open, read, etc. threw exceptions by default if called in a void context... Fixed in Perl 6 I think?)
Update: and
use Fatal qw( print );
won't work since print is one of those subroutines that Perl can't override cleanly.
| [reply] [d/l] |