Saturday, 9 May 2009

Testing Differences in Templates

I've been doing some template refactoring now, and since I want to make sure the new templates render exactly the same as the old ones, I used Schwern++'s Test::More to compare their outputs for all combinations of input variables I had. Things were great for the first small-and-obvious changes, but at some point both outputs looked the same to me, and yet were still failing the test, meaning something was off. But what?

A quick CPAN search pointed me to Barrie Slaymaker++'s Test::Differences (now maintained by Ovid++). After that, all I had to do was replace my is() call with eq_or_diff() and voilá:

#   Failed test 'templates should produce the exact same output'
# at t/refactoring.t line 128.
# +---+------+---+----------+
# | Ln| Got | Ln| Expected |
# +---+------+---+----------+
# | 3 | | 3 | |
# | 4 | | 4 | |
# | 5 | | 5 | |
# * 6 |\t\n * 6 |\n |
# | 7 | | 7 | |
# | 8 | | 8 | |
# | 9 | | 9 | |
# +---+------+---+----------+
Ha! Much easier, much direct. After a simple extra tab removal, all tests were successful and I could move on. Yay!

1 comment:

  1. If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you got to watch this video
    right away...

    (VIDEO) Why your ex will NEVER come back...

    ReplyDelete