Skip to content

Instantly share code, notes, and snippets.

@Stubbs
Created February 2, 2012 12:57
Show Gist options
  • Save Stubbs/1723342 to your computer and use it in GitHub Desktop.
Save Stubbs/1723342 to your computer and use it in GitHub Desktop.
watchr script to auto-run phing tests
# Watchr config script to run phing tests every time you save PHP or fixtures.
# See http://criticallog.thornet.net/2011/03/08/autotesting-with-watchr-growl-and-phpunit/
#
watch('./(.*).(php|inc)') { |m| code_changed(m[0]) }
watch('./fixtures.sql') { |m| code_changed(m[0]) }
watch('phpdebug_trigger') { |m| code_changed(m[0]) }
def code_changed(file)
run "phing test"
end
def run(cmd)
result = `#{cmd}`
growl result
end
def notify_send(message)
puts message
notify_send = `which notify-send`.chomp
if( not message.find { |e| /BUILD FINISHED/ =~ e})
title = "Fatal Error"
info = "There was a fatal error, the build did not finish"
image = "/home/stuart/Pictures/thumb-down.png"
else
title = message.find { |e| /(Failures: [1-9]+|Errors: [1-9])/ =~ e} ? "Failures" : "Pass"
if title == "Failures"
image = "/home/stuart/Pictures/thumb-down.png"
failures = /Failures: (\d)/.match(message)[1]
errors = /Errors: (\d)/.match(message)[1]
total = failures.to_i + errors.to_i
info = "There are #{total} failures/errors"
else
image = "/home/stuart/Pictures/thumb-up.png"
info = "All tests are passing"
end
end
options = "-t 10000 -i '#{image}' '#{title}' '#{info}'"
system %(sudo #{notify_send} #{options} &)
system %{rm phpdebug_trigger}
end
def growl(message)
puts(message)
growlnotify = `which growlnotify`.chomp
if( not message.find { |e| /BUILD FINISHED/ =~ e})
title = "Fatal Error"
info = "There was a fatal error, the build did not finish"
image = "/Users/stuart/Pictures/simon_cowell_thumbs_down.jpg"
priority=1
else
title = message.find { |e| /(Failures: [1-9]+|Errors: [1-9])/ =~ e} ? "Failures" : "Pass"
if title == "Failures"
image = "/Users/stuart/Pictures/simon_cowell_thumbs_down.jpg"
failures = /Failures: (\d)/.match(message)[1]
errors = /Errors: (\d)/.match(message)[1]
total = failures.to_i + errors.to_i
info = "There are #{total} failures/errors"
priority=1
else
image = "/Users/stuart/Pictures/susan-boyle-thumbs-up.png"
info = "All tests are passing"
priority=0
end
end
options = "-w -n Watchr --image '#{File.expand_path(image)}' --html '#{title}' -m '#{info}' -p #{priority}"
system %(#{growlnotify} #{options} &)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment