How do I go about testing a function or module that is machine or platform dependent? For example, something that looks at/depends on $^O
or a module like Net::Ifconfig::Wrapper? I don't need to test that Net::Ifconfig::Wrapper is returning the correct values, but I do need to test whether or not I'm doing the right thing with those values.
Thanks!
EDIT: Testing $^O
turned out to be easier than I thought:
{
# <~> $ perl -e 'print $^O'
# linux
local $^O = 'linux';
$rc = GetOSType();
is($rc, $OS_LINUX, 'OS Check - linux');
}
For some reason I thought it was a read-only variable.
To follow up on Jason's mock objects suggestion, you should take a look at the article "Interfacing with hard-to-test third party controls" by Misko Hevery. It directly addresses testing third party components.
Generally you use mock objects to "fake up" the results of those system calls.
During testing, use mock objects and have them return the various results you'd expect on different platforms, testing that your code reacts properly in those cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With