autofile, a little script for big hairy test suites

So, when you woke up today, you decided to make this a better day than yesterday; you started with a big healthty breakfast, and arrived to work early.

You look at your todo list to see what needs to be done next, and full of courage take that difficult task at the middle of the list.

Even though your project's test suite has been neglected, you know the way to go is TDD/BDD. You run ./autotest only to be greeted by a tsunami of failing tests and errors.

Bummer.

So, there's a lot of failing stuff on the test suite. You cannot remove it, as it's not yours. You decide to just run the tests for your new stuff (yeah, I know it's an ugly compromise), but don't want to run it manually.

Enter autofile.rb

./autofile.rb path/to/your/lonely/test

...and every time you write to the test file, it gets run again

#!/usr/bin/ruby
@mtime=nil
while true
  current_mtime = File.stat(ARGV.first).mtime
  if current_mtime != @mtime
   puts "found change, running test"
   puts `ruby #{ARGV.first}`
   @mtime = current_mtime
 end
 sleep 0.01
end

Posted by Maximiliano Guzman Sat, 23 May 2009 00:45:00 GMT


Comments

Leave a response

Leave a comment