Search code examples
perlunit-testingtddmultiplatform

How do I do Perl machine or platform dependent TDD?


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.


Solution

  • 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.