February 2018 Archives

Stupid Testing Trick: Inconstant Constants

I have a piece of Perl containing manifest constants that have the same value, but which signify different things. In my testing, I wanted to make sure I was getting the right one out of my code. That seems to mean changing code to test it, which is anathema to me.

It occurred to me today that if I held my tongue right I could change the values of the constants without touching the code they were defined in or exported from. Holy aspect-oriented programming, Batman!

The trick is based on the fact that what use constant really does is to define …

About Tom Wyant

user-pic Fine Perl code for over 0.005 centuries.