Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Unit testing built-in functions

by davidrw (Prior)
on Nov 08, 2006 at 23:12 UTC ( [id://582994]=note: print w/replies, xml ) Need Help??


in reply to Unit testing built-in functions

per perldoc for unlink, it returns the number of files deleted .. so can you just change the calls to something like this?
if( unlink( $filename ) != 1 ){ die "couldn't unlink '$filename': $!; } # or: unlink( $filename ) or die "couldn't unlink '$filename': $!;
Your unit tests could also check for both the existance before the unlink, and non-existence afterward ...

Replies are listed 'Best First'.
Re^2: Unit testing built-in functions
by ikegami (Patriarch) on Nov 09, 2006 at 00:01 UTC

    I believe you misunderstood. The OP wants to override unlink so he can test how the script handles errors from unlink. He's not asking how to check if unlink returned an error.

    We do something similar at my workplace. In our test environment, we hook into the OS to control the exit codes returned by the disk reading function, the analog input reading function, the analog output writing function, etc. to ensure that our software properly handles those errors.

      Yes, exactly.

      I want to get built-in functions to return specific values when called from specific test cases.

      It looks like over-rides and globals will be the easiest way to go so far.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found