I just finished wrapping libstatgrab into Unix::Statgrab
. It would now be time to add the tests (yes, I don't write them in beforehand). But how am I to write tests for a library that is designed to return different results for each platform and each machine even?
Maybe I just have the tests call each function/method and make sure that they at least do not segfault. I think pulling out values from Config.pm
and testing some of them against what the libary figures out is a bit too hairy.
On the upside though, this C library is deliberately portable among several unices so I wont have to worry about compilation issues, I hope.
Re:test it with values that you know...
ethan on 2004-05-26T08:40:39
For some functions it might be that you have to test it with a value that you experienced with a special OS/CPU combination.
This sounds extremely fragile to me. At some point, a new release of the operating system is being made and suddenly the values I experienced may have changed.
I eventually did find a solution, although not a very convincing one admittedly. I call every function in the module (that's easy because none of the functions take any argument). If the return value is an object, I call each available method upon this object. When done for one function, I do anok(1)
.
So the only thing I test is that none of the functions or methods segfaults which makes some sense for an XS module. Whether they return the right value is not my concern but rather the concern of the underlying library which I haven't written.