forked from thubble/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
continuous_testing
96 lines (77 loc) · 1.84 KB
/
continuous_testing
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
#!/usr/bin/env ruby
@all_files ={}
class ChangedFile
attr_accessor :name,:last_changed_time
def initialize(name)
@name = name
@last_changed_time = File.mtime(name)
end
def has_changed?
@last_changed_time < File.mtime(@name)
end
def update
@last_changed_time = File.mtime(@name)
end
def was_deleted?
not File.exists?(@name)
end
end
class BuildMessage
def initialize(error_items)
@error_items = error_items
end
def successful
@error_items.length == 0
end
def message
successful ? "Build Successful" : @error_items.join("\r\n")
end
end
def scan_for_new_files
has_new_files = false
Dir.glob("**/*.cs").each do|file|
unless (@all_files.key?(file))
has_new_files = true
@all_files[file] = ChangedFile.new(file)
end
end
has_new_files
end
def remove_all_deleted
remaining = @all_files.select{|path,item| ! item.was_deleted?}
files_were_deleted = remaining.length != @all_files.length
@all_files = remaining
files_were_deleted
end
def changes_have_occured
return scan_for_new_files | remove_all_deleted | files_have_changed
end
def files_have_changed
has_changed = false
@all_files.each do|path,file|
has_changed |= file.has_changed?
file.update
end
return has_changed
end
def get_errors_in(output)
error_pattern = /error|FAIL/
output.split("\n").select{|item| error_pattern =~ item}
end
def notify(build_message)
icon = build_message.successful ? "green" : "red"
args = {:t => "Build",:i => ".\\#{icon}.jpg"}
command_line = "build/tools/growl/growlnotify.exe"
args.each {|key,value| command_line += " /#{key}:\"#{value}\""}
`#{command_line} "#{build_message.message}"`
end
def monitor
if changes_have_occured
errors = get_errors_in(`rake specs:run`)
notify(BuildMessage.new(errors))
end
end
while true do
monitor
sleep(1)
end