Way beyond cool: autotest + growl + Doomguy

Here’s something that will amaze your friends to no end. Your male geek friends, that is. Type some code in your editor, save file and… a smiling Doom Marine tells you that all your tests passed. Or, if there were some errors, the Marine is bleeding. The more errors, the more blood. Is it cool or is it cool?

Just look at the screenshots. First: Marine is happy that your tests passed.

The Doom Marine is happy that your tests passed.

Next: there were some failures. The blood starts to flow!

The blood starts to flow.

Even more failures, even more blood.

Even more failures, even more blood.

Oh my, it looks like we killed him, we bastards!

Oh my, it looks like we killed him, we bastards!

How to do this? Read on.


First, go and read Autotest Growl Pass/Fail Notifications by John Nunemaker. This is where I got inspiration from (the comments section, specifically). The Doom Marine head sprites can be found here http://sdb.drshnaps.com/sheets/Misc/Misc/Other/Doom-Head.png.


For this all to work, you need Mac OS X, Growl notification application (with growlnotify), and autotest — automated testing utility. If you want it to look exactly as on screenshots above, set display style to ‘Music video’ in your Growl preferences.

The script

Now, if all prerequisites are installed, copy following script (this is John Nunemaker’s script with my tiny modifications) and save it as ~/.autotest file.

require 'autotest/redgreen' 
require 'autotest/timestamp'    

module Autotest::Growl 
  def self.growl title, msg, img, pri=0, sticky="" 
    system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" 
  Autotest.add_hook :ran_command do |at| 
    image_root = "~/.autotest_images" 
    results = [at.results].flatten.join("n") 
    output = results.slice(/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/) 
    if output 
      if $~[3].to_i > 0 || $~[4].to_i > 0 
        cnt = [(9 + $~[3].to_i + $~[4].to_i) / 10 * 10, 50].min 
        growl "FAIL", "#{output}", "#{image_root}/fail#{cnt}.png", 2 
        growl "Pass", "#{output}", "#{image_root}/pass.png" 

My addition is that depending on number of your failures and errors, one of 5 different failure icons is chosen.

The icons

You can download them from RapidShare (please let me know if the file is gone). The zip file contains one smiling Marine, five differently bleeding Marines and the above .autotest script in case you have any trouble with copying & saving stuff. After saving the zip file in your home directory, fire up your console and say:

~ > unzip doom.zip 
Archive:  doom.zip 
  inflating: .autotest 
  inflating: .autotest_images/fail10.png 
  inflating: .autotest_images/fail20.png 
 extracting: .autotest_images/fail30.png 
 extracting: .autotest_images/fail40.png 
  inflating: .autotest_images/fail50.png 
 extracting: .autotest_images/pass.png

And that’s all. Try running autotest and enjoy endless Doomguy goodness.

So you don’t use autotest?

Are you of those that refuse to accept the goodness of automated test running? Or maybe you don’t use Ruby at all? Don’t despair. As you can see the heart of this is the neat growlnotify utility. It should be as easy to add it to rake test. Or to report results of your ant or make build. Or anything really.

If you have any problems or questions, feel free to comment. I will be also glad to hear of any additional ideas where this could be used.

If you cannot download the above mentioned zip file from RapidShare, here are the icons again. Click on each and save to ~/.autotest_images:


Add to:
Digg! digg blog_head.png reddit delicioussmall.gif del.icio.us


31 responses to “Way beyond cool: autotest + growl + Doomguy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: