I develop a set of Perl scripts and modules that are then deployed to different machines and systems around our company. Some objects depend on a specific module, which may or may not be installed on different machines. I used 'eval' to determine if this module is available.
I just had a malfunction report, which boiled down to the fact that the user was unable to install the module on his machine (but did not understand that he did not): but the error in my code was that in this case I didn’t accepted the error condition to the top level, so it was lost, and the script simply did not execute part of its function.
To examine it, I disabled a specific module on my machine and easily found and fixed the problem. But the only way I could turn it off without deleting it was to rename the file (which I had to do through sudo, of course).
Now I am running all my tests with this module unavailable, and it has launched several other places where I am not handling the situation correctly.
But now I want to write some tests for this condition: but how can I reasonably make this module temporarily unavailable as part of an automatic test. I really don't want my tests to use sudo to move modules (I can do other things on the machine at the same time).
Does anyone know a way that I can tell Perl "Don't find this module, wherever I try to" use "or" require "it, for testing purposes"?
I am running Perl 5.10.0 (on Fedora 12) and using Test :: More and TAP :: Harness. Perl 5.8 works in some of our installations, so I am ready to use the 5.10 functions when testing, but not in the code itself.
source share