-
-
Save kakutani/7772 to your computer and use it in GitHub Desktop.
This file contains 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
## | |
# Autotest::Screen is test result notify GNU Screen's statusline. | |
# | |
# === screenshots | |
# * <img src="http://f.hatena.ne.jp/images/fotolife/s/secondlife/20061109/20061109015543.png" /> | |
# * <img src="http://f.hatena.ne.jp/images/fotolife/s/secondlife/20061109/20061109015522.png" /> | |
# | |
# == SYNOPSIS | |
# require 'autotest/screen' | |
# # Autotest::Screen.statusline = '%H %`%-w%{=b bw}%n %t%{-}%+w (your statusline)' | |
# | |
class Autotest::Screen | |
DEFAULT_STATUSLINE = '%H %`%-w%{=b bw}%n %t%{-}%+w' | |
DEFAULT_SCREEN_CMD = 'screen' | |
SCREEN_COLOR = { | |
:black => 'dd', | |
:green => 'gw', | |
:yellow => 'yk', | |
:red => 'rw', | |
} | |
def self.message(msg, color = :black) | |
col = SCREEN_COLOR[color] | |
msg = %Q[ %{=b #{col}} #{msg} %{-}] | |
send_cmd(msg) | |
end | |
def self.clear | |
send_cmd('') | |
end | |
def self.run_screen_session? | |
str = `#{screen_cmd} -ls` | |
str.match(/(\d+) Socket/) && ($1.to_i > 0) | |
end | |
def self.execute? | |
!($TESTING || !run_screen_session?) | |
end | |
@statusline, @screen_cmd = nil | |
def self.statusline; @statusline || DEFAULT_STATUSLINE.dup; end | |
def self.statusline=(a); @statusline = a; end | |
def self.screen_cmd; @screen_cmd || DEFAULT_SCREEN_CMD.dup; end | |
def self.screen_cmd=(a); @screen_cmd = a; end | |
def self.send_cmd(msg) | |
cmd = %(#{screen_cmd} -X eval 'hardstatus alwayslastline "#{(statusline + msg).gsub('"', '\"')}"') #' stupid ruby-mode | |
system cmd | |
end | |
# All blocks return false for each of following blocks defined in user's own ".autotest". | |
Autotest.add_hook :initialize do |at| | |
message "Run with #{at.class}" if execute? | |
next false | |
end | |
Autotest.add_hook :quit do |at| | |
clear if execute? | |
next false | |
end | |
Autotest.add_hook :run_command do |at| | |
message 'Running' if execute? | |
next false | |
end | |
Autotest.add_hook :ran_command do |at| | |
next false unless execute? | |
output = at.results.join | |
case at.class.name | |
when 'Autotest::Rails' | |
results = output.scan(/(\d+)\s*failures?,\s*(\d+)\s*errors?/).first | |
num_failures, num_errors = results.map{|r| r.to_i} | |
if num_failures > 0 || num_errors > 0 | |
message "Red F:#{num_failures} E:#{num_errors}", :red | |
else | |
message 'All Green', :green | |
end | |
when 'Autotest::RailsRspec' | |
results = output.scan(/(\d+)\s*examples?,\s*(\d+)\s*failures?(?:,\s*(\d+)\s*pendings?)?/).first | |
num_examples, num_failures, num_pendings = results.map{|r| r.to_i} | |
if num_failures > 0 | |
message "Fail F:#{num_failures} P:#{num_pendings}", :red | |
elsif num_pendings > 0 | |
message "Pend F:#{num_failures} P:#{num_pendings}", :yellow | |
else | |
message 'All Green', :green | |
end | |
end | |
next false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment