Problems? Is your data what you think it is? | |
PerlMonks |
RFC: Test::Cases -- Worth releasing?by xdg (Monsignor) |
on Sep 16, 2005 at 14:59 UTC ( [id://492638]=perlquestion: print w/replies, xml ) | Need Help?? |
xdg has asked for the wisdom of the Perl Monks concerning the following question: Dear Monks, I'm finding a lot of my testing boils down to taking some input, manipulating it, and comparing it to some output. It's fairly simple to put the inputs and expected outputs in a data structure and loop over them (c.f. my coment in Re^2: Wanted, more simple tutorials on testing). However, as I add cases, the data structure winds up dominating the test file and managing it or finding things in the middle when a case fails become challenging. One option to clean it up a bit is putting cases into the __DATA__section and pulling them out from there. This is the approach that Test::Base takes. Test::Base is really cool, but I'd rather avoid that because it's a Spiffy module and I wouldn't want that as a dependency just to test something I wrote that isn't using Spiffy already. What I've been doing lately instead is sticking my test cases into individual files in a subdirectory, and then iterating over them as so: For each file:
Rather than repeating that in every test file, I've put it into a test helper module that also:
It would be fairly trivial to package this up as a module for CPAN and add some additional callbacks so that it manages the file manipulation and users only have to provide processing functions and a test function if the default is() test isn't what's needed. It's not really doing all that much -- but it does avoid having to write the same helper code over and over for common input/output testing and makes managing test cases as simple as manipulating small text files in a directory tree. Is there demand for this? Would people find it useful enough to include as a dependency with their own modules? (Have I overlooked some existing test module that does this already?) For a name, I'm considering just Test::Cases or maybe Test::Casefiles. Other ideas? Thanks, -xdg Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
Back to
Seekers of Perl Wisdom
|
|