Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 945
Joe Casadonte Avatar asked Jan 22 '09 20:01

Joe Casadonte


2 Answers

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.

like image 133
Gavin Miller Avatar answered Sep 28 '22 15:09

Gavin Miller


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.

like image 23
Jason Cohen Avatar answered Sep 28 '22 15:09

Jason Cohen