I have used a similar technique to subvert Perl builtins and mimic system errors:
use Errno qw( ENOSPC );
{
local *CORE::GLOBAL::print = sub { $! = ENOSPC; return};
# make test call
# see what happens when a device is full
}
A finer grained and more accurate test can be obtained by localizing an open file handle:
{
open local(LOG), '>>', '/dev/full' or die $!;
# /dev/full is a Linux thing
# call the test
}
++
adrianh for bringing this up, there is a wealth of devious fun in this idiom.
After Compline,
Zaxo