Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Created May 6, 2011 12:26
Show Gist options
  • Save vderyagin/958862 to your computer and use it in GitHub Desktop.
Save vderyagin/958862 to your computer and use it in GitHub Desktop.
Autotest integration with libnotify on GNU/Linux
#! /usr/bin/env ruby
require 'autotest/timestamp'
IMAGES_ROOT = File.expand_path("~/.dotfiles/autotest_images/small")
module Autotest::LibNotify
def self.notify(title, msg, urgency=:normal)
img = File.join(IMAGES_ROOT, "#{title.downcase}.png")
`notify-send '#{title}' '#{msg}' --icon=#{img} --expire-time=5000 --urgency=#{urgency}`
end
Autotest.add_hook :ran_command do |at|
begin
time_taken = at.results[-2].strip
summary = at.results[-1]
pattern = /(\d+)\sexamples?,\s(\d+)\sfailures?(?:,\s(\d+)\spending)?/
(total, failures, pending) = summary.match(pattern) { |md| md[1..3].map(&:to_i) }
rescue # if autotest failed to produce valid output
notify "FAIL", "error occured", :critical
else # building output string for notification
output = "#{total} executed"
output << "\n#{failures} failed" unless failures.zero?
output << "\n#{pending} pending" unless pending.zero?
output << "\n\n"
output << time_taken
if failures > 0
notify "FAIL", output, :critical
elsif pending > 0
notify "Pending", output
else
notify "Passed", output
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment