-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautotest
133 lines (115 loc) · 3.43 KB
/
autotest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# .autotest
# Autotest Growl Notifications for Rspec and Test::Unit
#
# Created by Rein Henrichs on 2007-09-12.
# Copyright 2007 Rein Henrichs.
# http://pastie.caboo.se/96573/download
#
require 'autotest/redgreen'
require 'autotest/timestamp'
require 'logger'
logfile = File.join(File.dirname(__FILE__), '.autotest.log')
$logger = Logger.new(logfile)
module Autotest::Growl
Autotest.add_hook :ran_command do |at|
input = Input.new( at.results )
Growler.display_notification( input )
end
end
class String
def remove_color_codes!
self.gsub!(/\e\[\d+m/,'')
self.strip!
end
end
class Growler
class << self
def display_notification( input )
growler = RspecGrowler if input.from_rspec?
growler = TestUnitGrowler if input.from_test_unit?
growler.display_notification( input.result_line )
rescue => e
$logger.fatal e
notify_system_error( "Unexpected Error", "Please check your ~/.autotest.log and report anything strange to [email protected]" )
end
def notify(title, msg, img, pri=0, stick="" )
system "/usr/local/bin/growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
end
def notify_system_error( title = "System Error", err = "")
Growler.notify( title, err, '~/Library/autotest/fail.png')
end
end
end
class Input
def initialize(input)
@input = input
end
def empty?; @input.empty?; end
# TODO: Make these work
def failing?; end
def passing?; end
def error?; end
def from_rspec?; !!rspec_result_line || empty?; end
def from_test_unit?; !!test_unit_result_line; end
def rspec_result_line; @input.grep( /\d+\sexample/ ).first; end
def test_unit_result_line; @input.grep( /\d+\sassertion/ ).first; end
def result_line
@line ||= case
when from_rspec? then rspec_result_line
when from_test_unit? then test_unit_result_line
else nil
end
@line.remove_color_codes! if @line
end
end
class AutoGrowler < Growler
class << self
def notify_failure(input)
notify( "Tests Failed", input, '~/Library/autotest/fail.png', 2 )
end
def notify_success(input)
notify( "Tests Passed", input, '~/Library/autotest/pass.png', 0 )
end
end
end
class RspecGrowler < AutoGrowler
class << self
def notify_pending(input)
notify( "Tests Pending", input, '~/Library/autotest/pending.png', 1 )
end
def notify_error
notify( "Syntax Error", "It looks like there was a syntax error. Check your autotest results.", '~/Library/autotest/fail.png')
end
def display_notification(input)
notify_error and return unless input
# TODO: replace with some object oriented goodness. elsif FTL!
examples, failures, pending = input.split(", ")
if failures.to_i > 0
notify_failure input
elsif pending.to_i > 0
notify_pending input
else
notify_success input
end
end
end
end
class TestUnitGrowler < AutoGrowler
class << self
def notify_error(input)
notify( "Tests Errored", input, '~/Library/autotest/fail.png', 2 )
end
def display_notification( input )
# TODO: replace with some object oriented goodness. elsif FTL!
tests, assertions, failures, errors = input.split(", ")
if errors.to_i > 0
notify_error input
elsif failures.to_i > 0
notify_failure input
else
notify_success input
end
end
end
end