Monday, April 03, 2006

unit_diff is your friend

Pat introduced me to unit_diff a while ago. At the time, it didn't resonate very well. There isn't much documentation and I didn't get what it was supposed to do. Now, I know exactly what it does and I can give first hand testimony to how great it is.

unit_diff is one of the tools included in ZenTest, along with zentest, multiruby and autotest. If you haven't installed it yet and you are using Test/Unit (You are using Test/Unit, right?), then you absolutely must grab the gem. $ sudo gem install ZenTest unit_diff runs diff on the expected and actual output of failed assert_equal tests in your test cases. Pipe your test output into unit_diff and relax with all the extra time you now have since you don't have to search through pages and pages of output to find the 2 characters that were different.

Actual command example I used recently:
$ ruby -Ilib test/test_parse_tree.rb | unit_diff
Loaded suite test/test_parse_tree
Started
.....FF.........................
Finished in 0.347 seconds.

1) Failure:
test_case_stmt2(TestParseTree) [(eval):1]:
6,10c6,8
< [:case,
< nil,
< [:when, [:array, [:lit, 1]], [:lit, 2]],
< [:when, [:array, [:lit, 3]], [:lit, 4]],
< [:lit, 5]]]]]
---
> [:when, [:array, [:lit, 1]], [:lit, 2]],
> [:when, [:array, [:lit, 3]], [:lit, 4]],
> [:lit, 5]]]]

2) Failure:
test_class(TestParseTree) [test/test_parse_tree.rb:370]:
Must return a lot of shit.
76,80c76,78
< [:case,
< nil,
< [:when, [:array, [:lit, 1]], [:lit, 2]],
< [:when, [:array, [:lit, 3]], [:lit, 4]],
< [:lit, 5]]]]],
---
> [:when, [:array, [:lit, 1]], [:lit, 2]],
> [:when, [:array, [:lit, 3]], [:lit, 4]],
> [:lit, 5]]]],

32 tests, 32 assertions, 2 failures, 0 errors


Without unit_diff, this was nearly 700 lines of output. Imagine how hard that was to process.

1 Comments:

Blogger gnupate said...

heh. unit_diff is a huge help. Next step is to infect you with the autotest bug. I'm loving the way it sits in a terminal and keeps me on track.

6:05 AM  

Post a Comment

<< Home