Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Testing failures: How to override print to make it fail?

by eyepopslikeamosquito (Chancellor)
on May 05, 2005 at 13:31 UTC ( #454355=note: print w/replies, xml ) Need Help??


in reply to Re: Testing failures: How to override print to make it fail?
in thread Testing failures: How to override print to make it fail?

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.

Replies are listed 'Best First'.
Re^3: Testing failures: How to override print to make it fail?
by dragonchild (Archbishop) on May 05, 2005 at 13:35 UTC
    print() is generally considered one of those functions that "Just Works". adding "or die" to print is kinda ... dumb.

    Of course, if you absolutely had to test print's success or failure, you could

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://454355]
help
Chatterbox?
Discipulus manual work: i just tell the same to my boss: every time the quick solution is to assign some manual data entry task to my group.. because we have not direct access to many databases here..
[LanX]: point is: in high speed trade each bank has to remember what he has to get from the others... so dresdner got billed for losses but couldn't claim gains
Discipulus is this the IT?
[Corion]: Discipulus: Well, in many cases it doesn't make sense to build an interface and complicated program just to enter 20 rows into a database ;) But yes, automating data imports should pay off in the long run
[LanX]: Choroba: this happened before I joined, was still in uni, but my boss was summoned to the CEO of the second biggest German bank at that time and could only say " I told them its not ready" ;)
[LanX]: memories....I missed my connection while chatting
[Discipulus]: in this case Corion we are speaking about software licensing: evry year or two we must rescan the whole ced to produce an excel report, while at every activation / disactivation we update a black box DB: i said that i a week i can produce the perl to..

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-03-29 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (350 votes). Check out past polls.