On Mon, Apr 15, 2013 at 11:35:22AM -0700, Ben Tilly wrote: > On Mon, Apr 15, 2013 at 11:09 AM, Greg London <[email protected]> wrote: > For unit testing I've been emitting TAP > protocol and testing it with prove, but are there better approaches? > > I get a test file with a lot of code that looks like this: > > printf( > "%s %d: Some useful description and maybe a number %d\n", > (expected_value == test_value) ? "ok" : "not ok", ++tests, > some_useful_debugging_info > );
This method is usually tolerable for a while but gets old as soon as I realize I'm doing the computer's job much slower and less accurately. Instead, I generate the test file from a simpler data file that only contains the relevant test data. I've successfully used three different approaches for this: 1. Extract the relevant data into a text file and use it as input to a program that produces the test file. This works well when the input has a lot of variety or could change in unexpected ways, but then you also have a code generator to maintain. 2. Extract the relevant data into XML and use gsl (https://github.com/imatix/gsl) to generate the test file. Works well when the test data varies in ways that can be relatively easily expressed by xml. While this approach works well, I don't particularly like editing xml so I actually write my data in a hierarchical text format and use, shameless plug, txt2xml (https://github.com/gyepisam/txt2xml) to convert it to xml. 3. I have some similar things with autogen (apt-get install autogen) and it works pretty well too. The various conversions from txt to xml to c and h, do produce long pipelines, but I use make so I just define implicit rules and let make resolve the dependency chain for me. Then I can kick it off with. make test It works quite well and the pieces are modular enough that the next guy is likely to understand it. However, understanding is not required for effective use, which is usually the primary goal. -Gyepi _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

