Ruby's Watchr Configuration for ShUnit2
Monday, January 16, 2012 11:20:05 AM
require "erb"
watch('tests/.*Test\.sh') do |md|
clear_console
run "#{md[0]}"
end
watch('source/(.*)\.sh') do |md| # runs test when source code changes
clear_console
testpath = "tests/" + md[1] + "Test.sh"
run "#{testpath}"
end
def clear_console
puts "\e[H\e[2J" #clear console
end
def run cmd
result = `#{cmd} 2>&1`
if result.match(/FAILED\s+\(failures=/)
notify_failed cmd, result
elsif result.match(/ERROR/) or result.match(/command not found/)
notify "#{cmd}", result, "pending.png", 6000
elsif result.match(/\nOK\n/)
notify "#{cmd}", "<font size=4 color=lightgreen><b><i>Tests Passed Successfuly</i></b></font>", "success.png", 1000
else
notify "#{cmd}", "Unknown error:
" + result, "pending.png", 3000
end
puts result
end
def notify_failed cmd, result
ft = result.match(/.*(test.*)\nASSERT:(.*?)\n/m)
first_failing_test = defined?(ft[1]) ? ft[1] : "no match"
first_failure_message = defined?(ft[2]) ? ft[2] : "Critical"
notify "#{cmd}", "<b>" + first_failing_test + "</b> failed!\n" +
"<font size=3 color=pink><b><i>" + ERB::Util.html_escape(first_failure_message) + "</i></b></font>", "failure.png", 6000
end
def notify title, msg, img, show_time
images_dir='~/.autotest/images'
system "notify-send '#{title}' '#{msg}' -i #{images_dir}/#{img} -t #{show_time}"
end






