Created
March 23, 2009 07:57
-
-
Save szymon-jez/83463 to your computer and use it in GitHub Desktop.
ZenTest Autotest configuration file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- ruby -*- | |
# configuration file for autotes from ZenTest | |
# author: Szymon (jeznet) Jeż <[email protected]> | |
# inspired by the code found inside the ZenTest gem | |
require 'autotest/redgreen' | |
module Autotest::Notify | |
ALL_TESTS_COUNT = 10 # change this to be ca. 50% of the number of test in your test suite; this is used when chcking if all avaible tests passed or only a subset of them | |
def self.notify title, message | |
if RUBY_PLATFORM =~ /linux/ | |
# if dcop server is running (KDE) | |
if `ps -Al | grep dcop` && $? == 0 | |
def self.knotify title, msg | |
system "dcop knotify default notify " + | |
"eventname \'#{title}\' \'#{msg}\' '' '' 16 2" | |
end | |
knotify title, message | |
# if osd_cat is avaible | |
elsif `which osd_cat` && $? == 0 | |
color = case title | |
when /Passed/ | |
'green' | |
when /Failed/ | |
'red' | |
else | |
'white' | |
end | |
OsdCat.send "#{title} \n #{message}", color | |
# if notify-send is avaible | |
elsif `which notify-send` && $? == 0 | |
system("notify-send -i #{image} #{title} \"#{message}\"") | |
else | |
puts "No compatible popup notification system installed." | |
puts "Try installing one of this:\n * osd_cat (apt-get install xosd-bin),\n * knotify (use KDE),\n * notify-send (apt-get install libnotify-bin)" | |
puts " #{title}\n #{message}" | |
end | |
elsif RUBY_PLATFORM =~ /darwin/ # MacOS | |
if `ps -Al | grep GrowlHelper` && `which growlnotify` && $? == 0 | |
system("growlnotify -n autotest_notifier -p 2 -t \"#{title}\" -m \"#{message}\"") | |
else | |
puts "No compatible popup notification system installed." | |
puts "Try installing one of this:\n * growl" | |
puts " #{title}\n #{message}" | |
end | |
elsif RUBY_PLATFORM =~ /mswin/ | |
begin | |
require 'snarl' | |
rescue LoadError | |
puts 'To be notified by a popup please install Snarl and a ruby gem for it' | |
puts " #{title}\n #{message}"\ | |
else | |
Snarl.show_message(title, message, image) | |
end | |
else | |
puts "No compatible platform i use." | |
puts " #{title}\n #{message}" | |
end | |
end | |
def self.parse(results) | |
tests = 0 | |
assertions = 0 | |
failures = 0 | |
errors = 0 | |
results.scan(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/) do |t, a, f, e| | |
tests += t.to_i | |
assertions += a.to_i | |
failures += f.to_i | |
errors += e.to_i | |
end if results | |
return tests, assertions, failures, errors | |
end | |
Autotest.add_hook :ran_command do |at| | |
tests, assertions, failures, errors = parse(at.results.last) | |
message = "%d tests, %d assertions, %d failures, %d errors" % | |
[tests, assertions, failures, errors] | |
if failures > 0 || errors > 0 | |
message = "%d tests, %d assertions, %d failures, %d errors" % | |
[tests, assertions, failures, errors] | |
notify "---- Tests Failed ----", message | |
elsif tests < ALL_TESTS_COUNT | |
message = "%d tests, %d assertions" % [tests, assertions] | |
notify "Tests Passed", message | |
else tests >= ALL_TESTS_COUNT | |
message = "%d tests, %d assertions" % [tests, assertions] | |
notify "All Tests Passed", message | |
end | |
true | |
end | |
end | |
# taken from http://theadmin.org/articles/2008/2/10/fail-loudly-with-osd_cat-and-autotest | |
module OsdCat | |
# Use xlsfonts to find the different fonts | |
FONT = "-bitstream-charter-bold-r-normal--33-240-100-100-p-206-iso8859-1" | |
# Will display the message on the top of the screen centered, adjust these numbers to suit. | |
POSITION = "top" # top|middle|bottom | |
POSITION_OFFSET = "0" # Pixels from position to display (think CSS margin) | |
ALIGN = "center" # left|right|center | |
def self.send msg, color='green' | |
osd_command = "echo #{msg.inspect} | osd_cat --font=#{FONT} --shadow=0 --pos=#{POSITION} -o #{POSITION_OFFSET} --delay=4 --outline=4 --align=#{ALIGN} -c #{color}" | |
# osd_cat blocks so start a new thread, otherwise Autotest will wait | |
Thread.new do | |
`#{osd_command}` | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment