views:

176

answers:

3

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.

A: 

Why not a VM?

Jason Punyon
+3  A: 

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.

Jason Cohen
For whatever wacked-out reason, when I posted this I was thinking that I had to mock what Net::Ifconfig::Wrapper called, not Net::Ifconfig::Wrapper itself. I can only plead temporary insanity as a defense....
Joe Casadonte
+4  A: 

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.

Gavin Miller