We have written parsers for different scientific data formats in Perl. Recently I added a test suite with a parser_*.t
file for every format and subformat.
Of course, the API of the parsers is exactly the same only the data read from the example files that are used for testing parsing differs. To simplify the test files I wrote a sub that gets passed the parser object and a hash structure representing the expected data. It looks like
my $parser = new MyApp::Parser($file);
test_nested_objects = ($parser, {
property1 => "value",
property2 => 123,
subobject_accessor => {
property3 => "foobar",
}
}
The sub test_nested_objects
walks through the hash and runs tests for all properties defined in the hash, e.g. if subobject_accessor
can be called, returns an object and that object can be called property3
.
I checked how many tests are run by the whole *.t
file and added tests => 123
to all *.t
files. Now, I added some checks to the generic function and all plans are wrong.
How to make my plan aware of the subtests? I'd like to achieve the following:
- number of tests given before running them for view of progess
- total number increased automatically → no changing of numbers by hand when editing the sub
- individual tests in sub visible when running prove (hiding tests in sub and returning just 0 or 1 isn't acceptable because I really need to know what is wrong with the parsed data)
I hope you can understand. Sorry for the long story but I thought people would probably not understand without some background knowledge.