http://qs1969.pair.com?node_id=307122

EvdB has asked for the wisdom of the Perl Monks concerning the following question:

This could possibly go into SoPW, but it is more of a musing so here goes:

The problem I wish to address is content generated by Template from templates. I can envisage a situation where the perl code and the underlying templates are created and tested. Then in the future a web designer comes alnog and makes changes to the templates. Then the designer wants to check that they have not changed the functionality of the template in any way, which is a good thing. However they do not know Template beyond the very basics and know nothing of perl.

For example, how could a designer check that their modifications to the following are OK:

*** insert the introduction here *** [% FOREACH item = items %] id: [% item.id %] name: [% item.name %] quantity: [% item.quantity %] unit_price: [% item.unit_price FILTER format ( '%.2f' ) %] total_price: [% item.quantity * item.unit_price FILTER format ( '%.2f' + ) %] [% END %] ** insert thank you here ***
The template above could be easily processed and then tested against expected data (regression testing) to ensure that it works.

My proposed solution to this is that there should be two sets of templates: one is used to generate the content in production, the other is used to test that the production templates behave as expected. These two sets of templates would be identical in terms of their functionality.

During testing the two sets of templates are compared to see if they are functionally the same - hence the diff for templates. However it is not straight forward to write a script which strips out everything but the Template commands.

I have the following thoughts / questions:

I hope that this little musing of mine increases the ways to test, which for Templates currently appears to be quite few.

--tidiness is the memory loss of environmental mnemonics