A ghetto test library.
I've been working on some slightly complicated code with a myriad of bad design decisions over the course of a decade, and a total absence of test suite. I knew I needed some code reusability in my tests but I had no idea of exactly how much without making a quick start. Meanwhile my brain was filled with ancient code from which I was expurgating zombies, and had issues understanding multi-vendor interactions, so I wanted some bare minimum reusability to make engineering failure conditions easier.
So, I was working in a subdirectory of t
: t/my_functionality
.
#!/usr/bin/env perl
use warnings;
use strict
use Test::More;
use File::Basename;
use lib dirname(__FILE__) ."/lib";
use MyGhettoLib;
ok(everything_fine(), "Everything is fine :)";
done_testing;
Then in t/my_functionality/MyGhettoLib.pm:
package MyGhettoLib;
use warnings;
use strict;
package main;
sub everything_fine {
return 1;
}
1;
Yes, shifting to package main
is a little bit stupid and a little
bit evil. The solution does not scale, but it gives the bare minimum
of reusability without having to apply much thought. And a surface
for redesign should the need for further abstraction of the test
libary arise.
Leave a comment